本文整理汇总了Python中game.models.Game.players方法的典型用法代码示例。如果您正苦于以下问题:Python Game.players方法的具体用法?Python Game.players怎么用?Python Game.players使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类game.models.Game
的用法示例。
在下文中一共展示了Game.players方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: request_game
# 需要导入模块: from game.models import Game [as 别名]
# 或者: from game.models.Game import players [as 别名]
def request_game(request):
session_id = request.session.get('_auth_user_id', -1)
if(session_id == -1):
return login_page(request)
username = User.objects.get(pk=session_id)
platform = get_platform(request.get_signed_cookie('platform', 'x86'))
if(request.get_signed_cookie('at_index', default='False') == 'True'):
if(len(GameRequest.objects.filter(host=username)) >= 1):
#return HttpResponse("Can Only host one game at a time!!")
csrf_request = {'username' : str(username)}
return render_to_response('delete_req.html',csrf_request, context_instance=RequestContext(request))
num_players = get_request_param(request,'num_players', 0)
has_cpu = get_request_param(request,'has_cpu', 0)
gamerequest = GameRequest(requested_players=num_players, accepted_players=1, has_cpu=has_cpu, host=username)
gamerequest.save()
gamerequest.player_names.add(username)
gamerequest.save()
game = Game(num_players=num_players, has_cpu=False, log = '', num_cpu_dice = 0, turn=1, pk=gamerequest.id, cpu_roll=0, num_dice = NUM_DICE*num_players, timestamp=0)
game.save()
#chat related?
room = Room(id=game.id)
room.save()
userprofile = UserProfile.objects.get(user=username)
userprofile.turn=1
userprofile.num_dice = NUM_DICE
userprofile.save()
csrf_request = {'message' : 'waiting'}
csrf_request.update(csrf(request))
response = render_to_response('wait.html', csrf_request, context_instance=RequestContext(request))
response.set_signed_cookie('at_index', 'False')
response.set_signed_cookie('gamerequest_id', str(gamerequest.id))
#originally i stored turn in a cookie. then i realized it was not feasible because
#one player must know the turns of the others, so i now store in db. I may remove the
#cookie later
response.set_signed_cookie('turn', 1)
response.set_signed_cookie('playing_cpu', 0)
return response
else:
int_gamerequest_id = int(request.get_signed_cookie('gamerequest_id'))
try:
gamerequest = GameRequest.objects.get(pk=int_gamerequest_id)
except:
gamerequest = -1
if(gamerequest == -1):
csrf_request = {}
csrf_request.update(csrf(request))
return render_to_response(index_page[platform], csrf_request, context_instance=RequestContext(request))
#during development, >= will save me time. later should make ==
#if(gamerequest.accepted_players >= gamerequest.requested_players):
if(gamerequest.accepted_players == gamerequest.requested_players):
try:
game = Game.objects.get(pk=gamerequest.id)
except:
game = -1
if(game == -1):
csrf_request = {}
csrf_request.update(csrf(request))
return render_to_response(index_page[platform], csrf_request, context_instance=RequestContext(request))
game.players = gamerequest.player_names.all()
game.save()
csrf_request = {'multiplayer_begin':True,
'host' : gamerequest.host,
'num_players' : gamerequest.requested_players,
'game_fsm' : 0,
'playing_cpu' : 0,
'username' : str(username),
'dice_list' : [],
'game_id' : gamerequest.id#this doesn't seem to be working due to auto refresh
}
csrf_request.update(csrf(request))
response = render_to_response(main_page[platform], csrf_request, context_instance=RequestContext(request))
response.set_signed_cookie('inagame', 'True')
response.set_signed_cookie('game_id', gamerequest.id)
response.set_signed_cookie('game_fsm', 0)
response.set_signed_cookie('bullshit_timestamp', 0)
return response
elif(gamerequest.accepted_players < gamerequest.requested_players):
csrf_request = {'message' : 'still waiting'}
csrf_request.update(csrf(request))
response = render_to_response('wait.html', csrf_request, context_instance=RequestContext(request))
return response
else:
#if accepted_players > requested players then the user has probably hit back on browser
#and attempted to reentered. don't allow, redirect to index
csrf_request = {}
csrf_request.update(csrf(request))
return render_to_response(index_page[platform], csrf_request, context_instance=RequestContext(request))