本文整理汇总了Python中models.History.push方法的典型用法代码示例。如果您正苦于以下问题:Python History.push方法的具体用法?Python History.push怎么用?Python History.push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.History
的用法示例。
在下文中一共展示了History.push方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_guess
# 需要导入模块: from models import History [as 别名]
# 或者: from models.History import push [as 别名]
def make_guess(self, request):
"""Makes a move. Returns a game state with message"""
game = get_by_urlsafe(request.urlsafe_game_key, Game)
if game.game_over:
return game.to_form('Game already over!')
guess = request.guess[0].upper()
"""The Guess is only a character"""
if not guess.isalpha():
msg = 'Should put an alphabet!'
return game.to_form(msg)
"""The Guess is already used"""
if guess in game.matches + game.misses:
msg = 'Already used!'
return game.to_form(msg)
"""The Guess is in the taget word"""
if guess in list(game.target):
game.matches.append(guess)
msg = "Wonderful!"
# Set the Guess is in the output words list"""
i = 0
for x in list(game.target):
if x == guess:
game.output_words[i] = x
i += 1
if '_' not in game.output_words:
game.end_game(True)
return game.to_form(msg + ' You win!')
else:
# The Guess is not in the taget word"""
game.misses.append(guess)
msg = "You missed!"
if len(game.misses) >= 6:
game.end_game(False)
return game.to_form(msg + ' Game over!')
game.put()
History.push(game.key, guess, msg)
return game.to_form(msg)