当前位置: 首页>>代码示例>>Python>>正文


Python Game.create_game方法代码示例

本文整理汇总了Python中models.Game.create_game方法的典型用法代码示例。如果您正苦于以下问题:Python Game.create_game方法的具体用法?Python Game.create_game怎么用?Python Game.create_game使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Game的用法示例。


在下文中一共展示了Game.create_game方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_game

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import create_game [as 别名]
    def create_game(self, request):
        """ Creates a new game.

        This function creates a new game.
        (NB: Games are just shells for questions. See the supplied readme
        for more information.)

        Returns:
            GameForm -- a GameForm representation of the created game
        """
        # Get player by username
        player = get_player(request.user_name)

        # Create the game
        game = Game.create_game(player=player.key, title=request.title)

        # Return confirmation of game creation
        return game.to_form()
开发者ID:zebralove79,项目名称:fsd_p4g,代码行数:20,代码来源:api.py

示例2: form_valid

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import create_game [as 别名]
    def form_valid(self, form):
        session_details = self.request.session.get('session_details', {})  # FIXME
        # FIXME if not a dict, make it a dict (upgrade old content)
        log.logger.debug('session_details %r', session_details)

        existing_game = True
        # Set the game properties in the database and session
        game_name = form.cleaned_data['new_game']
        if game_name:
            # Attempting to create a new game
            try:
                # see if already exists
                existing_game = Game.objects.get(name=game_name)
            except Game.DoesNotExist:
                existing_game = None

            if not existing_game:
                # really a new game
                tmp_game = Game(name=form.cleaned_data['new_game'])
                new_game = tmp_game.create_game(form.cleaned_data['card_set'])
                tmp_game.gamedata = new_game
                tmp_game.save()
                self.game = tmp_game

        if existing_game:
            if not game_name:
                game_name = form.cleaned_data.get('game_list')

            existing_game = Game.objects.get(name=game_name)  # existing_game maybe a bool

            log.logger.debug('existing_game.gamedata %r',
                (existing_game.gamedata,)
            )
            log.logger.debug('existing_game.gamedata players %r',
                (existing_game.gamedata['players'],)
            )

            existing_game.save()

        # Set the player session details
        session_details['game'] = game_name
        self.request.session['session_details'] = session_details  # this is probably kinda dumb.... Previously we used seperate session items for game and user name and that maybe what we need to go back to

        return super(LobbyView, self).form_valid(form)
开发者ID:mralex,项目名称:cards-against-django,代码行数:46,代码来源:views.py

示例3: trigger_start

# 需要导入模块: from models import Game [as 别名]
# 或者: from models.Game import create_game [as 别名]
def trigger_start():
    Game.create_game()
开发者ID:eliotwinder,项目名称:downthetubescardgame,代码行数:4,代码来源:views.py


注:本文中的models.Game.create_game方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。