Exemplo n.º 1
0
def make_move(request,id):
    game=get_object_or_404(Game,pk=id)
    if not game.is_users_move(request.user):
        raise PermissionDenied
    move=game.new_move()
    form=MoveForm(instance=move,data=request.POST)
    if form.is_valid():
        move.save()
        return redirect("gameplay_detail",id)
    else:
        return render(request,
                      "gameplay/game_detail.html",
                      {'game':game,'form':form})
Exemplo n.º 2
0
def make_move(request, game_id):
    """ persist the move if available """
    game = get_object_or_404(Game, pk=game_id)
    if not game.is_users_move(request.user):
        raise PermissionDenied
    move = game.new_move()
    form = MoveForm(instance=move, data=request.POST)
    if form.is_valid:
        form.save()
        return redirect(game)
    else:
        return render(request, 'gameplay/game_detail.html', {
            'game': game,
            'form': form
        })
Exemplo n.º 3
0
def game_detail(request, id):
    game = get_object_or_404(Game, pk=id)
    context = {'game': game}
    # create a move form when it is the players form
    if game.is_users_move(request.user):
        context['form'] = MoveForm()
    return render(request, "gameplay/game_detail.html", context)
Exemplo n.º 4
0
def game_detail(request, game_id):
    """ show game detail """
    game = get_object_or_404(Game, pk=game_id)
    context = {'game': game}
    if game.is_users_move(request.user):
        context['form'] = MoveForm()
    return render(request, 'gameplay/game_detail.html', context)
Exemplo n.º 5
0
    def test_invalid_move(self):
        form_data = {"x": 5, "y": 7}
        form = MoveForm(data=form_data, instance=self.move)

        self.assertFalse(form.is_valid())
Exemplo n.º 6
0
    def test_valid_move(self):
        form_data = {"x": 0, "y": 1}
        form = MoveForm(data=form_data, instance=self.move)

        self.assertTrue(form.is_valid())
Exemplo n.º 7
0
def game_detail(request, id):
    game = get_object_or_404(Game, pk=id)
    context = {'game': game}
    if game.is_user_move(request.user):
        context['form'] = MoveForm()
    return render(request, "gameplay/game_detail.html", context)