forked from mattboan/Galtron
-
Notifications
You must be signed in to change notification settings - Fork 47
/
Copy pathgameStats.py
38 lines (35 loc) · 968 Bytes
/
gameStats.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
import json
class GameStats():
"""Track stats for alien shooter"""
def __init__(self, setting):
"""initialize statistics"""
self.setting = setting
#Start alien invasion in an active state.
self.gameActive = False
self.mainMenu = True
self.mainGame = False
self.mainAbout = False
self.playMenu = False
self.twoPlayer = False
self.paused = False
self.score = 0
self.level = 1
self.highScore = 0
#self.counter = 3
self.resetStats()
def resetStats(self):
"""initialize statistics that can change during the game"""
self.shipsLeft = self.setting.shipLimit
self.level = 1
self.score = 0
self.counter = 3
self.ultimateGauge = 0
self.ultimatePattern = 1
filename = 'data-files/highscore.json'
with open(filename, 'r') as f_obj:
self.tempScore = json.load(f_obj)
if self.highScore >= self.tempScore:
with open(filename, 'w') as f_obj:
json.dump(self.highScore, f_obj)
else:
self.highScore = self.tempScore