Пример #1
0
def room(id):
    rooms = ps.get_rooms(rooms_path)
    characters_stat = ps.get_characters(characters_path)
    if "nickname" not in session:
        return redirect("/create-nickname")
    selected_room = {}
    for room in rooms:
        if room["id"] == id:
            selected_room = room
            break
    else:
        return redirect("/list-rooms")
    if request.method == "POST":
        password = request.form["password"]
        if password == selected_room["password"]:
            if put_player_into_room(selected_room, session["nickname"]):
                session["room_id"] = id
                characters_stat.append(
                    game.create_character(session["nickname"], session["user_id"]))
                ps.export_rooms(rooms_path, rooms)
                ps.export_characters(characters_path, characters_stat)
                return redirect(f"/room/{id}")
        else:
            return render_template("join_room.html", room=selected_room, message="Password is incorrect")
    if "room_id" not in session or session["room_id"] != id:
        return render_template("join_room.html", room=selected_room)
    return render_template("room.html", room=selected_room)
Пример #2
0
def bomb_animation(state, user_id, character_name):
    character_list = ps.get_characters(characters_path)
    current_character = get_current_player(character_list, character_name)
    current_character['bomb_used'] = str(
        int(current_character["bomb_used"]) + 1)
    ps.export_characters(characters_path, character_list)
    time.sleep(2)
    my_map = ps.get_map(map_path)
    my_map[state[0]][state[1]] = my_map[state[0]][state[1]].replace(
        (',0' + str(user_id)), (',M' + str(user_id)), 1)
    explosion_placement(0, 1, current_character, state, user_id, 'R', my_map)
    explosion_placement(0, -1, current_character, state, user_id, 'L', my_map)
    explosion_placement(1, 0, current_character, state, user_id, 'D', my_map)
    explosion_placement(-1, 0, current_character, state, user_id, 'U', my_map)
    ps.export_map(map_path, my_map)
    bomb_delete_animation(state, user_id, character_name)
Пример #3
0
def place_bomb():
    characters_stat = ps.get_characters(characters_path)
    my_dict = request.json
    game.show_bomb(my_dict['bombState'], my_dict['userId'], characters_stat, session["nickname"])
Пример #4
0
def player_move():
    characters_stat = ps.get_characters(characters_path)
    my_dict = request.json
    game.step_player(my_dict['state'], my_dict['next'], characters_stat, session["nickname"])
    ps.export_characters(characters_path, characters_stat)