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


Python Game.fields_left方法代碼示例

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


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

示例1: index

# 需要導入模塊: from game.models import Game [as 別名]
# 或者: from game.models.Game import fields_left [as 別名]
def index(request):
  if request.method == 'POST':
    post = (request.POST)
    form = GameForm(post)
    if form.is_valid():
      #create the user if they don't exist already
      user = User.objects.filter(name=post['name'])[:1]
      if not user:
        new_user = User(name=post['name'])
        new_user.save()
      try:
        user = User.objects.get(name=post['name'])
      except User.DoesNotExist:
        return HttpResponse('database error', status=404)  

      #create the game including minefield then save it to database
      if post['difficulty'] == 'beginner':
        game = Game(width=9,height=9,number_of_mines=10,difficulty='beginner',user=user)
      elif post['difficulty'] == 'intermediate':
        game = Game(width=16,height=16,number_of_mines=40,difficulty='intermediate',user=user)
      elif post['difficulty'] == 'expert':
        game = Game(width=30,height=16,number_of_mines=99,difficulty='expert',user=user)
      game.create_minefield()
      game.fields_left = game.width * game.height
      game.save()

      #redirect to the game page
      args = {'name': user.name, 'game_id': str(game.id)}
      return HttpResponseRedirect(reverse('game_start', kwargs=args))
  else:
    form = GameForm()

  top_beginner_users = User.objects.filter(game__difficulty='beginner', game__won=True).order_by('game__won')
  beginner_dict = create_high_scores(top_beginner_users)

  top_inter_users = User.objects.filter(game__difficulty='intermediate', game__won=True)
  inter_dict = create_high_scores(top_inter_users)

  top_expert_users = User.objects.filter(game__difficulty='expert', game__won=True)
  expert_dict = create_high_scores(top_expert_users)

  return render(request, 'index.html', {
      'form': form, 
      'beginner_dict': beginner_dict, 
      'inter_dict': inter_dict,
      'expert_dict': expert_dict
      })
開發者ID:ZzCalvinzZ,項目名稱:minesweeper,代碼行數:49,代碼來源:views.py


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