Scoreboard mostly working. It doesn't read the existing scores correctly yet though.

This commit is contained in:
Storm Dragon 2019-12-11 21:45:52 -05:00
parent 08f06699c8
commit 54842bac29

View File

@ -38,6 +38,7 @@ class scoreboard():
'Handles scores and top 10' 'Handles scores and top 10'
def __init__(self, startingScore = 0): def __init__(self, startingScore = 0):
read_config()
try: try:
localConfig.add_section("scoreboard") localConfig.add_section("scoreboard")
except: except:
@ -46,16 +47,20 @@ class scoreboard():
self.oldScores = [] self.oldScores = []
for i in range(1, 11): for i in range(1, 11):
try: try:
self.oldScores.insert(i - 1, read_config("scoreboard", i)) self.oldScores.insert(i - 1, localConfig.get("scoreboard", i))
except: except:
pass pass
#self.oldScores.insert(i - 1, 0) self.oldScores.insert(i - 1, 0)
for i in range(1, 11): for i in range(1, 11):
if self.oldScores[i - 1] == None: if self.oldScores[i - 1] == None:
self.oldScores[i - 1] = 0 self.oldScores[i - 1] = 0
def __del__(self): def __del__(self):
self.Update_Scores() self.Update_Scores()
try:
write_config()
except:
pass
def Decrease_Score(self, points = 1): def Decrease_Score(self, points = 1):
self.score -= points self.score -= points
@ -70,36 +75,35 @@ class scoreboard():
self.score += points self.score += points
def Update_Scores(self): def Update_Scores(self):
newScores = self.oldScores.copy() # Update the scores
for i in newScores: for i, j in enumerate(self.oldScores):
if self.score > newScores[newScores.index(i)]: if self.score > j:
self.oldScores[newScores.index(newScores[i])] = i self.oldScores[i] = self.score
localConfig.set("scoreboard", str(newScores.index(newScores[i])), str(i)) break
try: # Update the scoreboard section of the games config file.
write_config() for i, j in enumerate(self.oldScores):
except: localConfig.set("scoreboard", str(i + 1), str(j))
pass
def write_config(writeGlobal = False): def write_config(writeGlobal = False):
if writeGlobal == False: if writeGlobal == False:
with open(gamePath + "config.ini", 'w') as configfile: with open(gamePath + "/config.ini", 'w') as configfile:
localConfig.write(configfile) localConfig.write(configfile)
else: else:
with open(globalPath + "config.ini", 'w') as configfile: with open(globalPath + "/config.ini", 'w') as configfile:
globalConfig.write(configfile) globalConfig.write(configfile)
def read_config(section, value, readGlobal = False): def read_config(readGlobal = False):
if readGlobal == False: if readGlobal == False:
try: try:
with open(gamePath + "config.ini", 'r') as configfile: with open(gamePath + "/config.ini", 'r') as configfile:
return localConfig.read(section, value) localConfig.read(configfile)
except: except:
pass pass
else: else:
try: try:
with open(globalPath + "config.ini", 'r') as configfile: with open(globalPath + "/config.ini", 'r') as configfile:
return globalConfig.read(section, value) globalConfig.read(configfile)
except: except:
pass pass