From 07e4a188e59243b97c808b6122edc6281ecf7b60 Mon Sep 17 00:00:00 2001 From: En Yi Date: Fri, 13 Jul 2018 14:37:27 +0800 Subject: [PATCH] Add functioning difficulty selection --- gameplay/sudoku_gameplay.py | 4 ++-- graphic_components/board.py | 16 +++++++++------- graphic_components/menu_graphics.py | 10 +++------- graphic_components/sudoku_graphics.py | 10 +++++----- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/gameplay/sudoku_gameplay.py b/gameplay/sudoku_gameplay.py index 90f07a4..308feb2 100644 --- a/gameplay/sudoku_gameplay.py +++ b/gameplay/sudoku_gameplay.py @@ -120,9 +120,9 @@ class SudokuSystem: for r, c in zip(row, col): self.cell_status[r, c] = EMPTY - def generate_random_board(self): + def generate_random_board(self, difficulty): self.clear_grid() - self.number_grid[:] = sdk_gen.generate_sudoku_puzzle(2) + self.number_grid[:] = sdk_gen.generate_sudoku_puzzle(difficulty) row, col = np.where(self.number_grid == 0) for r, c in zip(row, col): diff --git a/graphic_components/board.py b/graphic_components/board.py index aa2ee6e..e96c41c 100644 --- a/graphic_components/board.py +++ b/graphic_components/board.py @@ -115,7 +115,7 @@ class GameBoard(BoxBoard): self.gamegrid.setFocus(Qt.MouseFocusReason) self.anim.finished.connect(lambda: self.show_playmenu(True)) - self.playmenu.buttonClicked.connect(lambda: self.show_grid(True)) + self.playmenu.buttonClicked.connect(self.new_game) self.toggle_anim(True) def show_number_ring(self, x=0, y=0): @@ -138,16 +138,18 @@ class GameBoard(BoxBoard): self.gamegrid.setFocus() def show_grid(self, state): - self.gamegrid.setVisible(state) - if state: - self.gamegrid.toggle_anim(True) + if state ^ self.gamegrid.isVisible(): + self.gamegrid.setVisible(state) + if state: + self.gamegrid.toggle_anim(True) def show_playmenu(self, state): self.playmenu.setVisible(state) - def new_game(self): + def new_game(self, string): print('new game selected') - self.gamegrid.generate_new_grid() + self.gamegrid.generate_new_grid(menu_grap.DIFFICULTIES.index(string)) + self.show_grid(True) class MenuBoard(BoxBoard): @@ -173,7 +175,7 @@ class MenuBoard(BoxBoard): self.setLayout(self.layout) self.show_children(False) - self.anim.finished.connect(lambda: self.show_children(True)) + #self.anim.finished.connect(lambda: self.show_children(True)) self.toggle_anim(True) def show_difficulty(self, state): diff --git a/graphic_components/menu_graphics.py b/graphic_components/menu_graphics.py index 3d082f2..ce2a103 100644 --- a/graphic_components/menu_graphics.py +++ b/graphic_components/menu_graphics.py @@ -11,6 +11,7 @@ from PyQt5.QtCore import (QAbstractAnimation, QObject, QPointF, Qt, QRectF, QLin from . import buttons +DIFFICULTIES = ['Very Easy', 'Easy', 'Normal', 'Hard', 'Insane'] class TimerDisplayer(QGraphicsWidget): @@ -113,7 +114,7 @@ class DifficultyMenu(QGraphicsWidget): super().__init__(parent=parent) self.diff_buttons = [] - self.difficulty = ['Very Easy', 'Easy', 'Normal', 'Hard', 'Insane'] + #self.difficulty = ['Very Easy', 'Easy', 'Normal', 'Hard', 'Insane'] self.btn_height = height self.btn_width = width self.height = (self.btn_height + 10) * 5 @@ -121,14 +122,9 @@ class DifficultyMenu(QGraphicsWidget): for i in range(5): btn = buttons.animBox(0, (self.btn_height + 10) * i, - self.btn_width, self.btn_height, self.difficulty[i], parent=self) + self.btn_width, self.btn_height, DIFFICULTIES[i], parent=self) btn.buttonClicked.connect(self.clicked_on) self.diff_buttons.append(btn) - #def connect_buttons_signal(self, func): - # for btn in self.diff_buttons: - #btn.buttonClicked.connect(func) - # btn.buttonClicked.connect(self.clicked_on) - def clicked_on(self, string): self.menuClicked.emit(string) diff --git a/graphic_components/sudoku_graphics.py b/graphic_components/sudoku_graphics.py index 4c1b120..f4c4116 100644 --- a/graphic_components/sudoku_graphics.py +++ b/graphic_components/sudoku_graphics.py @@ -134,8 +134,8 @@ class SudokuGrid(BaseSudokuItem): self.anim.start() - def generate_new_grid(self): - self.sudoku_grid.generate_random_board() + def generate_new_grid(self, difficulty): + self.sudoku_grid.generate_random_board(difficulty) self.update() def replace_cell_number(self, val): @@ -258,7 +258,7 @@ class NumberRing(BaseSudokuItem): class PlayMenu(BaseSudokuItem): - buttonClicked = pyqtSignal() + buttonClicked = pyqtSignal(str) def __init__(self, parent): super().__init__(parent=parent) @@ -276,6 +276,6 @@ class PlayMenu(BaseSudokuItem): def boundingRect(self): return self.diff_select.boundingRect() - def difficulty_selected(self): + def difficulty_selected(self, string): self.setVisible(False) - self.buttonClicked.emit() + self.buttonClicked.emit(string)