當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。