From 05acc17262bcc35baf5653524a7651eae37691d3 Mon Sep 17 00:00:00 2001 From: En Yi Date: Fri, 20 Jul 2018 14:02:16 +0800 Subject: [PATCH] Fix scoreboard behaviour --- gameplay/test_board.txt | 2 +- general/highscore.py | 6 +++--- graphic_components/scoreboard.py | 4 +++- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/gameplay/test_board.txt b/gameplay/test_board.txt index 08676d6..58b36d3 100644 --- a/gameplay/test_board.txt +++ b/gameplay/test_board.txt @@ -6,4 +6,4 @@ 8,9,1,2,3,4,5,6,7 3,4,5,6,7,8,9,1,2 6,7,8,9,1,2,3,4,5 -9,1,2,3,4,5,6,7, \ No newline at end of file +9,1,2,3,4,5,6,7,0 \ No newline at end of file diff --git a/general/highscore.py b/general/highscore.py index 294b8ee..6057cbc 100644 --- a/general/highscore.py +++ b/general/highscore.py @@ -42,10 +42,10 @@ def write_highscore_file(file, data): def replace_placing(data, difficulty, name, time): - for info in data[difficulty]: + for i, info in enumerate(data[difficulty]): if time < info['time']: - info['name'] = name - info['time'] = time + data[difficulty].insert(i, {'name': name, 'time': time}) + data[difficulty].pop(-1) break diff --git a/graphic_components/scoreboard.py b/graphic_components/scoreboard.py index 4f6a992..7b052a6 100644 --- a/graphic_components/scoreboard.py +++ b/graphic_components/scoreboard.py @@ -190,6 +190,7 @@ class ScoreGrid(QGridLayout): def set_highscore(self, difficulty, name, time): hs.replace_placing(self.highscore_list, difficulty, name, time) + hs.write_highscore_file(hs_file, self.highscore_list) self.replace_scores(difficulty) self.scoreUpdate.emit(difficulty) @@ -209,6 +210,7 @@ class NameInput(QWidget): self.layout.addWidget(self.rank_label) self.name_input = QLineEdit(self) + self.name_input.setMaxLength(13) self.layout.addWidget(self.name_input) self.time_display = QLabel('-:-:-') @@ -216,7 +218,7 @@ class NameInput(QWidget): self.name_input.returnPressed.connect(self.receive_name_input) self.name_input.setStyleSheet(""" - border: 2px solid gray; + border-top: 1px solid white; """) def receive_name_input(self):