-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfilemanager.py
executable file
·53 lines (32 loc) · 1023 Bytes
/
filemanager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Pitfall v1.0
By Danilo Lekovic for Game Design 12
filemanager.py
File manager for opening, reading, editing saved games
"""
# We are using Python's built-in JSON support
# because it is very easy to access with minimal code
import json
class FileManager:
# Looks for key and returns value
def readOption(option):
jsonElements = None
# Save game file is save.pitfall
with open('save.pitfall', 'r') as f:
output = f.read()
jsonElements = json.loads(output)
return jsonElements[option]
# Edits key with value
def edit(option, value):
jsonElements = None
# Read file first
with open('save.pitfall', 'r') as f:
output = f.read()
jsonElements = json.loads(output)
# Make changes
jsonElements[option] = value
# Save changes
with open('save.pitfall', 'w') as outfile:
json.dump(jsonElements, outfile)