Пример #1
0
def start_game(message):
    game = utils.get_game_from_chat(message.chat.id)
    if game is not None:
        if game.gamestate == game.gamestates[0]:
            if game.gametype == 'game':
                if not game.pending_team1 or not game.pending_team2:
                    bot.send_message(message.chat.id,
                                     "O'yinchilar soni yetarli emas...")
                elif len(game.pending_players) > len(game.pending_team1) + len(
                        game.pending_team2):
                    bot.send_message(message.chat.id,
                                     "Bazi o'yinchilar guruh tanlashmadi.")
                elif len(game.pending_players) == len(
                        game.pending_team1) + len(game.pending_team2):
                    game.gamestate = game.gamestates[1]
                    for actor in game.pending_team1:
                        game.players.append(actor)
                        game.team1.players.append(actor)
                        actor.team = game.team1
                    for actor in game.pending_team2:
                        game.players.append(actor)
                        game.team2.players.append(actor)
                        actor.team = game.team2
                    bot_handlers.start_fight(message.chat.id)
            elif game.gametype == 'custom':
                if not game.pending_team1 or not game.pending_team2:
                    bot.send_message(
                        message.chat.id,
                        "Boshlash uchun o'yinchilar soni yetarli emas...")
                elif len(game.pending_players) > len(game.pending_team1) + len(
                        game.pending_team2):
                    bot.send_message(message.chat.id,
                                     "Bazi o`yinchilar guruh tanlashmadi.")
                elif len(game.pending_players) == len(
                        game.pending_team1) + len(game.pending_team2):
                    game.gamestate = game.gamestates[1]
                    for actor in game.pending_team1:
                        game.players.append(actor)
                        game.team1.players.append(actor)
                        actor.team = game.team1
                    for actor in game.pending_team2:
                        game.players.append(actor)
                        game.team2.players.append(actor)
                        actor.team = game.team2
                    bot_handlers.start_custom_fight(message.chat.id)
            else:
                if len(game.pending_players) < 1:
                    bot.send_message(
                        message.chat.id,
                        "Boshlash uchun o`yinchilar soni yetarli emas...")
                else:
                    game.gamestate = game.gamestates[1]
                    for actor in game.pending_team1:
                        game.players.append(actor)
                        game.team1.players.append(actor)
                        actor.team = game.team1
                    bot_handlers.start_fight(message.chat.id)
Пример #2
0
def start_game(message):
    game = utils.get_game_from_chat(message.chat.id)
    if game is not None:
        if game.gamestate == game.gamestates[0]:
            if game.gametype == 'game':
                if not game.pending_team1 or not game.pending_team2:
                    bot.send_message(message.chat.id,
                                     "Недостаточно игроков для начала игры.")
                elif len(game.pending_players) > len(game.pending_team1) + len(
                        game.pending_team2):
                    bot.send_message(message.chat.id,
                                     "Не все игроки выбрали команду.")
                elif len(game.pending_players) == len(
                        game.pending_team1) + len(game.pending_team2):
                    game.gamestate = game.gamestates[1]
                    for actor in game.pending_team1:
                        game.players.append(actor)
                        game.team1.players.append(actor)
                        actor.team = game.team1
                    for actor in game.pending_team2:
                        game.players.append(actor)
                        game.team2.players.append(actor)
                        actor.team = game.team2
                    bot_handlers.start_fight(message.chat.id)
            elif game.gametype == 'custom':
                if not game.pending_team1 or not game.pending_team2:
                    bot.send_message(message.chat.id,
                                     "Недостаточно игроков для начала игры.")
                elif len(game.pending_players) > len(game.pending_team1) + len(
                        game.pending_team2):
                    bot.send_message(message.chat.id,
                                     "Не все игроки выбрали команду.")
                elif len(game.pending_players) == len(
                        game.pending_team1) + len(game.pending_team2):
                    game.gamestate = game.gamestates[1]
                    for actor in game.pending_team1:
                        game.players.append(actor)
                        game.team1.players.append(actor)
                        actor.team = game.team1
                    for actor in game.pending_team2:
                        game.players.append(actor)
                        game.team2.players.append(actor)
                        actor.team = game.team2
                    bot_handlers.start_custom_fight(message.chat.id)
            else:
                if len(game.pending_players) < 1:
                    bot.send_message(message.chat.id,
                                     "Недостаточно игроков для начала игры.")
                else:
                    game.gamestate = game.gamestates[1]
                    for actor in game.pending_team1:
                        game.players.append(actor)
                        game.team1.players.append(actor)
                        actor.team = game.team1
                    bot_handlers.start_fight(message.chat.id)
