本文整理匯總了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)