本文整理汇总了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