forked from ismailhasannnnnn/PyMario
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.py
More file actions
47 lines (33 loc) · 934 Bytes
/
stats.py
File metadata and controls
47 lines (33 loc) · 934 Bytes
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
import os
class Stats:
def __init__(self, game):
self.game = game
self.settings = game.settings
self.reset_stats()
self.lives = 3
self.score = 0
self.high_score = self.load_high_score()
def __del__(self):
self.save_high_score()
def load_high_score(self):
try:
with open("highscore.txt", "r") as f:
return int(f.read())
except:
return 0
def save_high_score(self):
try:
with open("highscore.txt", "w+") as f:
f.write(str(round(self.high_score, -1)))
except:
print("highscore.txt not found")
def get_score(self):
return self.score
def get_highscore(self):
return self.high_score
def get_lives(self):
return self.lives
def death(self):
self.lives -= 1
def reset_stats(self):
pass