Пример #3
0
def start_game(message):
    game = utils.get_game_from_chat(message.chat.id)
    if game is not None:
        if game.gamestate == game.gamestates[0]:
            if game.gametype == 'game':
                if not game.pending_team1 or not game.pending_team2:
                    bot.send_message(message.chat.id, "Недостаточно игроков для начала игры.")
                elif len(game.pending_players) > len(game.pending_team1) + len(game.pending_team2):
                    bot.send_message(message.chat.id, "Не все игроки выбрали команду.")
                elif len(game.pending_players) == len(game.pending_team1) + len(game.pending_team2):
                    game.gamestate = game.gamestates[1]
                    for actor in game.pending_team1:
                        game.players.append(actor)
                        game.team1.players.append(actor)
                        actor.team = game.team1
                    for actor in game.pending_team2:
                        game.players.append(actor)
                        game.team2.players.append(actor)
                        actor.team = game.team2
                    bot_handlers.start_fight(message.chat.id)
            elif game.gametype == 'custom':
                if not game.pending_team1 or not game.pending_team2:
                    bot.send_message(message.chat.id, "Недостаточно игроков для начала игры.")
                elif len(game.pending_players) > len(game.pending_team1) + len(game.pending_team2):
                    bot.send_message(message.chat.id, "Не все игроки выбрали команду.")
                elif len(game.pending_players) == len(game.pending_team1) + len(game.pending_team2):
                    game.gamestate = game.gamestates[1]
                    for actor in game.pending_team1:
                        game.players.append(actor)
                        game.team1.players.append(actor)
                        actor.team = game.team1
                    for actor in game.pending_team2:
                        game.players.append(actor)
                        game.team2.players.append(actor)
                        actor.team = game.team2
                    bot_handlers.start_custom_fight(message.chat.id)
            else:
                if len(game.pending_players) < 1:
                    bot.send_message(message.chat.id, "Недостаточно игроков для начала игры.")
                else:
                    game.gamestate = game.gamestates[1]
                    for actor in game.pending_team1:
                        game.players.append(actor)
                        game.team1.players.append(actor)
                        actor.team = game.team1
                    bot_handlers.start_fight(message.chat.id)
Пример #4
0
def flee(message):
    game = utils.get_game_from_chat(message.chat.id)
    if game is not None:
        if message.from_user.id in game.marked_id and game.gamestate == game.gamestates[0]:
            for x in game.pending_players:
                if x.chat_id == message.from_user.id:
                    game.pending_players.remove(x)
            for x in game.marked_id:
                if x == message.from_user.id:
                    game.marked_id.remove(x)
            for x in game.pending_team1:
                if x.chat_id == message.from_user.id:
                    game.pending_team1.remove(x)
            for x in game.pending_team2:
                if x.chat_id == message.from_user.id:
                    game.pending_team2.remove(x)
            del Main_classes.dict_players[message.from_user.id]
            bot.send_message(game.cid, message.from_user.first_name + ' сбежал!')
Пример #5
0
def flee(message):
    game = utils.get_game_from_chat(message.chat.id)
    if game is not None:
        if message.from_user.id in game.marked_id and game.gamestate == game.gamestates[
                0]:
            for x in game.pending_players:
                if x.chat_id == message.from_user.id:
                    game.pending_players.remove(x)
            for x in game.marked_id:
                if x == message.from_user.id:
                    game.marked_id.remove(x)
            for x in game.pending_team1:
                if x.chat_id == message.from_user.id:
                    game.pending_team1.remove(x)
            for x in game.pending_team2:
                if x.chat_id == message.from_user.id:
                    game.pending_team2.remove(x)
            del Main_classes.dict_players[message.from_user.id]
            bot.send_message(game.cid,
                             message.from_user.first_name + ' qochib ketdi!')
