diff --git a/general/highscore.py b/general/highscore.py index 5c973de..294b8ee 100644 --- a/general/highscore.py +++ b/general/highscore.py @@ -1,4 +1,4 @@ -DIFFICULTIES = ['Very Easy', 'Easy', 'Medium', 'Hard', 'Insane'] +DIFFICULTIES = ['Very Easy', 'Easy', 'Normal', 'Hard', 'Insane'] def generate_highscore_file(file): @@ -49,13 +49,11 @@ def replace_placing(data, difficulty, name, time): break -def check_ranking(data, difficulty, name, time): +def check_ranking(data, difficulty, time): rank = -1 for rnk, info in enumerate(data[difficulty]): if time < info['time']: - info['name'] = name - info['time'] = time - rank = -1 + rank = rnk break return rank diff --git a/graphic_components/board.py b/graphic_components/board.py index 59b8622..bef49c3 100644 --- a/graphic_components/board.py +++ b/graphic_components/board.py @@ -182,6 +182,8 @@ class MenuBoard(BoxBoard): self.score_display.setX(self.width - self.margin) self.score_display.setY(self.height - self.margin) + self.score_display.scoreboard_widget.highScoreSet.connect(self.return_to_normal) + self.show_children(False) self.toggle_anim(True) @@ -198,5 +200,15 @@ class MenuBoard(BoxBoard): self.diff_display.set_text(string) self.timer_display.reset_time() - def stop_timer(self): + def finish_the_game(self): self.timer_display.timer.stop() + diff = self.diff_display.text + time = self.timer_display.get_time() + if self.score_display.scoreboard_widget.check_ranking(diff, time): + self.diff_display.set_disabled(True) + self.score_display.set_disabled(True) + self.score_display.show_board(True) + + def return_to_normal(self): + self.diff_display.set_disabled(False) + self.score_display.set_disabled(False) diff --git a/graphic_components/menu_graphics.py b/graphic_components/menu_graphics.py index 0a046bb..a6fbfae 100644 --- a/graphic_components/menu_graphics.py +++ b/graphic_components/menu_graphics.py @@ -57,6 +57,11 @@ class TimerDisplayer(QGraphicsWidget): self.atenth_seconds = 0 self.timer.start() + def get_time(self): + return "{:02d}:{:02d}:{:1d}".format(int(self.atenth_seconds/600), + int(self.atenth_seconds/10) % 60, + self.atenth_seconds % 10) + def paint(self, painter, style, widget=None): box = self.timer_box painter.setPen(self.box_pen) @@ -194,11 +199,11 @@ class HighScoreDisplayer(QGraphicsObject): self.scoreboard_widget.setVisible(False) self.setAcceptHoverEvents(True) - + #self.show_board(True) self.selected = False def set_disabled(self, state): - self.setAcceptHoverEvents(state) + self.setAcceptHoverEvents(not state) def show_board(self, state): self.scoreboard_widget.setVisible(state) diff --git a/graphic_components/scoreboard.py b/graphic_components/scoreboard.py index b7bb56f..60bd5a2 100644 --- a/graphic_components/scoreboard.py +++ b/graphic_components/scoreboard.py @@ -15,7 +15,9 @@ from general import highscore as hs BACKWARD = 1 FORWARD = -1 + class HighScoreBoard(QWidget): + highScoreSet = pyqtSignal() def __init__(self, width, height): super().__init__() @@ -54,6 +56,21 @@ class HighScoreBoard(QWidget): def set_score(self, name): self.score_grid.set_highscore(self.current_difficulty, name, self.final_time) + self.name_input.setVisible(False) + self.highScoreSet.emit() + + def check_ranking(self, difficulty, time): + self.current_difficulty = difficulty + self.final_time = time + rank = self.score_grid.get_rank(difficulty, time) + if rank >= 0: + self.diff_switch.go_to_difficulty(difficulty) + self.score_grid.replace_scores(difficulty) + self.name_input.setVisible(True) + self.name_input.rank_label.setText(str(rank+1)) + self.name_input.time_display.setText(time) + return True + return False class DifficultySwitch(QHBoxLayout): @@ -109,7 +126,7 @@ class DifficultySwitch(QHBoxLayout): self.timer.start() def go_to_difficulty(self, difficulty): - pos = (hs.DIFFICULTIES.index(difficulty) + 1) * self.max_length + pos = (hs.DIFFICULTIES[::-1].index(difficulty) + 1) * self.max_length self.show_pos = pos self.next_pos = pos @@ -169,6 +186,10 @@ class ScoreGrid(QGridLayout): self.replace_scores(difficulty) self.scoreUpdate.emit(difficulty) + def get_rank(self, difficulty, time): + return hs.check_ranking(self.highscore_list, difficulty, time) + + class NameInput(QWidget): nameReceived = pyqtSignal(str) @@ -177,10 +198,14 @@ class NameInput(QWidget): self.layout = QHBoxLayout(self) - self.layout.addWidget(QLabel('Name')) + self.rank_label = QLabel('-') + self.layout.addWidget(self.rank_label) self.name_input = QLineEdit(self) self.layout.addWidget(self.name_input) + + self.time_display = QLabel('-:-:-') + self.layout.addWidget(self.time_display) self.name_input.returnPressed.connect(self.receive_name_input) self.name_input.setStyleSheet(""" diff --git a/graphic_components/sudoku_graphics.py b/graphic_components/sudoku_graphics.py index 1edd825..467a7cd 100644 --- a/graphic_components/sudoku_graphics.py +++ b/graphic_components/sudoku_graphics.py @@ -149,6 +149,7 @@ class SudokuGrid(BaseSudokuItem): def generate_new_grid(self, difficulty): self.sudoku_grid.generate_random_board(difficulty) + #self.sudoku_grid.generate_test_board() self.update() def replace_cell_number(self, val): diff --git a/main.py b/main.py index dac0373..f14fc99 100644 --- a/main.py +++ b/main.py @@ -45,7 +45,7 @@ class SudokuWindow(QGraphicsView): # Cross-Board signal connections self.gameboard.gridDrawn.connect(lambda: self.menuboard.show_children(True)) self.gameboard.newGameSelected.connect(self.menuboard.set_difficulty_text) - self.gameboard.sudokuDone.connect(self.menuboard.stop_timer) + self.gameboard.sudokuDone.connect(self.menuboard.finish_the_game) self.menuboard.diff_display.notFocus.connect(self.gameboard.game_refocus) self.menuboard.diff_display.difficultySelected.connect(self.gameboard.new_game)