Esempio n. 1
0
async def edit_message_after_someone_win(player, enemy_id, function_for_text):
    cursor.execute(f"SELECT * FROM messages WHERE t_id = {player.t_id}")
    msg_id = cursor.fetchone()[0]

    cursor.execute(f"SELECT nickname FROM player WHERE t_id = {enemy_id}")
    enemy_nickname = cursor.fetchone()[0]
    text = function_for_text(enemy_nickname)

    keyboard = ''
    await bot.edit_message_text(chat_id=player.t_id,
                                message_id=msg_id,
                                text=text)
Esempio n. 2
0
async def start_filter(message: Message):
    t_id = message.from_user.id

    # if player in the next phase
    cursor.execute(f"SELECT player_phase FROM phase WHERE t_id = {t_id}")
    phase = cursor.fetchone()
    if phase:
        if phase[0] != 'in_queue':
            return

    # if player already in queue
    try:
        result = functions_for_work_with_bd.insert_player_to_queue(
            message)  # [(666),(555)] or False
    except MyError as err:
        await bot.send_message(t_id, *err.args)
        return

    # if only one player in the queue
    if not result:
        await bot.send_message(t_id, dictionary['/start'])

    # start game
    else:
        await logic_for_aiogram.start_game(t_id=t_id)
Esempio n. 3
0
async def edit_message_after_random(player):
    cursor.execute(f"SELECT * FROM messages WHERE t_id = {player.t_id}")
    msg_id = cursor.fetchone()[0]
    keyboard = keyboard_generator.get_keyboard_phase_2(player)
    await bot.edit_message_reply_markup(chat_id=player.t_id,
                                        message_id=msg_id,
                                        reply_markup=keyboard)
def get_turn_info(game):
    # get turn from bd and check for player
    cursor.execute(
        "SELECT turn FROM sea_battle_game WHERE t_id_1 = ? OR t_id_2 = ?",
        (game.player_1.t_id, game.player_2.t_id))
    turn = cursor.fetchone()[0]
    reverse_turn = 2 if turn == 1 else 1
    cost_dict_for_turn = {1: game.player_1, 2: game.player_2}

    return turn, reverse_turn, cost_dict_for_turn
Esempio n. 5
0
async def filter_callback(callback: CallbackQuery):
    await callback.answer(cache_time=1)
    cursor.execute(
        f"SELECT player_phase FROM phase WHERE t_id = {callback.from_user.id}")
    phase = cursor.fetchone()[0]

    if phase == phases.phase_2:
        await logic_for_aiogram.call_back_for_phase_2(callback=callback)

    elif phase == phases.phase_4:
        await logic_for_aiogram.call_back_for_phase_4(callback)
Esempio n. 6
0
async def edit_message_after_hit(player, player_for_hit):
    cursor.execute(f"SELECT * FROM messages WHERE t_id = {player.t_id}")
    msg_id = cursor.fetchone()[0]
    if player.t_id != player_for_hit.t_id:
        keyboard = keyboard_generator.get_actual_keyboard(player_for_hit,
                                                          invisible=True)
    else:
        keyboard = keyboard_generator.get_actual_keyboard(player_for_hit)

    await bot.edit_message_reply_markup(chat_id=player.t_id,
                                        message_id=msg_id,
                                        reply_markup=keyboard)
def collect_current_game_from_in_queue(t_id=False):
    if not t_id:
        cursor.execute("SELECT * FROM in_queue")
        players_ids = cursor.fetchall()
        t_id_1 = players_ids[0][0]
        t_id_2 = players_ids[1][0]
        players_ids = [t_id_1, t_id_2]
    else:
        cursor.execute(
            f"SELECT * FROM sea_battle_game WHERE t_id_1 = ? OR t_id_2 = ?",
            (t_id, t_id))
        players_ids = cursor.fetchone()
        t_id_1 = players_ids[0]
        t_id_2 = players_ids[1]
        players_ids = [t_id_1, t_id_2]

    players_objects = []

    player = collect_full_player(t_id_1, t_id_2)
    players_objects.append(player)

    player = collect_full_player(t_id_2, t_id_1)
    players_objects.append(player)

    player_1 = players_objects[0]
    player_2 = players_objects[1]
    t_id_1 = player_1.t_id
    t_id_2 = player_2.t_id

    cursor.execute(
        "SELECT turn FROM sea_battle_game WHERE t_id_1 = ? OR t_id_2 = ?",
        (t_id_1, t_id_1))
    turn_in_tuple = cursor.fetchall()  # [(turn)]

    if not turn_in_tuple:
        turn = 1
        cursor.execute("INSERT INTO sea_battle_game VALUES(?, ?, ?)",
                       (t_id_1, t_id_2, turn))
    else:
        turn = turn_in_tuple[0][0]

    current_game = some_classes.SeaBattleGame(player_1=player_1,
                                              player_2=player_2,
                                              t_id_1=t_id_1,
                                              t_id_2=t_id_2,
                                              turn=turn)

    cursor.execute("DELETE FROM in_queue")  # clear table
    conn.commit()

    return current_game
def get_phase(t_id):
    cursor.execute(f"SELECT player_phase from phase WHERE t_id = {t_id}")
    phase = cursor.fetchone()