Пример #6
0
def suicide(message):
    game = utils.get_game_from_chat(message.chat.id)
    if game != None:
        print("Игра найдена.")
        found = True
        actor = None
        try:
            actor = game.player_dict[message.from_user.id]
        except:
            print('ошибка')
            found = False

        if game.gamestate == 'fight' and found and actor in actor.team.players:
            actor.turn = 'suicide'
            try:
                game.fight.playerpool.remove(actor)
            except:
                pass
            try:
                bot.delete_message(chat_id=actor.chat_id, message_id=actor.choicemessage)
            except:
                pass
Пример #7
0
def suicide(message):
    game = utils.get_game_from_chat(message.chat.id)
    if game != None:
        print("Игра найдена.")
        found = True
        actor = None
        try:
            actor = game.player_dict[message.from_user.id]
        except:
            print('ошибка')
            found = False

        if game.gamestate == 'fight' and found and actor in actor.team.players:
            actor.turn = 'suicide'
            try:
                game.fight.playerpool.remove(actor)
            except:
                pass
            try:
                bot.delete_message(chat_id=actor.chat_id,
                                   message_id=actor.choicemessage)
            except:
                pass
Пример #8
0
def add_player(message):
    game = utils.get_game_from_chat(message.chat.id)
    if message.from_user.id in Main_classes.dict_players:
        pass
    elif game is not None:
        try:
            no = 0
            for ids in message.from_user.first_name:
                if ids.lower() not in symbols:
                    no = 1
            if no == 0:
                name = message.from_user.first_name.split(' ')[0][:12]
            else:
                name = message.from_user.username
            bot.send_message(message.from_user.id,
                             'Вы присоединились к игре.',
                             parse_mode='markdown')
            if game.gametype == game.gametypes[0] and message.from_user.id not in game.marked_id \
                    and message.chat.id == game.cid and game.gamestate == game.gamestates[0]:
                player = Main_classes.Player(message.from_user.id, name,
                                             Weapon_list.fists, game,
                                             message.from_user.username)
                game.pending_players.append(player)
                game.marked_id.append(player.chat_id)
                Main_classes.dict_players[player.chat_id] = game
                game.gamers = game.gamers + 1
                bot.send_message(
                    game.cid,
                    name + ' успешно присоединился. Всего игроков: ' +
                    str(game.gamers))
                if not game.pending_team1:
                    game.pending_team1.append(player)
                    datahandler.get_player(message.from_user.id,
                                           message.from_user.username, name)
                elif not game.pending_team2:
                    game.pending_team2.append(player)
                    datahandler.get_player(message.from_user.id,
                                           message.from_user.username, name)
                elif len(game.pending_players) >= 3:
                    keyboard = types.InlineKeyboardMarkup()
                    callback_button1 = types.InlineKeyboardButton(
                        text=str(len(game.pending_team1)) + ' - ' +
                        game.pending_team1[0].name,
                        callback_data='team1')
                    callback_button2 = types.InlineKeyboardButton(
                        text=str(len(game.pending_team2)) + ' - ' +
                        game.pending_team2[0].name,
                        callback_data='team2')
                    keyboard.add(callback_button1, callback_button2)
                    bot.send_message(message.from_user.id,
                                     name +
                                     ' Выберите, кому вы поможете в этом '
                                     'бою.',
                                     reply_markup=keyboard)
                    datahandler.get_player(message.from_user.id,
                                           message.from_user.username, name)
            elif game.gametype == game.gametypes[3] and message.from_user.id not in game.marked_id \
                    and message.chat.id == game.cid and game.gamestate == game.gamestates[0]:
                datahandler.get_player(message.from_user.id,
                                       message.from_user.username, name)
                data = datahandler.get_current(message.from_user.id)
                bot.send_message(
                    game.cid,
                    name + ' успешно присоединился к кастомной игре.')
                if data[0] is not None and data[1] is not None and data[
                        2] is not None:
                    player = Main_classes.Player(message.from_user.id,
                                                 name.split(' ')[0][:12],
                                                 Weapon_list.fists, game,
                                                 message.from_user.username)
                    game.pending_players.append(player)
                    game.marked_id.append(player.chat_id)
                    Main_classes.dict_players[player.chat_id] = game
                    if not game.pending_team1:
                        game.pending_team1.append(player)
                        datahandler.get_player(message.from_user.id,
                                               message.from_user.username,
                                               name)
                    elif not game.pending_team2:
                        game.pending_team2.append(player)
                        datahandler.get_player(message.from_user.id,
                                               message.from_user.username,
                                               name)
                    elif len(game.pending_players) >= 3:
                        keyboard = types.InlineKeyboardMarkup()
                        callback_button1 = types.InlineKeyboardButton(
                            text=str(len(game.pending_team1)) + ' - ' +
                            game.pending_team1[0].name,
                            callback_data='team1')
                        callback_button2 = types.InlineKeyboardButton(
                            text=str(len(game.pending_team2)) + ' - ' +
                            game.pending_team2[0].name,
                            callback_data='team2')
                        keyboard.add(callback_button1, callback_button2)
                        bot.send_message(message.from_user.id,
                                         message.from_user.first_name +
                                         ' Выберите, кому вы поможете в этом '
                                         'бою.',
                                         reply_markup=keyboard)
                else:
                    bot.send_message(message.chat.id, 'Заполните лист /player')

            elif message.from_user.id not in game.marked_id and message.chat.id == game.cid and \
                            game.gamestate == game.gamestates[0]:
                if game.gametype == game.gametypes[1] and len(
                        game.pending_players) > 2:
                    pass
                else:
                    game.gamers = game.gamers + 1
                    bot.send_message(
                        game.cid,
                        name + ' успешно присоединился. Всего игроков: ' +
                        str(game.gamers))
                    datahandler.get_player(message.from_user.id,
                                           message.from_user.username, name)
                    player = Main_classes.Player(message.from_user.id,
                                                 name.split(' ')[0][:12], None,
                                                 game,
                                                 message.from_user.username)
                    game.pending_players.append(player)
                    game.pending_team1.append(player)

                    Main_classes.dict_players[player.chat_id] = game
                    game.marked_id.append(player.chat_id)
            elif game.gamestate != game.gamestates[0]:
                bot.send_message(message.chat.id,
                                 'Нет запущенной игры или игра уже началась.')
        except:
            bot.send_message(
                message.chat.id,
                'Что-то пошло не так. Возможно, стоит начать разговор с ботом @'
                + config.username)

    time.sleep(3)
