master
En Yi 2018-07-21 17:03:25 +08:00
parent e9be3dca6d
commit 3aedc13608
3 changed files with 12 additions and 22 deletions

View File

@ -26,9 +26,6 @@ class SudokuSystem:
row.append([]) row.append([])
self.offending_cells.append(row) self.offending_cells.append(row)
if TESTING:
self.generate_test_board()
def clear_grid(self): def clear_grid(self):
self.number_grid[:] = 0 self.number_grid[:] = 0
self.cell_status[:] = FIXED self.cell_status[:] = FIXED

View File

@ -109,7 +109,6 @@ class GameBoard(BoxBoard):
self.show_playmenu(False) self.show_playmenu(False)
self.gamegrid.buttonClicked.connect(self.show_number_ring) self.gamegrid.buttonClicked.connect(self.show_number_ring)
#self.numring.connect_button_signals(self.select_ring_number)
self.numring.keyPressed.connect(self.select_ring_number) self.numring.keyPressed.connect(self.select_ring_number)
self.gamegrid.setFocus(Qt.MouseFocusReason) self.gamegrid.setFocus(Qt.MouseFocusReason)
@ -152,7 +151,6 @@ class GameBoard(BoxBoard):
self.playmenu.setVisible(state) self.playmenu.setVisible(state)
def new_game(self, string): def new_game(self, string):
print('new game selected')
self.gamegrid.generate_new_grid(menu_grap.DIFFICULTIES.index(string)) self.gamegrid.generate_new_grid(menu_grap.DIFFICULTIES.index(string))
self.show_grid(True) self.show_grid(True)
self.newGameSelected.emit(string) self.newGameSelected.emit(string)
@ -160,8 +158,8 @@ class GameBoard(BoxBoard):
def paint(self, painter, style, widget=None): def paint(self, painter, style, widget=None):
super().paint(painter, style, widget) super().paint(painter, style, widget)
painter.drawText(QRectF(0, self.height+15,self.width,15), Qt.AlignCenter, painter.drawText(QRectF(0, self.height+15, self.width, 15), Qt.AlignCenter,
"Hold M to mark numbers in a cell") "Hold M to scribble down numbers in a cell")
class MenuBoard(BoxBoard): class MenuBoard(BoxBoard):

View File

