-
Notifications
You must be signed in to change notification settings - Fork 0
/
Save_Load.py
51 lines (42 loc) · 1.26 KB
/
Save_Load.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
import Stats
def save():
# Write
file2write = open("Save_File", 'w')
#Set Bools
if Stats.Drill_Sargent:
x = 1
else:
x = 0
file2write.write(f"Money:{str(Stats.resorces.money)} Rations:{str(Stats.resorces.rations)} "
f"Soldiers:{str(Stats.Unit_Soldiers.amount)} Drill_Sargent:{x} Time:{Stats.Time} "
f"Heavy:{str(Stats.Unit_Heavy.amount)} Med-Kit:{str(Stats.resorces.med_kit)} end")
file2write.close()
def load():
# READ
f = open('Save_File', 'r')
new = f.readline()
f.close()
list = []
t = ""
n_line = False
for x in new:
if n_line:
t += x
if x == ":":
n_line = True
elif x == " ":
n_line = False
list.append(t)
t = ""
print(list)
#Change Variables
Stats.resorces.money = float(list[0])
Stats.resorces.rations = int(list[1])
Stats.Unit_Soldiers.amount = int(list[2])
Stats.Drill_Sargent = int(list[3])
Stats.Drill_Sargent = bool(Stats.Drill_Sargent)
Stats.Time = int(list[4])
Stats.Unit_Heavy.amount = int(list[5])
Stats.resorces.med_kit = int(list[6])
print(f"Drill Sargent: {Stats.Drill_Sargent}")
print(type(Stats.Drill_Sargent))