Esempio n. 1
0
    def draw_board(self, size=Cons.SIZE):
        """ Draw playing board """

        self.board_size = size
        self.c_size, self.r_size = Cons.SIZE_DICT[self.board_size]
        self.digits = Cons.DIGITS[:self.board_size]
        Tile.board_size = self.board_size
        Tile.digits = self.digits

        self.content = [["0"] * self.board_size for _ in range(self.board_size)]
        self.sudoku = [["0"] * self.board_size for _ in range(self.board_size)]
        self.tiles = [[None] * self.board_size for _ in range(self.board_size)]
        self.poss_tiles = [[None] * self.board_size for _ in range(self.board_size)]

        board_w = self.board_size * (Cons.WIDTH + Cons.MARGIN) + Cons.MARGIN  # width of playing board
        board_h = self.board_size * (Cons.HEIGHT + Cons.MARGIN) + Cons.MARGIN  # height of playing board
        board_x = (Cons.WINDOW_SIZE[0] - board_w) / 2  # x-coordinate of scrabble board
        board_y = (Cons.WINDOW_SIZE[1] - board_h) / 2  # y-coordinate of scrabble board
        board = [board_x, board_y, board_w, board_h]  # board rect details

        self.cells = []
        self.background_item = QGraphicsRectItem(board[0], board[1],
                                                 board[2], board[3])
        self.background_item.persistent = False
        self.background_item.setBrush(Qt.black)

        for row in range(self.board_size):
            for col in range(self.board_size):
                left_adj = Cons.INT_CELLS if col % self.c_size else 0
                top_adj = Cons.INT_CELLS if row % self.r_size else 0
                width_adj = Cons.INT_CELLS if col % self.c_size else 0
                height_adj = Cons.INT_CELLS if row % self.r_size else 0
                square = QGraphicsRectItem(board[0] + (Cons.MARGIN + Cons.WIDTH) * col +
                                           Cons.MARGIN - left_adj, board[1] + (Cons.MARGIN + Cons.HEIGHT) * row +
                                           Cons.MARGIN - top_adj, Cons.WIDTH + width_adj, Cons.HEIGHT + height_adj,
                                           parent=self.background_item)
                self.cells.append(square.rect())
                setattr(square, 'cell', (row, col))
                colour = Cons.NORMAL_COLOUR
                square.setBrush(QColor(colour[0], colour[1], colour[2]))
                square.setToolTip("Square")
                square.persistent = False

        self.scene.addItem(self.background_item)
        self.set_digits()
Esempio n. 2
0
    def __init__(self, scene):
        super(Setbuttons, self).__init__()

        self.scene = scene
        self.buttons = {}  # Register of buttons as {name: button}

        buttonParent = QGraphicsRectItem()
        buttonParent.persistent = True

        self.playButton, self.acceptButton, self.passButton = None, None, None
        self.challengeButton, self.exchangeButton, self.quitButton = None, None, None
        self.nextButton, self.backButton, self.endButton, self.newButton = None, None, None, None

        self.setup_buttons(buttonParent)
        self.set_button_pos()
        # self.reset_tips()
        self.scene.addItem(buttonParent)
        buttonParent.setScale(0.75)
        buttonParent.setPos(200, 200)
        buttonParent.setZValue(65)