Exemplo n.º 1
0
def repeat_all_messages(message):
    user_id = message.from_user.id
    db = Db(db_dir)
    user = db.get_user_by_id(user_id)
    if user:
        if user[1]:
            if message.text in ['1', '2', '3', '4', '5', '6', '7', '8', '9']:
                pos = int(message.text)
                user_game = db.get_game(user_id)
                if '0' == user_game[2][pos]:
                    field = db.set_step(user_id, pos)
                    winner = who_win(field)
                    if winner:
                        markup = types.ReplyKeyboardHide()
                        field = draw_field(field)
                        bot.send_message(user_id,
                                         field + "\n" + winner,
                                         reply_markup=markup,
                                         parse_mode='HTML')
                        db.set_type_to_user(user_id, None)
                        if 'Ничья' == winner:
                            db.user_draw(user_id)
                        else:
                            db.user_win(user_id)
                        db.end_game(user_id)
                        return True
                    field = bot_step(user_id, field)
                    winner = who_win(field)
                    if winner:
                        markup = types.ReplyKeyboardHide()
                        field = draw_field(field)
                        bot.send_message(user_id,
                                         field + "\n" + winner,
                                         reply_markup=markup,
                                         parse_mode='HTML')
                        db.set_type_to_user(user_id, None)
                        if 'Ничья' == winner:
                            db.user_draw(user_id)
                        else:
                            db.user_lose(user_id)
                        db.end_game(user_id)
                        return True
                    field = draw_field(field)
                    bot.send_message(user_id, field, parse_mode='HTML')
                else:
                    bot.send_message(user_id, 'Так сходить нельзя')
            else:
                markup = types.ReplyKeyboardHide()
                if message.text in ['X', 'O']:
                    db.set_type_to_user(user_id, message.text)
                    bot.send_message(user_id,
                                     'Вы выбрали ' + str(message.text) + '!',
                                     reply_markup=markup)
                db.create_game(user_id)
                cmd_game(message)
Exemplo n.º 2
0
def end_game(message):
    user_id = message.from_user.id
    db = Db(db_dir)
    user = db.get_user_by_id(user_id)
    if not user:
        return False
    if user[5]:
        markup = types.ReplyKeyboardHide()
        db.set_type_to_user(user_id, None)
        db.end_game(user_id)
        bot.send_message(message.from_user.id,
                         "Игра окончена!",
                         reply_markup=markup)