本文整理汇总了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'