Пример #9
0
def cancel(message):
    game = utils.get_game_from_chat(message.chat.id)
    if game is not None and game.gamestate == game.gamestates[0]:
        bot_handlers.cancel_game(game)
Пример #10
0
def add_player(message):
    game = utils.get_game_from_chat(message.chat.id)
    if message.from_user.id in Main_classes.dict_players:
        pass
    elif game is not None:
        try:
            bot.send_message(message.from_user.id,
                             "Siz o'yinga omadli qo'shildingiz.",
                             parse_mode='markdown')
            if game.gametype == game.gametypes[0] and message.from_user.id not in game.marked_id \
                    and message.chat.id == game.cid and game.gamestate == game.gamestates[0]:
                player = Main_classes.Player(
                    message.from_user.id,
                    message.from_user.first_name.split(' ')[0][:12],
                    Weapon_list.fists, game, message.from_user.username)
                game.pending_players.append(player)
                game.marked_id.append(player.chat_id)
                Main_classes.dict_players[player.chat_id] = game
                bot.send_message(
                    game.cid,
                    message.from_user.first_name + ' o`yinga qo`shildi.')
                if not game.pending_team1:
                    game.pending_team1.append(player)
                    datahandler.get_player(message.from_user.id,
                                           message.from_user.username,
                                           message.from_user.first_name)
                elif not game.pending_team2:
                    game.pending_team2.append(player)
                    datahandler.get_player(message.from_user.id,
                                           message.from_user.username,
                                           message.from_user.first_name)
                elif len(game.pending_players) >= 3:
                    keyboard = types.InlineKeyboardMarkup()
                    callback_button1 = types.InlineKeyboardButton(
                        text=str(len(game.pending_team1)) + ' - ' +
                        game.pending_team1[0].name,
                        callback_data='team1')
                    callback_button2 = types.InlineKeyboardButton(
                        text=str(len(game.pending_team2)) + ' - ' +
                        game.pending_team2[0].name,
                        callback_data='team2')
                    keyboard.add(callback_button1, callback_button2)
                    bot.send_message(message.from_user.id,
                                     message.from_user.first_name +
                                     ' Kimga yordam berishingizni '
                                     'tanlang.',
                                     reply_markup=keyboard)
                    datahandler.get_player(message.from_user.id,
                                           message.from_user.username,
                                           message.from_user.first_name)
            elif game.gametype == game.gametypes[3] and message.from_user.id not in game.marked_id \
                    and message.chat.id == game.cid and game.gamestate == game.gamestates[0]:
                datahandler.get_player(message.from_user.id,
                                       message.from_user.username,
                                       message.from_user.first_name)
                data = datahandler.get_current(message.from_user.id)
                bot.send_message(
                    game.cid, message.from_user.first_name +
                    ' sozlangan janga omadli qo`shildi.')
                if data[0] is not None and data[1] is not None and data[
                        2] is not None:
                    player = Main_classes.Player(
                        message.from_user.id,
                        message.from_user.first_name.split(' ')[0][:12],
                        Weapon_list.fists, game, message.from_user.username)
                    game.pending_players.append(player)
                    game.marked_id.append(player.chat_id)
                    Main_classes.dict_players[player.chat_id] = game
                    if not game.pending_team1:
                        game.pending_team1.append(player)
                        datahandler.get_player(message.from_user.id,
                                               message.from_user.username,
                                               message.from_user.first_name)
                    elif not game.pending_team2:
                        game.pending_team2.append(player)
                        datahandler.get_player(message.from_user.id,
                                               message.from_user.username,
                                               message.from_user.first_name)
                    elif len(game.pending_players) >= 3:
                        keyboard = types.InlineKeyboardMarkup()
                        callback_button1 = types.InlineKeyboardButton(
                            text=str(len(game.pending_team1)) + ' - ' +
                            game.pending_team1[0].name,
                            callback_data='team1')
                        callback_button2 = types.InlineKeyboardButton(
                            text=str(len(game.pending_team2)) + ' - ' +
                            game.pending_team2[0].name,
                            callback_data='team2')
                        keyboard.add(callback_button1, callback_button2)
                        bot.send_message(message.from_user.id,
                                         message.from_user.first_name +
                                         ' Kimga jangda yordam berishingizni '
                                         'tanlang.',
                                         reply_markup=keyboard)
                else:
                    bot.send_message(message.chat.id,
                                     '/player jadvalini to`ldiring')

            elif message.from_user.id not in game.marked_id and message.chat.id == game.cid and \
                            game.gamestate == game.gamestates[0]:
                if game.gametype == game.gametypes[1] and len(
                        game.pending_players) > 2:
                    pass
                else:
                    bot.send_message(
                        game.cid,
                        message.from_user.first_name + ' o`yinga qo`shildi.')
                    datahandler.get_player(message.from_user.id,
                                           message.from_user.username,
                                           message.from_user.first_name)
                    player = Main_classes.Player(
                        message.from_user.id,
                        message.from_user.first_name.split(' ')[0][:12], None,
                        game, message.from_user.username)
                    game.pending_players.append(player)
                    game.pending_team1.append(player)

                    Main_classes.dict_players[player.chat_id] = game
                    game.marked_id.append(player.chat_id)
            elif game.gamestate != game.gamestates[0]:
                bot.send_message(
                    message.chat.id,
                    'O`yin boshlanmagan yoki allaqachon bo`layabdi.')
        except:
            bot.send_message(
                message.chat.id,
                'O`yinga qo`shilish uchun @HuntUzBot bilan bog`laning.')

    time.sleep(3)
