本文整理汇总了Python中models.Move.put方法的典型用法代码示例。如果您正苦于以下问题:Python Move.put方法的具体用法?Python Move.put怎么用?Python Move.put使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Move
的用法示例。
在下文中一共展示了Move.put方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_move
# 需要导入模块: from models import Move [as 别名]
# 或者: from models.Move import put [as 别名]
def make_move(self, request):
"""Makes a move. Returns a game state with message"""
game = utils.get_by_urlsafe(request.urlsafe_game_key, Game)
if game.game_over:
return game.to_form('Game already over!')
if not utils.valid_letter_guess(request.letter_guess, game.guessed_letters):
return game.to_form('Sorry, %s is an invalid guess!' % request.letter_guess)
game.attempts_remaining -= 1
game.guessed_letters = game.guessed_letters + request.letter_guess
move = Move(game=game.key, move=request.letter_guess, move_index=game.attempts_allowed - game.attempts_remaining)
move.put()
if utils.guessed_letters_are_correct(game.guessed_letters, game.target):
game.end_game(True)
return game.to_form('You win!')
if request.letter_guess in game.target:
msg = 'That letter is in the word! Remaining %s' % utils.show_hyphenated_progress(game.guessed_letters, game.target)
else:
msg = 'Oops! That letter is not in the word! Remaining %s' % utils.show_hyphenated_progress(game.guessed_letters, game.target)
if game.attempts_remaining < 1:
game.end_game(False)
return game.to_form(msg + ' Game over!')
else:
game.put()
return game.to_form(msg)
示例2: guess_answer
# 需要导入模块: from models import Move [as 别名]
# 或者: from models.Move import put [as 别名]
def guess_answer(self, request):
"""Guesses the answer. Returns a game state with message"""
game = utils.get_by_urlsafe(request.urlsafe_game_key, Game)
if game.game_over:
return game.to_form('Game already over!')
if not utils.valid_word_guess(request.word_guess):
return game.to_form('Sorry, %s is an invalid guess!' % request.guess)
game.attempts_remaining -= 1
move = Move(game=game.key, move=request.word_guess, move_index=game.attempts_allowed - game.attempts_remaining)
move.put()
if request.word_guess == game.target:
game.end_game(True)
return game.to_form('You win!')
else:
msg = 'Oops! That is not the word! Remaining %s' % utils.show_hyphenated_progress(game.guessed_letters, game.target)
if game.attempts_remaining < 1:
game.end_game(False)
return game.to_form(msg + ' Game over!')
else:
game.put()
return game.to_form(msg)
示例3: make_move
# 需要导入模块: from models import Move [as 别名]
# 或者: from models.Move import put [as 别名]
def make_move(self, request):
"""Makes a move. Returns a game state with message. The two
positions are a and b"""
game = get_by_urlsafe(request.urlsafe_game_key, Game)
if game.game_over:
return game.to_form('Game already over!')
cards = Card.query(Card.game == game.key, Card.matched == False)
position1 = request.a
position2 = request.b
mark_card = Card.query(Card.position == position1)
for card in mark_card:
card.seen = True
card.put()
mark_card = Card.query(Card.position == position2)
for card in mark_card:
card.seen = True
card.put()
unmatched_cards = []
for card in cards:
unmatched_cards.append(card)
unmatched_cards_count = len(unmatched_cards)
if unmatched_cards_count < 2:
raise IndexError('No unmatched pair found but the game is not '
'over')
cards_list = []
msg = 'Boo'
game.attempts += 1
move = Move()
move.card1 = position1
move.card2 = position2
move.game = game.key
move.result = msg
for card in unmatched_cards:
if card.position == position1 or card.position == position2:
cards_list.append(card)
try:
if cards_list[0].matched or cards_list[1].matched:
move.result = 'Card already matched'
move.put()
return game.to_form('Card already matched')
except:
msg = 'One of the cards is already matched. Please Try again.'
move.result = msg
move.put()
return game.to_form(msg)
if cards_list[0].value == cards_list[1].value:
cards_list[0].matched = cards_list[1].matched = True
cards_list[0].put()
cards_list[1].put()
msg = 'Yay'
move.result = msg
if unmatched_cards_count == 2:
game.game_over = True
game.end_game()
msg = 'You win, Game Over'
move.put()
users = User.query(User.key == game.user)
for user in users:
user.games_played += 1
user.average_attempt = game.attempts
user.calculate_score()
user.put()
return game.to_form(msg)
game.put()
move.put()
return game.to_form(msg)