當前位置: 首頁>>代碼示例>>Python>>正文


Python History.push方法代碼示例

本文整理匯總了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)
開發者ID:halee9,項目名稱:HangMan,代碼行數:43,代碼來源:api.py


注:本文中的models.History.push方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。