Пример #11
0
def add_player(message):
    game = utils.get_game_from_chat(message.chat.id)
    if message.from_user.id in Main_classes.dict_players:
        pass
    elif game is not None:
        try:
            bot.send_message(message.from_user.id, 'Вы присоединились к игре.', parse_mode='markdown')
            if game.gametype == game.gametypes[0] and message.from_user.id not in game.marked_id \
                    and message.chat.id == game.cid and game.gamestate == game.gamestates[0]:
                player = Main_classes.Player(message.from_user.id, message.from_user.first_name.split(' ')[0][:12], Weapon_list.fists,
                                         game, message.from_user.username)
                game.pending_players.append(player)
                game.marked_id.append(player.chat_id)
                Main_classes.dict_players[player.chat_id] = game
                bot.send_message(game.cid, message.from_user.first_name + ' успешно присоединился.')
                if not game.pending_team1:
                    game.pending_team1.append(player)
                    datahandler.get_player(message.from_user.id, message.from_user.username, message.from_user.first_name)
                elif not game.pending_team2:
                    game.pending_team2.append(player)
                    datahandler.get_player(message.from_user.id, message.from_user.username, message.from_user.first_name)
                elif len(game.pending_players) >= 3:
                    keyboard = types.InlineKeyboardMarkup()
                    callback_button1 = types.InlineKeyboardButton(
                        text=str(len(game.pending_team1)) + ' - ' + game.pending_team1[0].name, callback_data='team1')
                    callback_button2 = types.InlineKeyboardButton(
                        text=str(len(game.pending_team2)) + ' - ' + game.pending_team2[0].name, callback_data='team2')
                    keyboard.add(callback_button1, callback_button2)
                    bot.send_message(message.from_user.id,
                                 message.from_user.first_name + ' Выберите, кому вы поможете в этом '
                                                                'бою.', reply_markup=keyboard)
                    datahandler.get_player(message.from_user.id, message.from_user.username, message.from_user.first_name)
            elif game.gametype == game.gametypes[3] and message.from_user.id not in game.marked_id \
                    and message.chat.id == game.cid and game.gamestate == game.gamestates[0]:
                datahandler.get_player(message.from_user.id, message.from_user.username, message.from_user.first_name)
                data = datahandler.get_current(message.from_user.id)
                bot.send_message(game.cid, message.from_user.first_name + ' успешно присоединился к кастомной игре.')
                if data[0] is not None and data[1] is not None and data[2] is not None:
                    player = Main_classes.Player(message.from_user.id, message.from_user.first_name.split(' ')[0][:12],
                                                 Weapon_list.fists, game, message.from_user.username)
                    game.pending_players.append(player)
                    game.marked_id.append(player.chat_id)
                    Main_classes.dict_players[player.chat_id] = game
                    if not game.pending_team1:
                        game.pending_team1.append(player)
                        datahandler.get_player(message.from_user.id, message.from_user.username, message.from_user.first_name)
                    elif not game.pending_team2:
                        game.pending_team2.append(player)
                        datahandler.get_player(message.from_user.id, message.from_user.username, message.from_user.first_name)
                    elif len(game.pending_players) >= 3:
                        keyboard = types.InlineKeyboardMarkup()
                        callback_button1 = types.InlineKeyboardButton(
                            text=str(len(game.pending_team1)) + ' - ' + game.pending_team1[0].name, callback_data='team1')
                        callback_button2 = types.InlineKeyboardButton(
                            text=str(len(game.pending_team2)) + ' - ' + game.pending_team2[0].name, callback_data='team2')
                        keyboard.add(callback_button1, callback_button2)
                        bot.send_message(message.from_user.id,
                                 message.from_user.first_name + ' Выберите, кому вы поможете в этом '
                                                                'бою.', reply_markup=keyboard)
                else:
                    bot.send_message(message.chat.id, 'Заполните лист /player')

            elif message.from_user.id not in game.marked_id and message.chat.id == game.cid and \
                            game.gamestate == game.gamestates[0]:
                if game.gametype == game.gametypes[1] and len(game.pending_players) > 2:
                    pass
                else:
                    bot.send_message(game.cid, message.from_user.first_name + ' успешно присоединился.')
                    datahandler.get_player(message.from_user.id, message.from_user.username, message.from_user.first_name)
                    player = Main_classes.Player(message.from_user.id, message.from_user.first_name.split(' ')[0][:12],
                                                 None, game, message.from_user.username)
                    game.pending_players.append(player)
                    game.pending_team1.append(player)

                    Main_classes.dict_players[player.chat_id] = game
                    game.marked_id.append(player.chat_id)
            elif game.gamestate != game.gamestates[0]:
                bot.send_message(message.chat.id, 'Нет запущенной игры или игра уже началась.')
        except:
            bot.send_message(message.chat.id, 'Что-то пошло не так. Возможно, стоит начать разговор с ботом @veganwarsbot.')

    time.sleep(3)