Scoreboard mostly working. It doesn't read the existing scores correctly yet though.
This commit is contained in:
parent
08f06699c8
commit
54842bac29
@ -38,6 +38,7 @@ class scoreboard():
|
||||
'Handles scores and top 10'
|
||||
|
||||
def __init__(self, startingScore = 0):
|
||||
read_config()
|
||||
try:
|
||||
localConfig.add_section("scoreboard")
|
||||
except:
|
||||
@ -46,16 +47,20 @@ class scoreboard():
|
||||
self.oldScores = []
|
||||
for i in range(1, 11):
|
||||
try:
|
||||
self.oldScores.insert(i - 1, read_config("scoreboard", i))
|
||||
self.oldScores.insert(i - 1, localConfig.get("scoreboard", i))
|
||||
except:
|
||||
pass
|
||||
#self.oldScores.insert(i - 1, 0)
|
||||
self.oldScores.insert(i - 1, 0)
|
||||
for i in range(1, 11):
|
||||
if self.oldScores[i - 1] == None:
|
||||
self.oldScores[i - 1] = 0
|
||||
|
||||
def __del__(self):
|
||||
self.Update_Scores()
|
||||
try:
|
||||
write_config()
|
||||
except:
|
||||
pass
|
||||
|
||||
def Decrease_Score(self, points = 1):
|
||||
self.score -= points
|
||||
@ -70,36 +75,35 @@ class scoreboard():
|
||||
self.score += points
|
||||
|
||||
def Update_Scores(self):
|
||||
newScores = self.oldScores.copy()
|
||||
for i in newScores:
|
||||
if self.score > newScores[newScores.index(i)]:
|
||||
self.oldScores[newScores.index(newScores[i])] = i
|
||||
localConfig.set("scoreboard", str(newScores.index(newScores[i])), str(i))
|
||||
try:
|
||||
write_config()
|
||||
except:
|
||||
pass
|
||||
# Update the scores
|
||||
for i, j in enumerate(self.oldScores):
|
||||
if self.score > j:
|
||||
self.oldScores[i] = self.score
|
||||
break
|
||||
# Update the scoreboard section of the games config file.
|
||||
for i, j in enumerate(self.oldScores):
|
||||
localConfig.set("scoreboard", str(i + 1), str(j))
|
||||
|
||||
|
||||
def write_config(writeGlobal = False):
|
||||
if writeGlobal == False:
|
||||
with open(gamePath + "config.ini", 'w') as configfile:
|
||||
with open(gamePath + "/config.ini", 'w') as configfile:
|
||||
localConfig.write(configfile)
|
||||
else:
|
||||
with open(globalPath + "config.ini", 'w') as configfile:
|
||||
with open(globalPath + "/config.ini", 'w') as configfile:
|
||||
globalConfig.write(configfile)
|
||||
|
||||
def read_config(section, value, readGlobal = False):
|
||||
def read_config(readGlobal = False):
|
||||
if readGlobal == False:
|
||||
try:
|
||||
with open(gamePath + "config.ini", 'r') as configfile:
|
||||
return localConfig.read(section, value)
|
||||
with open(gamePath + "/config.ini", 'r') as configfile:
|
||||
localConfig.read(configfile)
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
try:
|
||||
with open(globalPath + "config.ini", 'r') as configfile:
|
||||
return globalConfig.read(section, value)
|
||||
with open(globalPath + "/config.ini", 'r') as configfile:
|
||||
globalConfig.read(configfile)
|
||||
except:
|
||||
pass
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user