当前位置: 首页>>代码示例>>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;未经允许,请勿转载。