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


Python Grid.process_player_move方法代码示例

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


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

示例1: TicTacToe

# 需要导入模块: from Grid import Grid [as 别名]
# 或者: from Grid.Grid import process_player_move [as 别名]
class TicTacToe(object):

    def __init__(self):
        self.user_requested_exit = False
        self.player_turn = 1
        self.grid = Grid()
        self.is_a_winner = False
        print 'Welcome to TicTacToe!'
        print 'Here is the grid'

    def start(self):
        while self.game_has_to_continue():
            self.grid.display()
            print 'Alright Player {}, your turn:'.format(self.player_turn)
            if not self.process_player_input(raw_input()):
                continue
            self.switch_player_turn()

        if self.user_requested_exit:
            print "Bye bye!"
        elif self.is_a_winner:
            self.grid.display()
            self.switch_player_turn()
            print "Congratulation Player {}, you won!".format(self.player_turn)
        else:
            print "Game Over, nobody wins."

    def process_player_input(self, player_input):
        if player_input == "quit":
            self.user_requested_exit = True
            return True
        if not self.grid.process_player_move(self.player_turn, player_input):
            print 'Sorry, you cannot play this'
            return False
        return True

    def game_has_to_continue(self):
        if self.no_winner() and self.grid.is_not_full() and self.user_wants_to_continue():
            return True
        return False

    def no_winner(self):
        if not self.grid.no_winner():
            self.is_a_winner = True
            return False
        return True

    def switch_player_turn(self):
        if self.player_turn == 1:
            self.player_turn = 2
        else:
            self.player_turn = 1

    def user_wants_to_continue(self):
        return not self.user_requested_exit
开发者ID:Nerus92,项目名称:udemy_python,代码行数:57,代码来源:main.py


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