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


Python Game.num_dice方法代碼示例

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


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

示例1: main

# 需要導入模塊: from game.models import Game [as 別名]
# 或者: from game.models.Game import num_dice [as 別名]

#.........這裏部分代碼省略.........
    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'

      #generate player roll
      userprofile.roll = 0 
      if(game_fsm == "has_rolled"):
        userprofile.num_dice = NUM_DICE 
      for i in range(userprofile.num_dice):
        roll = random.randint(1,6)
        dice_list.append(roll)
        userprofile.roll += roll*(10**(i))
        print "roll = %d" % userprofile.roll
      userprofile.save()
      if(game_fsm == "has_rolled"):
        game = Game(num_players=2, has_cpu=True, log = '', num_cpu_dice = NUM_DICE, turn=1, timestamp=0)
        game.num_dice = game.num_players*NUM_DICE
      else:
        game = get_object_or_404(Game, pk=get_request_param(request,'game_id', -1)) 

      #generate cpu roll->only on cpu game
      game.cpu_roll = 0 
      for i in range(game.num_cpu_dice):
        roll = random.randint(1,6)
        game.cpu_roll += roll*(10**(i))
        print "roll = %d" % game.cpu_roll
      game.save()
      print "game_id = %d" %game.id
      csrf_request['game_id'] = game.id
      csrf_request['game_fsm'] = 'has_rolled'
      csrf_request['log'] = re.split('\n', game.log)

      #check if game is over
      if(game_fsm == "reroll" and (game.num_cpu_dice == 0 or userprofile.num_dice == 0)):
        csrf_request['game_fsm'] = 'game_over'
        if(game.num_cpu_dice == 0):
          csrf_request['winner'] = '%s' %(string.upper(str(csrf_request['username'])))
        else:
          csrf_request['winner'] = 'CPU'
開發者ID:joshyg,項目名稱:liarsdice,代碼行數:69,代碼來源:views.py


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