Exemplo n.º 1
0
def leave_game(request):
    opponent = get_opponent(request.user)
    if opponent is not None:
        game = finish_game(get_opponent(request.user).user, request.user)
    else:
        game = finish_game(None, request.user)
    game = Game.objects.filter(pk=game.pk)
    data = serializers.serialize('json', game, use_natural_keys=True)
    return HttpResponse(data, content_type='application/json')
Exemplo n.º 2
0
def finish_stroke(request):
    player = get_player(request.user)
    opponent = get_opponent(request.user)

    if player.is_lost():
        finish_game(opponent.user, player.user)
        return HttpResponse()

    if opponent.is_lost():
        finish_game(player.user, opponent.user)
        return HttpResponse()

    player.active = False
    player.save()
    Unit.objects.filter(player=player).update(active=False)
    Settlement.objects.filter(player=player).update(active=False)

    opponent.increase_money_for_day()
    opponent.active = True
    opponent.save()

    Unit.objects.filter(player=opponent).update(active=True)
    Settlement.objects.filter(player=opponent).update(active=True)
    return HttpResponse()