-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoreManager.py
43 lines (31 loc) · 884 Bytes
/
scoreManager.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
#-----scoreManager for turty game :-)-----
# Define global scoreCounter variable
scoreCounter = 0
def incrementScore():
global scoreCounter
scoreCounter+= 1
def decrementScore():
global scoreCounter
scoreCounter-= 1
def resetScore():
global scoreCounter
scoreCounter = 0
def getHighscore(fileName):
global scoreCounter
highScoreFile = open(fileName, "r")
for line in highScoreFile:
index = 0
highScoreStr = ""
while (line[index] != "\n"):
highScoreStr = highScoreStr + line[index]
index+=1
highScoreFile.close()
if scoreCounter > int(highScoreStr):
updateHighscore(fileName)
return highScoreStr
else:
return highScoreStr
def updateHighscore(fileName):
global scoreCounter
file = open(fileName, "w")
file.write(str(scoreCounter) + "\n")