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


Python Game.current_game方法代碼示例

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


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

示例1: move

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import current_game [as 別名]
def move(request, column_number):
    game = Game.current_game(request.user)
    if game is None:
        return Response({"detail": "Not currently in a game."}, 400)
    try:
        game.move(request.user, column_number)
    except IllegalMove as exception:
        return Response({"detail": str(exception)}, 400)
    return Response(GameSerializer(game).data, 200)
開發者ID:SeMorgana,項目名稱:ConnectWithFriends,代碼行數:11,代碼來源:views.py

示例2: game_message_list

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import current_game [as 別名]
def game_message_list(request):
    """
    List all messages for the current game this user is in.
    """
    game = Game.current_game(request.user)
    if not game:
        return Response({"detail": "You are not in a game."}, 400)
    game_messages = GameMessage.objects.filter(game=game)
    serializer = GameMessageSerializer(game_messages, many=True)
    return Response(serializer.data)
開發者ID:SeMorgana,項目名稱:ConnectWithFriends,代碼行數:12,代碼來源:views.py

示例3: test_leave_stalemate

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import current_game [as 別名]
 def test_leave_stalemate(self):
     self.client.credentials(HTTP_AUTHORIZATION='Token ' + str(self.alice.auth_token))
     self.client.post(reverse("games:start"))
     self.client.credentials(HTTP_AUTHORIZATION='Token ' + str(self.bob.auth_token))
     self.client.post(reverse("games:start"))
     game = Game.current_game(self.alice)
     game.stalemate = True
     game.save()
     response = self.client.post(reverse("games:forfeit"))
     self.assertEquals(response.status_code, 200)
     self.assertEquals(response.data["winner"], None)
開發者ID:SeMorgana,項目名稱:ConnectWithFriends,代碼行數:13,代碼來源:tests.py

示例4: test_create_game_already_in_game

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import current_game [as 別名]
 def test_create_game_already_in_game(self):
     first_game = Game._create_game(self.alice)
     second_game = Game._create_game(self.alice)
     self.assertEquals(first_game.turn, None)
     self.assertEquals(first_game.player1, self.alice)
     self.assertEquals(first_game.player2, None)
     self.assertEquals(first_game.winner, None)
     self.assertEquals(Game.current_game(self.alice), second_game)
     self.assertEquals(second_game.turn, None)
     self.assertEquals(second_game.player1, self.alice)
     self.assertEquals(second_game.player2, None)
     self.assertEquals(second_game.winner, None)
開發者ID:SeMorgana,項目名稱:ConnectWithFriends,代碼行數:14,代碼來源:tests.py

示例5: send_game_message

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import current_game [as 別名]
def send_game_message(request):
    game = Game.current_game(request.user)
    if not game:
        return Response({"detail": "You are not in a game."}, 400)
    data = JSONParser().parse(request)
    data["sender"] = request.user.pk
    data["pub_date"] = timezone.now()
    data["game"] = game.pk
    serializer = GameMessageSerializer(data=data)
    if serializer.is_valid():
        serializer.save()
        return Response(serializer.data, status=201)
    return Response(serializer.errors, status=400)
開發者ID:SeMorgana,項目名稱:ConnectWithFriends,代碼行數:15,代碼來源:views.py

示例6: forfeit

# 需要導入模塊: from games.models import Game [as 別名]
# 或者: from games.models.Game import current_game [as 別名]
def forfeit(request):
    game = Game.current_game(request.user)
    if game is None:
        return Response({"detail": "Not currently in a game."}, 400)
    game.forfeit(request.user)
    return Response(GameSerializer(game).data, 200)
開發者ID:SeMorgana,項目名稱:ConnectWithFriends,代碼行數:8,代碼來源:views.py


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