当前位置: 首页>>代码示例>>Python>>正文


Python Menu.set_alignment方法代码示例

本文整理汇总了Python中menu.Menu.set_alignment方法的典型用法代码示例。如果您正苦于以下问题:Python Menu.set_alignment方法的具体用法?Python Menu.set_alignment怎么用?Python Menu.set_alignment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在menu.Menu的用法示例。


在下文中一共展示了Menu.set_alignment方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import set_alignment [as 别名]
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 = []
开发者ID:alex5imon,项目名称:wiff-waffer,代码行数:58,代码来源:match_menu.py

示例2: __init__

# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import set_alignment [as 别名]
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)
开发者ID:alex5imon,项目名称:wiff-waffer,代码行数:55,代码来源:colour_menu.py

示例3: __init__

# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import set_alignment [as 别名]
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 = []
开发者ID:alex5imon,项目名称:wiff-waffer,代码行数:52,代码来源:tournament_menu.py

示例4: __init__

# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import set_alignment [as 别名]
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)
开发者ID:alex5imon,项目名称:wiff-waffer,代码行数:51,代码来源:choose_menu.py

示例5: __init__

# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import set_alignment [as 别名]
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)
开发者ID:alex5imon,项目名称:wiff-waffer,代码行数:50,代码来源:player_menu.py

示例6: __init__

# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import set_alignment [as 别名]
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)
开发者ID:alex5imon,项目名称:wiff-waffer,代码行数:50,代码来源:avatar_menu.py

示例7: __init__

# 需要导入模块: from menu import Menu [as 别名]
# 或者: from menu.Menu import set_alignment [as 别名]
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)
开发者ID:alex5imon,项目名称:wiff-waffer,代码行数:42,代码来源:main_menu.py


注:本文中的menu.Menu.set_alignment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。