def current_trick(): if len(Preferans.trick()) == 0: return players_tricks() answer = 'Текущая взятка\n' for i in Preferans.trick(): answer += name_list[i.player] + ' - ' + hash_to_sting(i.card) + '\n' return players_tricks() + answer
def bidding(message): bot.send_message( id_list[Preferans.current_player()], 'Ваше слово!!\nМинимальная ставка - ' + hash_to_sting(Preferans.dib()) + 'Отправь "+" если хочешь играть, ' '"-" если хочешь пасануть и "мизер" если хочешь сказать мизер\n') bot.register_next_step_handler(message, bidding)
def start(): if Preferans.need_pass_card(): Preferans.add_pass_card() message = current_trick() + 'Ваш ход' bot.send_message(id_list[Preferans.current_player()], text=message, reply_markup=hand_to_keyboard(Preferans.current_hand()))
def whist(call): if call.from_user.id != id_list[Preferans.current_player()]: return if Preferans.get_whist(call.data == 'whist'): ask_whist() else: start()
def last_trick(): answer = '' answer += 'Забрал игрок ' + name_list[Preferans.current_player()] + '\n' for j in Preferans.last_trick(): for i in range(3): if i == j.player: answer += name_list[i] + ': ' + hash_to_sting(j.card) + '\n' return answer
def new_round(message): Preferans.set_round() bot.send_message(id_list[0], 'Твои карты:\n' + hand_to_string(Preferans.hand0())) bot.send_message(id_list[1], 'Твои карты:\n' + hand_to_string(Preferans.hand1())) bot.send_message(id_list[2], 'Твои карты:\n' + hand_to_string(Preferans.hand2())) bidding(message)
def ask_bidding(): keyboard = telebot.types.InlineKeyboardMarkup() key_raz = telebot.types.InlineKeyboardButton(text=hash_to_sting(Preferans.dib()), callback_data='raise') key_pas = telebot.types.InlineKeyboardButton(text='Пас', callback_data='fold') key_misere = telebot.types.InlineKeyboardButton(text='Мизер', callback_data='misere') keyboard.add(key_raz) keyboard.add(key_pas) keyboard.add(key_misere) question = "Ваша ставка?" bot.send_message(id_list[Preferans.current_player()], text=question, reply_markup=keyboard)
def ask_whist(): keyboard = telebot.types.InlineKeyboardMarkup() key_raz = telebot.types.InlineKeyboardButton(text='Вист', callback_data='whist') key_pas = telebot.types.InlineKeyboardButton(text='Пас', callback_data='pass') keyboard.add(key_raz) keyboard.add(key_pas) question = "Ваш слово? {0}".format(Preferans.current_player()) bot.send_message(id_list[Preferans.current_player()], text=question, reply_markup=keyboard)
def discarding(call): if call.from_user.id != id_list[Preferans.current_player()]: return Preferans.discard(int(call.data)) Preferans.inc_discard() bot.edit_message_reply_markup(chat_id=call.from_user.id, message_id=call.message.message_id, reply_markup=hand_to_keyboard(Preferans.hand_declarer())) if Preferans.discarded() == 2: Preferans.inc_discard() if Preferans.game_type() == 'game': config.state = 'set_game' bot.send_message(id_list[Preferans.declarer()], text='Закажите игру', reply_markup=game_keyboard()) else: config.state = 'game' start()
def get_card(call): if call.from_user.id != id_list[Preferans.current_player()]: return if Preferans.get_card(int(call.data)): if Preferans.cards_in_trick() == 0: for i in id_list: bot.send_message(i, last_trick()) start() else: for i in id_list: bot.send_message(i, last_trick()) for i in id_list: bot.send_message(i, players_tricks()) # Preferans.score() new_round()
def game_keyboard(): keyboard = telebot.types.InlineKeyboardMarkup() keys = [] for i in range(Preferans.dib() - 1, 44): if i % 4 == 0: key = telebot.types.InlineKeyboardButton(text=hash_to_sting(i), callback_data=str(i)) keyboard.row(*keys) keys.clear() keys.append(key) else: key = telebot.types.InlineKeyboardButton(text=hash_to_sting(i), callback_data=str(i)) keys.append(key) keyboard.row(*keys) return keyboard
def set_game(call): if call.from_user.id != id_list[Preferans.current_player()]: return Preferans.set_game(int(call.data)) start()
def bidding(call): if call.from_user.id != id_list[Preferans.current_player()]: return if Preferans.update_bidding(call.data): ask_bidding() else: result = '' if Preferans.game_type() == 'game': result = 'Играет ' + name_list[Preferans.declarer()] + '. Ждем пока игрок закажет игру.' if Preferans.game_type() == 'misere': result = name_list[Preferans.declarer()] + ' играет мизер. Ждем пока игрок понесет карты.' if Preferans.game_type() == 'all-pass': result = 'Распас. Ход с игрока ' + name_list[Preferans.move()] for i in id_list: if i != id_list[Preferans.declarer()]: bot.send_message(i, result) if Preferans.game_type() == 'game' or Preferans.game_type() == 'misere': talon = 'Прикуп:\n' + hand_to_string(Preferans.talon()) for i in id_list: bot.send_message(i, talon) Preferans.add_talon() keyboard = hand_to_keyboard(Preferans.hand_declarer()) bot.send_message(id_list[Preferans.declarer()], text='Что хотите понести?', reply_markup=keyboard)
def players_tricks(): answer = 'Взятки:\n' for i in range(3): answer += name_list[i] + ': ' + str(Preferans.player_tricks()[i]) + '\n' return answer
def get_answer(message): if message.from_user.id != id_list[Preferans.current_player()] \ or (message.text != '+' and message.text != '-' and message.text != 'мизер'): bot.register_next_step_handler(message, bidding) else: bot.send_message(message.from_user.id, 'coooool')