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


Python Game.log方法代码示例

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


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

示例1: main

# 需要导入模块: from game.models import Game [as 别名]
# 或者: from game.models.Game import log [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.log方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。