Add functioning difficulty selection
parent
e82d26c7bc
commit
07e4a188e5
|
@ -120,9 +120,9 @@ class SudokuSystem:
|
||||||
for r, c in zip(row, col):
|
for r, c in zip(row, col):
|
||||||
self.cell_status[r, c] = EMPTY
|
self.cell_status[r, c] = EMPTY
|
||||||
|
|
||||||
def generate_random_board(self):
|
def generate_random_board(self, difficulty):
|
||||||
self.clear_grid()
|
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)
|
row, col = np.where(self.number_grid == 0)
|
||||||
|
|
||||||
for r, c in zip(row, col):
|
for r, c in zip(row, col):
|
||||||
|
|
|
@ -115,7 +115,7 @@ class GameBoard(BoxBoard):
|
||||||
self.gamegrid.setFocus(Qt.MouseFocusReason)
|
self.gamegrid.setFocus(Qt.MouseFocusReason)
|
||||||
|
|
||||||
self.anim.finished.connect(lambda: self.show_playmenu(True))
|
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)
|
self.toggle_anim(True)
|
||||||
|
|
||||||
def show_number_ring(self, x=0, y=0):
|
def show_number_ring(self, x=0, y=0):
|
||||||
|
@ -138,6 +138,7 @@ class GameBoard(BoxBoard):
|
||||||
self.gamegrid.setFocus()
|
self.gamegrid.setFocus()
|
||||||
|
|
||||||
def show_grid(self, state):
|
def show_grid(self, state):
|
||||||
|
if state ^ self.gamegrid.isVisible():
|
||||||
self.gamegrid.setVisible(state)
|
self.gamegrid.setVisible(state)
|
||||||
if state:
|
if state:
|
||||||
self.gamegrid.toggle_anim(True)
|
self.gamegrid.toggle_anim(True)
|
||||||
|
@ -145,9 +146,10 @@ class GameBoard(BoxBoard):
|
||||||
def show_playmenu(self, state):
|
def show_playmenu(self, state):
|
||||||
self.playmenu.setVisible(state)
|
self.playmenu.setVisible(state)
|
||||||
|
|
||||||
def new_game(self):
|
def new_game(self, string):
|
||||||
print('new game selected')
|
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):
|
class MenuBoard(BoxBoard):
|
||||||
|
@ -173,7 +175,7 @@ class MenuBoard(BoxBoard):
|
||||||
self.setLayout(self.layout)
|
self.setLayout(self.layout)
|
||||||
|
|
||||||
self.show_children(False)
|
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)
|
self.toggle_anim(True)
|
||||||
|
|
||||||
def show_difficulty(self, state):
|
def show_difficulty(self, state):
|
||||||
|
|
|
@ -11,6 +11,7 @@ from PyQt5.QtCore import (QAbstractAnimation, QObject, QPointF, Qt, QRectF, QLin
|
||||||
|
|
||||||
from . import buttons
|
from . import buttons
|
||||||
|
|
||||||
|
DIFFICULTIES = ['Very Easy', 'Easy', 'Normal', 'Hard', 'Insane']
|
||||||
|
|
||||||
class TimerDisplayer(QGraphicsWidget):
|
class TimerDisplayer(QGraphicsWidget):
|
||||||
|
|
||||||
|
@ -113,7 +114,7 @@ class DifficultyMenu(QGraphicsWidget):
|
||||||
super().__init__(parent=parent)
|
super().__init__(parent=parent)
|
||||||
|
|
||||||
self.diff_buttons = []
|
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_height = height
|
||||||
self.btn_width = width
|
self.btn_width = width
|
||||||
self.height = (self.btn_height + 10) * 5
|
self.height = (self.btn_height + 10) * 5
|
||||||
|
@ -121,14 +122,9 @@ class DifficultyMenu(QGraphicsWidget):
|
||||||
|
|
||||||
for i in range(5):
|
for i in range(5):
|
||||||
btn = buttons.animBox(0, (self.btn_height + 10) * i,
|
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)
|
btn.buttonClicked.connect(self.clicked_on)
|
||||||
self.diff_buttons.append(btn)
|
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):
|
def clicked_on(self, string):
|
||||||
self.menuClicked.emit(string)
|
self.menuClicked.emit(string)
|
||||||
|
|
|
@ -134,8 +134,8 @@ class SudokuGrid(BaseSudokuItem):
|
||||||
|
|
||||||
self.anim.start()
|
self.anim.start()
|
||||||
|
|
||||||
def generate_new_grid(self):
|
def generate_new_grid(self, difficulty):
|
||||||
self.sudoku_grid.generate_random_board()
|
self.sudoku_grid.generate_random_board(difficulty)
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def replace_cell_number(self, val):
|
def replace_cell_number(self, val):
|
||||||
|
@ -258,7 +258,7 @@ class NumberRing(BaseSudokuItem):
|
||||||
|
|
||||||
|
|
||||||
class PlayMenu(BaseSudokuItem):
|
class PlayMenu(BaseSudokuItem):
|
||||||
buttonClicked = pyqtSignal()
|
buttonClicked = pyqtSignal(str)
|
||||||
|
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
super().__init__(parent=parent)
|
super().__init__(parent=parent)
|
||||||
|
@ -276,6 +276,6 @@ class PlayMenu(BaseSudokuItem):
|
||||||
def boundingRect(self):
|
def boundingRect(self):
|
||||||
return self.diff_select.boundingRect()
|
return self.diff_select.boundingRect()
|
||||||
|
|
||||||
def difficulty_selected(self):
|
def difficulty_selected(self, string):
|
||||||
self.setVisible(False)
|
self.setVisible(False)
|
||||||
self.buttonClicked.emit()
|
self.buttonClicked.emit(string)
|
||||||
|
|
Loading…
Reference in New Issue