Ejemplo n.º 1
0
class MatchMenu:

    def __init__(self, screen):
        self._screen = screen
        self._menu = Menu(50, 50, 20, 5, 'horizontal', 100, screen,
                          [('Player 1', 1, None),
                           ('Player 2', 2, None)], "assets/backgrounds/player_menu.png")

        self._menu.set_center(True, True)
        self._menu.set_alignment('center', 'center')
        self.on_reset()

    def on_init(self):
        pass

    def on_event(self, event):
        if event.type == pygame.KEYDOWN or event.type == u.EVENT_CHANGE_STATE:
            if self._state == 0:
                self._rect_list, self._state = self._menu.update(event, self._state)
            if self._state == 1:
                m.on_change_menu('player1')  # Go to player1
            if (m.get_player_1() is not None) and self._state == 2:
                m.on_change_menu('player2')  # Go to player2
            self._state = 0
            # Go back
            if event.key == pygame.K_ESCAPE:
                m.on_change_menu('main')  # Go to main menu
            # Play match
            if event.key == pygame.K_SPACE:
                m.start_game()  # Go to main menu

    def on_loop(self):
        if self._prev_state != self._state:
            pygame.event.post(pygame.event.Event(u.EVENT_CHANGE_STATE, key=0))
            self._prev_state = self._state
        self._ready = (m.get_player_1() is not None) and (m.get_player_2() is not None)

    def on_render(self):
        # Render the screen
        pygame.display.update(self._rect_list)
        # Draw players
        player1 = m.get_player_1()
        if player1 is not None:
            player1.render(self._screen, left=True)
        player2 = m.get_player_2()
        if player2 is not None:
            player2.render(self._screen, left=False)
        if self._ready:
            text = text = u.fonts['main'].render("Press SPACE to start", 1, u.WHITE)
            self._screen.blit(text, (200, 450))

    def on_reset(self):
        self._state = 0
        self._prev_state = 1
        self._ready = False
        self._rect_list = []
Ejemplo n.º 2
0
class ColourMenu:

    def __init__(self, screen, previous):
        self._previous = previous

        self._menu = Menu(50, 50, 20, 5, 'horizontal', 100, screen,
                          [('Image', 1, u.red_image),
                           ('Image', 2, u.blue_image),
                           ('Image', 3, u.green_image),
                           ('Image', 4, u.yellow_image),
                           ('Image', 5, u.white_image)], "assets/backgrounds/color_menu.png")

        self._menu.set_center(True, True)
        self._menu.set_alignment('center', 'center')
        self._state = 0
        self._prev_state = 1
        self._rect_list = []

    def on_init(self):
        pass

    def on_event(self, event):
        if event.type == pygame.KEYDOWN or event.type == u.EVENT_CHANGE_STATE:
            colour_selected = None
            if self._state == 0:
                self._rect_list, self._state = self._menu.update(event, self._state)
            if event.key == pygame.K_RETURN:
                if self._state == 1:
                    colour_selected = u.RED
                elif self._state == 2:
                    colour_selected = u.BLUE
                elif self._state == 3:
                    colour_selected = u.GREEN
                elif self._state == 4:
                    colour_selected = u.YELLOW
                elif self._state == 5:
                    colour_selected = u.WHITE
                if colour_selected is not None:
                    m.create_player(colour=colour_selected)
                    m.on_change_menu(self._previous)
            self._state = 0
            # Go back
            if event.key == pygame.K_ESCAPE:
                m.on_change_menu(self._previous)  # Go to create player

    def on_loop(self):
        if self._prev_state != self._state:
            pygame.event.post(pygame.event.Event(u.EVENT_CHANGE_STATE, key=0))
            self._prev_state = self._state

    def on_render(self):
        # Render the screen
        pygame.display.update(self._rect_list)
Ejemplo n.º 3
0
class TournamentMenu:

    def __init__(self, screen):
        self._screen = screen
        self._menu = Menu(50, 50, 20, 5, 'horizontal', 100, screen,
                          [('Add player', 1, None)])

        self._menu.set_center(True, True)
        self._menu.set_alignment('center', 'center')
        self.on_reset()

    def on_init(self):
        pass

    def on_event(self, event):
        if event.type == pygame.KEYDOWN or event.type == EVENT_CHANGE_STATE:
            if self._state == 0:
                self._rect_list, self._state = self._menu.update(event, self._state)
            if self._state == 1:
                m.on_change_menu('player_tournament')
                self._state = 0
            # Go back
            if event.key == pygame.K_ESCAPE:
                m.on_change_menu('main')  # Go to main menu
            # Play match
            if event.key == pygame.K_SPACE:
                m.start_game()  # Go to main menu

    def on_loop(self):
        if self._prev_state != self._state:
            pygame.event.post(pygame.event.Event(EVENT_CHANGE_STATE, key=0))
            self._prev_state = self._state
        self._ready = (m.get_player_1() is not None) and (m.get_player_2() is not None)

    def on_render(self):
        # Render the screen
        pygame.display.update(self._rect_list)
        # Draw players
        tournament = m.get_tournament()
        tournament.draw_table()

        if tournament.is_full():
            text = pygame.font.Font(None, 32).render("Press SPACE to start", 1, (0, 255, 0))
            self._screen.blit(text, (200, 300))

    def on_reset(self):
        self._state = 0
        self._prev_state = 1
        self._ready = False
        self._rect_list = []
