New scoreboard feature added. Partially implimented.

This commit is contained in:
Storm Dragon 2019-12-11 09:32:50 -05:00
parent f2326c628c
commit 7ef11be54c

View File

@ -36,13 +36,48 @@ globalConfig = configparser.ConfigParser()
class scoreboard(): class scoreboard():
'Handles scores and top 10' 'Handles scores and top 10'
def __init__(self): def __init__(self, startingScore = 0):
self.oldScores = []
for i in range(9):
try: try:
self.oldScores[i] = read_config("scoreboard", i) localConfig.add_section("scoreboard")
except: except:
self.oldScores[i] = 0 pass
self.score = startingScore
self.oldScores = []
for i in range(1, 11):
try:
self.oldScores.insert(i - 1, read_config("scoreboard", i))
except:
pass
#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()
def Decrease_Score(self, points = 1):
self.score -= points
def Get_High_Score(self, position = 1):
return self.oldScores[position - 1]
def Get_Score(self):
return self.score
def Increase_Score(self, points = 1):
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
def write_config(writeGlobal = False): def write_config(writeGlobal = False):
@ -55,11 +90,17 @@ def write_config(writeGlobal = False):
def read_config(section, value, readGlobal = False): def read_config(section, value, readGlobal = False):
if readGlobal == False: if readGlobal == False:
try:
with open(gamePath + "config.ini", 'r') as configfile: with open(gamePath + "config.ini", 'r') as configfile:
return localConfig.read(section, value) return localConfig.read(section, value)
except:
pass
else: else:
try:
with open(globalPath + "config.ini", 'r') as configfile: with open(globalPath + "config.ini", 'r') as configfile:
return globalConfig.read(section, value) return globalConfig.read(section, value)
except:
pass
def speak(text, interupt = True): def speak(text, interupt = True):
if speechProvider == "speechd": if speechProvider == "speechd":
@ -177,7 +218,7 @@ def display_text(text):
speak("Failed to copy the text to the clipboard.") speak("Failed to copy the text to the clipboard.")
if event.key == pygame.K_t: if event.key == pygame.K_t:
try: try:
pyperclip.copy(''.join(text[1:-1])) pyperclip.copy(' '.join(text[1:-1]))
speak("Copied entire message to the clipboard.") speak("Copied entire message to the clipboard.")
except: except:
speak("Failed to copy the text to the clipboard.") speak("Failed to copy the text to the clipboard.")