I broke it again
This commit is contained in:
+33
-30
@@ -47,49 +47,52 @@ class EndSceen():
|
|||||||
|
|
||||||
self.isBackButton = True
|
self.isBackButton = True
|
||||||
|
|
||||||
self.loadResults()
|
self.data = self.getResultsFromFile()
|
||||||
|
self.sortedDataByScores = sorted(enumerate(self.data),
|
||||||
|
key=lambda i: i[1][1], reverse=True)
|
||||||
|
|
||||||
|
|
||||||
def loadResults(self):
|
def getResultsFromFile(self):
|
||||||
|
data = []
|
||||||
|
|
||||||
with open(self.saveFileName, 'rb') as file:
|
with open(self.saveFileName, 'rb') as file:
|
||||||
for line in file:
|
for line in file:
|
||||||
try:
|
try:
|
||||||
name, score, time = with line.split()
|
line = self.shiftRight(line).decode('ascii')
|
||||||
self.data.append(
|
name, score, time = line.split()
|
||||||
[name[:10].decode('ascii'), int(score), float(time)]
|
data.append(
|
||||||
|
[name[:10], int(score), float(time)]
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
continue
|
continue
|
||||||
|
return data
|
||||||
file.close()
|
|
||||||
|
|
||||||
self.sortedDataByScores = sorted(enumerate(self.data),
|
|
||||||
key=lambda i: i[1][1], reverse=True)
|
|
||||||
|
|
||||||
|
|
||||||
def saveResults(self):
|
def saveResults(self):
|
||||||
newData = []
|
data = self.getResultsFromFile()
|
||||||
|
|
||||||
# try:
|
# data.append(('{0} {1} {2:.2f}\n'.format(self.playerName,
|
||||||
# fileWithData = open(self.saveFileName, 'rb')
|
|
||||||
# except IOError as e:
|
|
||||||
# pass
|
|
||||||
# else:
|
|
||||||
# tmpData = pickle.load(fileWithData)
|
|
||||||
# fileWithData.close()
|
|
||||||
#
|
|
||||||
# for line in tmpData:
|
|
||||||
# if len(line.split()) == 3:
|
|
||||||
# if not (line.split()[0].rstrip() == self.playerName.rstrip()):
|
|
||||||
# newData.append(line)
|
|
||||||
#
|
|
||||||
# newData.append(('{0} {1} {2:.2f}\n'.format(self.playerName,
|
|
||||||
# self.game.getScore(), self.game.getTime())))
|
# self.game.getScore(), self.game.getTime())))
|
||||||
#
|
|
||||||
# with open (self.saveFileName, 'wb') as fileWithData:
|
data.append(
|
||||||
# pickle.dump(newData, fileWithData)
|
[self.playerName[:10],
|
||||||
#
|
int(self.game.getScore()),
|
||||||
# fileWithData.close()
|
float(self.game.getTime())]
|
||||||
|
)
|
||||||
|
|
||||||
|
with open(self.saveFileName, 'wb') as file:
|
||||||
|
for entry in data:
|
||||||
|
string = '{} {} {}\n'.format(*entry)
|
||||||
|
arr = string.encode('ascii')
|
||||||
|
file.write(self.shiftLeft(arr))
|
||||||
|
|
||||||
|
|
||||||
|
def shiftLeft(self, arr):
|
||||||
|
return bytearray([lambda x: x if x == 10 else x-32 for x in arr])
|
||||||
|
|
||||||
|
|
||||||
|
def shiftRight(self, arr):
|
||||||
|
return bytearray([lambda x: x if x == 10 else x+32 for x in arr])
|
||||||
|
|
||||||
|
|
||||||
def renderText(self, text, font, color, center, backColor=None):
|
def renderText(self, text, font, color, center, backColor=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user