예제 #1
0
def update_stone_player(screen, player_color):
    """
    Move the stone along the mouse cursor.
    """
    coord_x, coord_y = pygame.mouse.get_pos()
    white = pygame.image.load(rsrc_path('./img/stoneW.png')).convert_alpha()
    black = pygame.image.load(rsrc_path('./img/stoneB.png')).convert_alpha()
    coord_x = int((coord_x - 5) / 40) * 40 + 5
    coord_y = int((coord_y - 5) / 40) * 40 + 5
    screen.blit(white if player_color == 'w' else black,
                (round(coord_x), round(coord_y)))
예제 #2
0
 def launch(self):
     """
     Create the menu, launch the corresponding gamemode.
     """
     run = True
     while run:
         pygame.event.pump()
         background = pygame.image.load(rsrc_path('./img/MenuBG.jpg'))
         self.screen.blit(background, (0, 0))
         for event in pygame.event.get():
             if event.type == pygame.QUIT:
                 run = False
             elif event.type == pygame.KEYDOWN:
                 if event.key == pygame.K_ESCAPE:
                     run = False
             for option in self.options:
                 if option.surf.collidepoint(pygame.mouse.get_pos()):
                     option.hover = True
                     if (event.type == pygame.MOUSEBUTTONDOWN
                             and event.button == 1):
                         run = option.func(self.screen)
                 else:
                     option.hover = False
                 option.draw()
         for option in self.options:
             option.hover = bool(
                 option.surf.collidepoint(pygame.mouse.get_pos()))
             option.draw()
         pygame.display.update()
예제 #3
0
def display_board(screen, board):
    """
    Display the board and stones.
    """
    background = pygame.image.load(rsrc_path('./img/Goban.jpg'))
    white = pygame.image.load(rsrc_path('./img/stoneW.png')).convert_alpha()
    black = pygame.image.load(rsrc_path('./img/stoneB.png')).convert_alpha()
    screen.blit(background, (0, 0))
    for cpt_y in range(0, 19):
        for cpt_x in range(0, 19):
            coord_y = cpt_y * 40 + 5
            coord_x = cpt_x * 40 + 5
            if board[cpt_y][cpt_x] == 'b':
                screen.blit(black, (round(coord_x), round(coord_y)))
            elif board[cpt_y][cpt_x] == 'w':
                screen.blit(white, (round(coord_x), round(coord_y)))
예제 #4
0
class Launcher:
    """
    Class allowing pygame to load.
    """
    pygame.init()
    pygame.display.set_caption('Gomoku')
    pygame.display.set_icon(pygame.image.load(rsrc_path('./img/ico.png')))

    def __init__(self):
        self.screen = pygame.display.set_mode((770, 770))
        self.options = [
            Option("Player VS Player", (750, 430), self.screen,
                   gameplay.load_p_vs_p),
            Option("Player VS IA", (750, 480), self.screen,
                   gameplay.load_p_vs_ai),
            Option("Quit", (750, 750), self.screen, gameplay.r_false)
        ]

    def launch(self):
        """
        Create the menu, launch the corresponding gamemode.
        """
        run = True
        while run:
            pygame.event.pump()
            background = pygame.image.load(rsrc_path('./img/MenuBG.jpg'))
            self.screen.blit(background, (0, 0))
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    run = False
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        run = False
                for option in self.options:
                    if option.surf.collidepoint(pygame.mouse.get_pos()):
                        option.hover = True
                        if (event.type == pygame.MOUSEBUTTONDOWN
                                and event.button == 1):
                            run = option.func(self.screen)
                    else:
                        option.hover = False
                    option.draw()
            for option in self.options:
                option.hover = bool(
                    option.surf.collidepoint(pygame.mouse.get_pos()))
                option.draw()
            pygame.display.update()

    def exit(self):
        """
        Exit.
        """
        _ = self
        pygame.quit()
        return 0
예제 #5
0
def set_color_player():
    """
    Choose the player color (mode Player vs AI).
    """
    screen = pygame.display.set_mode((770, 770))
    options = [
        Option("Black", (750, 430), screen, r_text),
        Option("White", (750, 480), screen, r_text),
        Option("Return", (750, 750), screen, r_text)
    ]
    run = True
    color = None
    while run:
        pygame.event.pump()
        background = pygame.image.load(rsrc_path('./img/MenuBG.jpg'))
        screen.blit(background, (0, 0))
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                run = False
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    run = False
            for option in options:
                if option.surf.collidepoint(pygame.mouse.get_pos()):
                    option.hover = True
                    if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
                        run, color = option.func(option.text)
                else:
                    option.hover = False
                option.draw()
        for option in options:
            option.hover = bool(
                option.surf.collidepoint(pygame.mouse.get_pos()))
            option.draw()
        pygame.display.update()
    return color