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


Python Menu.setCurrentMenu方法代码示例

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


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

示例1: __init__

# 需要导入模块: from Menu import Menu [as 别名]
# 或者: from Menu.Menu import setCurrentMenu [as 别名]
class AcesUp:
    def __init__(self):
        self.__currentMenu = 'main'
        self.menu = Menu()
        self.game = Game()

    def main(self, argc, argv):
        while self.menu.hasMenu():
            try:
                if self.menu.getCurrentMenu() == Menu.MAIN:
                    self.menu.printMenu(self.game.getPlayer().get('name'))
                elif self.menu.getCurrentMenu() == Menu.GAME:
                    self.__loopGame()
                elif self.menu.getCurrentMenu() == Menu.STATS:
                    self.menu.printMenu(self.game.getPlayerStats())
                elif self.menu.getCurrentMenu() == Menu.RESET:
                    self.__loopReset()
                elif self.menu.getCurrentMenu() == Menu.OPTIONS:
                    self.__loopOptions()
                elif self.menu.getCurrentMenu() == Menu.PLAYER:
                    self.__changePlayer()
                elif self.menu.getCurrentMenu() == Menu.QUIT:
                    self.menu.printMenu(self.game.getPlayer().get('options.confirmQuit'))

            except KeyboardInterrupt:
                if self.game.isInGame():
                    self.game.finishGame()
                break

        return 0

    def __loopGame(self):
        self.game.startGame()
        while self.game.isInGame():
            title = 'Aces Up! ' + self.game.getPlayer().get('name') + '\n' + 'Score: ' \
                + str(self.game.getPlayer().get('score')) + ' Multiplier: ' + str(self.game.getModifier()) \
                + '\n' + 'Time: ' + self.game.getCurrentTime()
            self.menu.printTitle(title + self.game.printCards())
            uInput = str(self.menu.printMenu(self.game.getCurrentFacingCards())).strip()

            action = uInput[:2]
            if action == 'mv' or action == 'rm':
                try:
                    column = int(uInput[-1:])
                except ValueError:
                    print('Column must be an integer')
                    continue

                # Call the proper function to handle the action
                getattr(self.game, action + 'Card')(column - 1)
            elif action == 'u':
                self.game.undo()
            elif action == 'd':
                self.game.deal()
            elif action == 'q':
                self.game.finishGame()

        while self.game.isFinished():
            title = 'Aces Up! ' + self.game.getPlayer().get('name') + '\n' + 'Score: ' \
                + str(self.game.getPlayer().get('score')) + ' Multiplier: ' + str(self.game.getModifier()) \
                + '\n' + 'Time: ' + self.game.getCurrentTime()
            self.menu.printTitle(title + self.game.printCards())
            print('Game over, you ' + ('won' if self.game.didPlayerWin() else 'lost') + '!')
            uInput = self.menu.getInput('Would you like to play again? [y/n] ')
            if uInput == 'y' or uInput == 'yes':
                self.menu.setCurrentMenu(Menu.GAME)
                break
            elif uInput == 'n' or uInput == 'no':
                self.game.quitGame()
                self.menu.setCurrentMenu(Menu.MAIN)

    def __loopReset(self):
        while self.menu.getCurrentMenu() == Menu.RESET:
            uInput = self.menu.getInput('Are you sure you want to reset your stats? [y/n] ')
            if uInput == 'y' or uInput == 'yes':
                self.game.getPlayer().resetStats()
                self.game.savePlayer(self.game.getPlayer())
                self.menu.setCurrentMenu(Menu.MAIN)
            elif uInput == 'n' or uInput == 'no':
                self.menu.setCurrentMenu(Menu.MAIN)

    def __changePlayer(self):
        players = self.game.getPlayerNames()
        playersTable = self.__formatDataToTable(players)
        self.menu.printTable(playersTable)

        uInput = self.menu.getInput('Choose a player or create a new one: ', lower=False)

        self.game.loadPlayer(uInput)

        self.menu.setCurrentMenu(Menu.MAIN)

    def __loopOptions(self):
        playerName = self.game.getPlayer().get('name')
        options = self.game.getPlayer().get('options')

        while self.menu.getCurrentMenu() == Menu.OPTIONS:
            self.menu.printTitle('Options: ' + playerName)

            print('Enter the option name followed by the new value')
#.........这里部分代码省略.........
开发者ID:pbarnum,项目名称:acesup,代码行数:103,代码来源:AcesUp.py


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