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


Python Game.master方法代碼示例

本文整理匯總了Python中game.models.Game.master方法的典型用法代碼示例。如果您正苦於以下問題:Python Game.master方法的具體用法?Python Game.master怎麽用?Python Game.master使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在game.models.Game的用法示例。


在下文中一共展示了Game.master方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: index

# 需要導入模塊: from game.models import Game [as 別名]
# 或者: from game.models.Game import master [as 別名]
def index(request):
    player = get_player(request)
    if player is not None:
        # Delete old player and game objects
        if player.game and player == player.game.master:
            player.game.delete()
        player.delete()
        del request.session['player_pk']

    if request.method == "POST":
        form = LoginForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data['player_name']
            create_game = form.cleaned_data['create_game']

            checkin = CheckIn()
            checkin.save()
            player = Player(name=name, rand_id=Player.generate_rand_id(), checkin=checkin)

            if create_game:
                checkin = CheckIn()
                checkin.save()
                bot = Bot()
                bot.save()
                game = Game(checkin=checkin, bot=bot)
                game.save()
                player.game = game
                player.index = 1

            player.save()
            
            if create_game:
                game.master = player
                game.players.add(player)
                game.save()

            request.session['player_pk'] = player.pk
            request.session['player_rand_id'] = player.rand_id
            request.session['player_name'] = name

            if create_game:
                return redirect('/create-game')
            else:
                return redirect('/join-game')
    else:
        form = LoginForm(initial={'player_name': request.session.get('player_name', '')})

    return render(request, 'game/index.html', {'form': form})
開發者ID:ReshNesh,項目名稱:Zombies,代碼行數:50,代碼來源:views.py


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