本文整理匯總了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')
#.........這裏部分代碼省略.........