Exemplo n.º 1
0
    def display(self, screen: pygame.display) -> None:
        """Display the current Connect Four Board on screen"""
        w, h = screen.get_size()
        screen.fill((0, 0, 255))

        # Draw the lines on the board
        for i in range(1, self.n):
            pygame.draw.line(screen, (0, 0, 0), (0, h * i // self.n),
                             (w, h * i // self.n))
            pygame.draw.line(screen, (0, 0, 0), (w * i // self.n, 0),
                             (w * i // self.n, h))

        # Draw the markers
        for x in range(self.n):
            for y in range(self.n):
                if self.board[x][y] == 1:
                    color = (255, 0, 0)
                elif self.board[x][y] == 0:
                    color = (255, 255, 0)
                else:
                    color = (255, 255, 255)

                pygame.draw.circle(screen, color, ((y + 0.5) * (w // self.n),
                                                   (x + 0.5) * (h // self.n)),
                                   h // (3 * self.n))
        pygame.display.update()
Exemplo n.º 2
0
    def display(self, screen: pygame.display) -> None:
        """Display the current TicTacToe Board on screen"""
        w, h = screen.get_size()
        screen.fill((255, 255, 255))

        # Draw the lines on the board
        pygame.draw.line(screen, (0, 0, 0), (0, h // 3), (w, h // 3))
        pygame.draw.line(screen, (0, 0, 0), (0, 2 * h // 3), (w, 2 * h // 3))
        pygame.draw.line(screen, (0, 0, 0), (w // 3, 0), (w // 3, h))
        pygame.draw.line(screen, (0, 0, 0), (2 * w // 3, 0), (2 * w // 3, h))

        # Draw the markers
        font = pygame.font.SysFont('Calibri', 100)
        for x in range(3):
            for y in range(3):
                piece = font.render(
                    self.board_object(x, y),
                    True,
                    (0, 0, 0)
                )
                screen.blit(
                    piece,
                    (
                        (y + 0.3) * (w // 3),
                        (x + 0.3) * (h // 3)
                    )
                )
        pygame.display.update()
Exemplo n.º 3
0
 def __init__(self, screen: pygame.display):
     size = screen.get_size()
     self.x = (size[0] - ROCKSIZE[0]) / 2
     self.y = 7 * (size[1] - ROCKSIZE[1]) / 8
     self.velx = 0
     self.cooldown = 0
     self.shots = []
     self.lives = LIVES
     self.screen = screen
Exemplo n.º 4
0
    def get_human_input(self, screen: pygame.display,
                        click_loc: Optional[Tuple[int, int]]) -> Optional[GameState]:
        """Return the game state after a valid move has been inputted by the user"""
        if click_loc is None:
            return None
        w, h = screen.get_size()
        position = ((3 * click_loc[1]) // w, (3 * click_loc[0]) // h)

        new_game = TicTacToeGameState(self)
        if new_game.make_move(position, True):
            return new_game
        return None
Exemplo n.º 5
0
    def get_human_input(
            self, screen: pygame.display,
            click_loc: Optional[Tuple[int, int]]) -> Optional[GameState]:
        """Return the game state after a valid move has been inputted by the user"""
        if click_loc is None:
            return None
        w = screen.get_size()[0]
        position = (self.n * click_loc[0]) // w

        new_game = ConnectFourGameState(self.n, self)
        if new_game.make_move(position, True):
            return new_game
        return None
Exemplo n.º 6
0
    def get_human_input(
            self, screen: pygame.display,
            click_loc: Optional[Tuple[int, int]]) -> Optional[GameState]:
        """Return the game state after a valid move has been inputted by the user"""
        if click_loc is None:
            return None
        w, h = screen.get_size()
        position = ((self.n * click_loc[1]) // h, (self.n * click_loc[0]) // w)

        new_game = ReversiGameState(self.n, self)

        # Check if a pass is played
        if self.is_legal(None):
            new_game.make_move(None, False)
            return new_game

        if new_game.make_move(position, True):
            return new_game
        return None
Exemplo n.º 7
0
 def __init__(self, surface: pygame.display) -> None:
     self.bg = pygame.Surface(surface.get_size()).convert()  # surface
Exemplo n.º 8
0
def init_background(screen: pygame.display):
    background = pygame.Surface(screen.get_size())
    background = background.convert()
    background.fill((250, 250, 250))
    return background