コード例 #1
0
def show_game_service(request):
    if 'game_selected' not in request.session:
        return HttpResponseNotFound('No se ha seleccionado una partida a la que jugar')    

    game_id = request.session['game_selected']
    games = Game.objects.filter(id=game_id)

    if len(games) == 0:
        return HttpResponseNotFound('La partida seleccionada no es válida') 

    game = games[0]

    if game.status != GameStatus.ACTIVE:
        return HttpResponseNotFound('La partida no está activa')

    if game.cat_user != request.user and game.mouse_user != request.user:
        return HttpResponseNotFound('No eres jugador de la partida seleccionada')

    board = [0]*64
    board[game.cat1] = 1
    board[game.cat2] = 1
    board[game.cat3] = 1
    board[game.cat4] = 1
    board[game.mouse] = -1

    move_form = MoveForm()
    
    context_dict = { 'game': game, 'board': board, 'move_form': move_form }
    return render(request, 'mouse_cat/game.html', context_dict)