Ejemplo n.º 4
0
class ChooseMenu:

    def __init__(self, screen, previous):
        self._previous = previous
        self._screen = screen
        self._menu = None
        self._menu_list = []
        self._state = 0
        self._prev_state = 1
        self._rect_list = []

    def on_init(self):
        players = m.get_players()
        i = 1
        for p in players:
            self._menu_list.append((p._name, i, None))
            i += 1
            if i >= 10:
                break
        self._menu_list.append(("Next page", i, None))
        self._menu = Menu(50, 50, 20, 5, 'vertical', 100, self._screen, self._menu_list, "assets/backgrounds/choose_menu.png")
        self._menu.set_center(True, True)
        self._menu.set_alignment('center', 'center')

    def on_event(self, event):
        if event.type == pygame.KEYDOWN or event.type == EVENT_CHANGE_STATE:
            if self._state == 0:
                self._rect_list, self._state = self._menu.update(event, self._state)
            else:
                player_name = self._menu_list[self._state - 1][0]
                if self._previous == 'tournament':
                    m.add_player_by_name(player_name, tournament=True)
                else:
                    m.add_player_by_name(player_name, tournament=False)
                m.on_change_menu(self._previous)  # Go to match
                self._state = 0
                del self._menu_list[:]
            # Go back
            if event.key == pygame.K_ESCAPE:
                m.on_change_menu(self._previous)  # Go to match

    def on_loop(self):
        if self._prev_state != self._state:
            pygame.event.post(pygame.event.Event(EVENT_CHANGE_STATE, key=0))
            self._prev_state = self._state

    def on_render(self):
        # Render the screen
        pygame.display.update(self._rect_list)
Ejemplo n.º 5
0
class PlayerMenu:

    def __init__(self, screen, player, previous):
        self._player = player
        self._screen = screen
        self._menu = Menu(50, 50, 20, 5, 'vertical', 100, screen,
                          [('Create Player', 1, None),
                           ('Choose Existent Player', 2, None)], "assets/backgrounds/player_menu.png")

        self._menu.set_center(True, True)
        self._menu.set_alignment('center', 'center')

        self._state = 0
        self._prev_state = 1
        self._rect_list = []

        self._previous = previous
        if previous == 'tournament':
            self._opt1 = 'add_tournament'
            self._opt2 = 'choose_tournament'
        else:
            self._opt1 = 'add'
            self._opt2 = 'choose'

    def on_init(self):
        pass

    def on_event(self, event):
        if event.type == pygame.KEYDOWN or event.type == EVENT_CHANGE_STATE:
            if self._state == 0:
                self._rect_list, self._state = self._menu.update(event, self._state)
            if self._state == 1:
                m.on_change_menu(self._opt1)  # Go to create player
            if self._state == 2:
                m.on_change_menu(self._opt2)  # Go to select player
            self._state = 0
            # Go back
            if event.key == pygame.K_ESCAPE:
                m.on_change_menu(self._previous)

    def on_loop(self):
        if self._prev_state != self._state:
            pygame.event.post(pygame.event.Event(EVENT_CHANGE_STATE, key=0))
            self._prev_state = self._state

    def on_render(self):
        # Render the screen
        pygame.display.update(self._rect_list)
Ejemplo n.º 6
0
class AvatarMenu:

    def __init__(self, screen, previous):
        self._screen = screen

        self._menu = Menu(50, 50, 20, 5, 'horizontal', 100, screen,
                          [('Image', 1, u.avatar_1),
                           ('Image', 2, u.avatar_2),
                           ('Image', 3, u.avatar_3),
                           ('Image', 4, u.avatar_4),
                           ('Image', 5, u.avatar_5)], "assets/backgrounds/avatar_menu.png")

        self._menu.set_center(True, True)
        self._menu.set_alignment('center', 'center')
        self._state = 0
        self._prev_state = 1
        self._rect_list = []

        self._previous = previous
        if previous == 'tournament':
            self._opt1 = 'colour_tournament'
        else:
            self._opt1 = 'colour'

    def on_init(self):
        pass

    def on_event(self, event):
        if event.type == pygame.KEYDOWN or event.type == u.EVENT_CHANGE_STATE:
            if self._state == 0:
                self._rect_list, self._state = self._menu.update(event, self._state)
            if event.key == pygame.K_RETURN:
                avatar_name = "%i.png" % self._state
                m.create_player(avatar=avatar_name)
                m.on_change_menu(self._opt1)
            self._state = 0
            # Go back
            if event.key == pygame.K_ESCAPE:
                m.on_change_menu(self._previous)  # Go to create player

    def on_loop(self):
        if self._prev_state != self._state:
            pygame.event.post(pygame.event.Event(u.EVENT_CHANGE_STATE, key=0))
            self._prev_state = self._state

    def on_render(self):
        # Render the screen
        pygame.display.update(self._rect_list)
Ejemplo n.º 7
0
class MainMenu:

    def __init__(self, screen):
        self._menu = Menu(50, 50, 20, 5, 'horizontal', 100, screen,
                          [('Single Game', 1, None),
                           ('Tournament', 2, None)], "assets/backgrounds/main_menu.png")

        self._menu.set_center(True, True)
        self._menu.set_alignment('center', 'center')
        self._state = 0
        self._prev_state = 1
        self._rect_list = []

    def on_init(self):
        m.reset_game()

    def on_event(self, event):
        if event.type == pygame.KEYDOWN or event.type == EVENT_CHANGE_STATE:
            if self._state == 0:
                self._rect_list, self._state = self._menu.update(event, self._state)
            if self._state == 1:
                m.on_change_menu('match')
                self._state = 0
            elif self._state == 2:
                m.on_change_menu('tournament')
                self._state = 0
            else:
                self._state = 0
            # Go back
            if event.key == pygame.K_ESCAPE:
                pygame.quit()

    def on_loop(self):
        if self._prev_state != self._state:
            pygame.event.post(pygame.event.Event(EVENT_CHANGE_STATE, key=0))
            self._prev_state = self._state

    def on_render(self):
        # Render the screen
        pygame.display.update(self._rect_list)