@ -5,7 +5,7 @@ This module contains the components that make up the Sudoku Board
import numpy as np import numpy as np
from PyQt5.QtCore import (QAbstractAnimation, QPointF, Qt, QRectF, QLineF, from PyQt5.QtCore import (QAbstractAnimation, QPointF, Qt, QRectF, QLineF,
QPropertyAnimation, pyqtProperty, pyqtSignal) QPropertyAnimation, pyqtProperty, pyqtSignal)
from PyQt5.QtGui import QPen, QFont, QKeyEvent from PyQt5.QtGui import QPen, QFont
from PyQt5.QtWidgets import QGraphicsItem, QGraphicsObject from PyQt5.QtWidgets import QGraphicsItem, QGraphicsObject
from gameplay import sudoku_gameplay as sdk from gameplay import sudoku_gameplay as sdk
@ -13,6 +13,8 @@ from general.extras import bound_value
from . import buttons from . import buttons
from . import menu_graphics as menu_grap from . import menu_graphics as menu_grap
SCRIBBLE_KEY = Qt.Key_M
class BaseSudokuItem(QGraphicsObject): class BaseSudokuItem(QGraphicsObject):
@ -84,7 +86,6 @@ class NumberPainter(BaseSudokuItem):
class SudokuGrid(BaseSudokuItem): class SudokuGrid(BaseSudokuItem):
# TODO: Add functions to animated the grid lines
buttonClicked = pyqtSignal(float, float, bool) buttonClicked = pyqtSignal(float, float, bool)
finishDrawing = pyqtSignal() finishDrawing = pyqtSignal()
puzzleFinished = pyqtSignal() puzzleFinished = pyqtSignal()
@ -231,12 +232,12 @@ class SudokuGrid(BaseSudokuItem):
def keyPressEvent(self, event): def keyPressEvent(self, event):
if not event.isAutoRepeat(): if not event.isAutoRepeat():
if (event.key() == Qt.Key_M) and not self.scribbling: if (event.key() == SCRIBBLE_KEY) and not self.scribbling:
self.scribbling = True self.scribbling = True
def keyReleaseEvent(self, event): def keyReleaseEvent(self, event):
if not event.isAutoRepeat(): if not event.isAutoRepeat():
if event.key() == Qt.Key_M and self.scribbling: if event.key() == SCRIBBLE_KEY and self.scribbling:
self.scribbling = False self.scribbling = False
# Defining the length to be drawn as a pyqtProperty # Defining the length to be drawn as a pyqtProperty
@ -265,8 +266,6 @@ class SudokuGrid(BaseSudokuItem):
class NumberRing(BaseSudokuItem): class NumberRing(BaseSudokuItem):
# TODO: Add functions to animated the ring appearing
# TODO: Adjust the positioning of each element
# TODO: Make it transparent when mouse is out of range # TODO: Make it transparent when mouse is out of range
loseFocus = pyqtSignal() loseFocus = pyqtSignal()
keyPressed = pyqtSignal(str, bool) keyPressed = pyqtSignal(str, bool)
@ -287,7 +286,6 @@ class NumberRing(BaseSudokuItem):
btn = buttons.AnimBox(0, 0, self.cell_width, btn = buttons.AnimBox(0, 0, self.cell_width,
self.cell_height, cell_string, parent=self) self.cell_height, cell_string, parent=self)
btn.buttonClicked.connect(self.send_button_press) btn.buttonClicked.connect(self.send_button_press)
#btn.buttonClicked.connect(self.close_menu)
self.cell_buttons.append(btn) self.cell_buttons.append(btn)
self.radius = 54 self.radius = 54
@ -357,9 +355,7 @@ class NumberRing(BaseSudokuItem):
def keyPressEvent(self, event): def keyPressEvent(self, event):
if not event.isAutoRepeat(): if not event.isAutoRepeat():
print('Pressed:', event.key()) if (event.key() == SCRIBBLE_KEY) and not self.scribbling:
if (event.key() == Qt.Key_M) and not self.scribbling:
print('Scribbling On')
self.scribbling = True self.scribbling = True
if event.key() == 88: if event.key() == 88:
txt = 'X' txt = 'X'
@ -369,16 +365,13 @@ class NumberRing(BaseSudokuItem):
txt = '' txt = ''
if txt: if txt:
print('keypress:', txt)
self.keyPressed.emit(txt, self.scribbling) self.keyPressed.emit(txt, self.scribbling)
if not self.scribbling: if not self.scribbling:
self.clearFocus() self.clearFocus()
def keyReleaseEvent(self, event): def keyReleaseEvent(self, event):
if not event.isAutoRepeat(): if not event.isAutoRepeat():
print('Released:', event.key()) if event.key() == SCRIBBLE_KEY and self.scribbling:
if event.key() == Qt.Key_M and self.scribbling:
print('Scribbling Off')
self.scribbling = False self.scribbling = False
# Defining the length to be drawn as a pyqtProperty # Defining the length to be drawn as a pyqtProperty
@ -415,7 +408,9 @@ class PlayMenu(BaseSudokuItem):
self.diff_select.menuClicked.connect(self.difficulty_selected) self.diff_select.menuClicked.connect(self.difficulty_selected)
def paint(self, painter, style, widget=None): def paint(self, painter, style, widget=None):
pass painter.setPen(self.default_pen)
painter.setFont(self.default_font)
painter.drawText(self.rect, Qt.AlignHCenter, 'Select A Difficulty')
def boundingRect(self): def boundingRect(self):
return self.diff_select.boundingRect() return self.diff_select.boundingRect()