Exemplo n.º 1
0
 def place_white_royals(self):
     xKing, yKing = Position.get_position(
         self.whiteTeam.player.king[0].get_position())
     self.chess_board_canvas.create_image(
         xKing,
         yKing,
         image=self.whiteTeam.player.king[0].get_photo(),
         anchor=NW)
     for x in range(0, len(self.whiteTeam.player.queens)):
         x0, y0 = Position.get_position(
             self.whiteTeam.player.queens[x].get_position())
         self.chess_board_canvas.create_image(
             x0,
             y0,
             image=self.whiteTeam.player.queens[x].get_photo(),
             anchor=NW)
Exemplo n.º 2
0
    def generate_possible_moves(self, allPositions):
        self.possiblePositions.clear()

        direction = [-7, 7, -9, 9]

        for x in range(1, 7):
            for d in direction:
                newPosition = self.pos + d * x
                if 65 > newPosition > 0 and not Utils.isCollision(
                        newPosition, allPositions):
                    self.possiblePositions.append(newPosition)

        ## vertical
        for x in range(0, NUMBER_OF_COLUMNS):
            newPosition = self.pos + 8 * x
            if newPosition < 65 and not Utils.isCollision(
                    newPosition, allPositions):
                self.possiblePositions.append(newPosition)

        for x in range(0, NUMBER_OF_COLUMNS):
            newPosition = self.pos - 8 * x
            if newPosition > 0 and not Utils.isCollision(
                    newPosition, allPositions):
                self.possiblePositions.append(newPosition)

        # Horizontal
        currentRow, possiblePositions = Position.get_row_and_possible_places_in_row(
            self.pos)

        for x in possiblePositions:
            newPosition = x
            if newPosition is not self.pos and not Utils.isCollision(
                    newPosition, allPositions):
                self.possiblePositions.append(newPosition)
Exemplo n.º 3
0
 def place_black_pawns(self):
     for x in range(0, len(self.blackTeam.player.pawns)):
         x0, y0 = Position.get_position(
             self.blackTeam.player.pawns[x].get_position())
         self.chess_board_canvas.create_image(
             x0,
             y0,
             image=self.blackTeam.player.pawns[x].get_photo(),
             anchor=NW)
Exemplo n.º 4
0
 def place_white_bishops(self):
     for x in range(0, len(self.whiteTeam.player.bishops)):
         x0, y0 = Position.get_position(
             self.whiteTeam.player.bishops[x].get_position())
         self.chess_board_canvas.create_image(
             x0,
             y0,
             image=self.whiteTeam.player.bishops[x].get_photo(),
             anchor=NW)
Exemplo n.º 5
0
 def board_press(self, event):
     if self.firstPress is False:
         self.firstPress = True
         hasPiece, self.currentMovePiece = self.model.game.has_piece_on(
             Position.get_location(event.x, event.y))
         if hasPiece:
             if self.currentMovePiece.color != self.move:
                 self.currentMovePiece = None
                 pass
     else:
         pass
Exemplo n.º 6
0
    def place_piece(self, event):
        self.firstPress = False
        position = Position.get_location(event.x, event.y)
        if self.currentMovePiece is not None:
            possibleMoves = self.currentMovePiece.get_possible_moves()
            isMovePossible = False

            for pos in possibleMoves:
                if position == pos:
                    isMovePossible = True
                    break

            if isMovePossible:
                self.currentMovePiece.set_position(position)
                if self.move == WHITE:
                    self.move = BLACK
                else:
                    self.move = WHITE

            print("new position: ", position)
        self.view.refresh()
        self.model.refresh()