-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatManager.py
36 lines (31 loc) · 911 Bytes
/
statManager.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
import json
class statManager:
gameWin = True
@staticmethod
def updateStat():
if statManager.gameWin:
requiredStat = "totalWin"
else:
requiredStat = "totalLoss"
with open('stat.json', 'r+') as f:
dataStat = json.load(f)
previousNumber = dataStat[requiredStat]
dataStat[requiredStat] = previousNumber + 1
f.seek(0)
f.truncate()
json.dump(dataStat, f)
@staticmethod
def setWin(flag):
statManager.gameWin = flag
@staticmethod
def getWin():
with open('stat.json', 'r+') as f:
dataStat = json.load(f)
win = dataStat["totalWin"]
return win
@staticmethod
def getLoss():
with open('stat.json', 'r+') as f:
dataStat = json.load(f)
loss = dataStat["totalLoss"]
return loss