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


Python Game.create方法代码示例

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


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

示例1: accept

# 需要导入模块: from game.models import Game [as 别名]
# 或者: from game.models.Game import create [as 别名]
    def accept(self, accepted):
        wait = GameRequest.check_last_time(self.requester)
        if wait:
            return wait

        self.accepted = accepted
        self.accept_time = timezone.now()
        if accepted:
            Game.create([self.requestee, self.requester], game_conf=self.game_config)
        self.save()
开发者ID:SharifAIChallenge,项目名称:AIC_game_runner,代码行数:12,代码来源:models.py

示例2: save

# 需要导入模块: from game.models import Game [as 别名]
# 或者: from game.models.Game import create [as 别名]
 def save(self):
     game_type = self.cleaned_data['type']
     csv_file = self.cleaned_data['file']
     for line in csv_file.readlines():
         teams = line.strip().split(',')
         try:
             group = Group.objects.get(name=teams[0])
         except Group.DoesNotExist:
             group = None
         try:
             game_conf = GameConfiguration.objects.get(id=teams[1])
         except GameConfiguration.DoesNotExist:
             continue
         try:
             place = GamePlace.objects.get(id=teams[2])
         except GamePlace.DoesNotExist:
             place = None
         try:
             time = datetime.datetime(*list(map(int, teams[3:8])))
         except ValueError:
             time = None
         Game.create([Team.objects.get(id=team) for team in teams[8:]], game_type=game_type, game_conf=game_conf,
                     title=self.cleaned_data['name'], group=group, place=place, time=time)
开发者ID:SharifAIChallenge,项目名称:AIC_mezzanine_site,代码行数:25,代码来源:forms.py

示例3: start_game

# 需要导入模块: from game.models import Game [as 别名]
# 或者: from game.models.Game import create [as 别名]
def start_game(request):
    user = request.user
    qs = GameSession.objects.\
        filter(user=user,
               left=False,
               game__finished=False).\
        exclude(client_state=ClientConnectionState.LOST)
    if qs.count():
        gs = qs.all()[0]
        return {'status': 302,
                'url': reverse(game_screen, kwargs={'game_id': gs.game.id})}

    wu = WaitingUser.objects.get_or_create(user=user)[0].update()
    last_poll_guard = datetime.datetime.now() - constants.WAITING_USER_TIMEOUT

    opponents = WaitingUser.objects.\
        filter(last_poll__gt=last_poll_guard).\
        exclude(user=user).all()
    if not opponents:
        return {'status': 'polling',
                'opponents': []}

    now = datetime.datetime.now()
    join_timeout = request.session.get('game_join_timeout', None)
    if not join_timeout:
        join_timeout = request.session['game_join_timeout'] = now

    if join_timeout + constants.GAME_JOIN_WAIT_TIMEOUT > now:
        time_left = join_timeout + constants.GAME_JOIN_WAIT_TIMEOUT - now
        return {'status': 'polling',
                'timeout': time_left.seconds,
                'opponents': [op.serialize() for op in opponents]}

    game_id = get_uid()
    game = Game.create(id=game_id)
    GameSession.objects.create(game=game, user=user)
    wu.delete()
    for op in opponents:
        GameSession.objects.create(game=game, user=op.user)
        op.delete()
    return {'status': '302',
            'url': reverse(game_screen, kwargs={'game_id': game_id})}
开发者ID:elegion,项目名称:setwith.me,代码行数:44,代码来源:views.py


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