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


Python Game.turn方法代碼示例

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


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

示例1: main

# 需要導入模塊: from game.models import Game [as 別名]
# 或者: from game.models.Game import turn [as 別名]
def main(request):
  csrf_request = {}
  response_cookie_dict = {}
  debug_log = []
  session_id = request.session.get('_auth_user_id', -1)
  if(session_id == -1):
    return login_page(request)
  print "in main()"
  user = User.objects.get(pk=session_id)
  csrf_request['username'] = str(user) 
  userprofile = UserProfile.objects.get(user=user)
  debug_log.append('logged in!!')
  dice_list = []

  ##determine whether we are in a mobile platform
  platform = get_platform(request.get_signed_cookie('platform', 'x86'))

  #if we are playing the cpu then our turn is always 1, otherwise we can find it stored in a cookie and in the db
  playing_cpu = int(request.GET.get('playing_cpu', 0))
  debug_log.append('playing_cpu read from GET as %s' % str(playing_cpu))
  if(playing_cpu == 1):
    turn = 1 
  else:
    turn = userprofile.turn
  debug_log.append('player turn is %d after turn assignment block' %turn)
  print 'player turn is %d after turn assignment block' %turn

  #exit game flow
  if(int(request.GET.get('exit_game', -1)) == 1):
    debug_log.append('Exiting game')
    response = render_to_response(index_page[platform],  csrf_request, context_instance=RequestContext(request))
    response.set_signed_cookie('at_index', 'True')
    response.set_signed_cookie('inagame', 'False')
    if(not (request.get_signed_cookie('playing_cpu', default=-1) == '1' or playing_cpu == 1)):
      cookie_game_id = int(request.get_signed_cookie('game_id'))
      if(len(GameRequest.objects.filter(pk=cookie_game_id)) > 0):
        try: 
          gamerequest = GameRequest.objects.get(pk=cookie_game_id)
        except:
          gamerequest = -1
        if(gamerequest != -1):
          if(gamerequest.host == user):
            gamerequest.delete() 
    return response

  #inagame is used to determine if we should redirect to index page
  get_inagame = int(request.GET.get('inagame', -1))
  if(( (request.get_signed_cookie('playing_cpu', default=-1) != '1' and playing_cpu != 1))):
    if(len(Game.objects.filter(pk=get_request_param(request,'game_id', -1))) > 0):
      in_defunct_game = False
    else:
      in_defunct_game = True
  else:
    in_defunct_game = False
    
  if((request.get_signed_cookie('inagame', 'False') == 'False' and get_inagame != 1) or in_defunct_game):
    username = User.objects.get(pk=session_id)
    csrf_request = { 'username' : str(username) }
    response = render_to_response(index_page[platform],  csrf_request, context_instance=RequestContext(request))
    response.set_signed_cookie('at_index', 'True')
    return response

  #the previous_game_fsm value will not be affected by posted form data
  #therefore it should only equal game_fsm when there is a refresh
  #if we're plying_cpu we set previous_game_fsm to NA, so it will never = game_fsm
  if(playing_cpu != 1):
    previous_game_fsm = request.get_signed_cookie('game_fsm', 0)
  else:
    previous_game_fsm = 'NA'
  game_fsm = get_request_param(request,'game_fsm', 0)
  if(playing_cpu != 1 and game_fsm == 0):
    game_fsm = request.get_signed_cookie('game_fsm', 0)
    debug_log.append('game_fsm cookie read,')
  debug_log.append(' game_fsm = %s previous_game_fsm = %s' % (str(game_fsm), str(previous_game_fsm)))
  print ' game_fsm = %s previous_game_fsm = %s' % (str(game_fsm), str(previous_game_fsm))
  if(get_request_param(request,'submit_type', 0) == 'New Game'):
    #for now, the new game button should only appear when we are playing the cpu.  
    #otherwise a new request should be launched
    playing_cpu = 1
    game_fsm = 0
    if(len(Game.objects.filter(pk=get_request_param(request,'game_id', -1))) > 0):
      game = get_object_or_404(Game, pk=get_request_param(request,'game_id', -1)) 
      game.delete()
  csrf_request['game_fsm'] = game_fsm

  #############################
  ##beginning of game FSM logic
  #############################

  print 'game_fsm = %s' %(str(game_fsm))
  debug_str = get_request_param(request, 'debug_str', 'NA')
  print '%s debug_str = %s' %(user, debug_str)

  ##rolls should occur regardless of whether it is our turn
  if(game_fsm == "has_rolled" or game_fsm == "reroll"):
    debug_str = get_request_param(request, 'debug_str', 'NA')
    print '%s has_rolled/reroll, submit_type != bullshit, debug_str = %s' %(user, debug_str)
    if(request.get_signed_cookie('playing_cpu', default=-1) == '1' or playing_cpu == 1):
      debug_log.append('in playing_cpu and (has_rolled or reroll) block')
      print 'in playing_cpu and (has_rolled or reroll) block'
#.........這裏部分代碼省略.........
開發者ID:joshyg,項目名稱:liarsdice,代碼行數:103,代碼來源:views.py


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