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


Python Game.isFinished方法代码示例

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


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

示例1: __init__

# 需要导入模块: from Game import Game [as 别名]
# 或者: from Game.Game import isFinished [as 别名]

#.........这里部分代码省略.........
                            self.waitingForPlay = True
                            self.opponent = msg[1]
                            self.currentGame = Game()
                        continue
                    if msg[0] == ClientMessages.RCV_PLAY:
                        self.recv_play(msg)
                        continue




    def read_play(self):
        while (1):
            try:
                print("Column: ")
                column = int(sys.stdin.readline())
                if column not in (1,2,3):
                    print("Invalid play. Please go again.")
                    continue
                print("Row: ")
                row = int(sys.stdin.readline())
                if row not in (1,2,3):
                    print("Invalid play. Please go again.")
                    continue
                break
            except ValueError:
                print("Invalid play. Please go again.")
        while not(self.currentGame.play(column, row)):
            print("Invalid play")
            print("Column: ")
            column = int(sys.stdin.readline())
            print("Row: ")
            row = int(sys.stdin.readline())
        ended = self.currentGame.isFinished()
        self.send_play(column, row, ended)
        self.currentGame.drawBoard()
        if ended:
            self.waitingForPlay = False
            self.playing = False
        self.waitingForPlay = True

    def recv_play(self, msg):
        self.currentGame.play(int(msg[2]), int(msg[3]))
        self.currentGame.drawBoard()
        self.waitingForPlay = False
        if msg[4] == "True":
            self.playing = False
            self.currentGame = False



    def register(self, username):
        self.send_message("REG " + username)
        msg = self.recv_message()
        msg = msg.split()
        if msg[0] != "REG":
            return False
        if msg[1] == "ok":
            self.username = username
            return True
        else:
            return False

    def exit(self):
        msg = "EXT " + self.username
        self.send_message(msg)
开发者ID:DiMesq,项目名称:tic-tac-toe-online,代码行数:70,代码来源:Client.py

示例2: __init__

# 需要导入模块: from Game import Game [as 别名]
# 或者: from Game.Game import isFinished [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


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