-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPSS_Game.py
154 lines (145 loc) · 9.33 KB
/
PSS_Game.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import random
import telebot
from telebot import types
from DB_for_PSS_Game import id_lst, db_1665218818, db_guest
bot = telebot.TeleBot(token='bot_token')
@bot.message_handler(commands=['start'])
def start(message):
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton("Привет, Бот!")
markup.add(btn1)
bot.send_message(message.from_user.id, text="Привет! Я Бот для игры в камень-ножницы-бумага!"
.format(message.from_user), reply_markup=markup)
@bot.message_handler(content_types=['text'])
def get_text_messages(message):
# выбор словаря для ведения счета, по id пользователя (наброски авторизации)
global db
if message.from_user.id not in id_lst:
db = db_guest
elif message.from_user.id == 1665218818:
db = db_1665218818
# генерация хода бота
comp = random.randint(1, 9999)
if 1 <= comp <= 3333:
comp = "Камень 🗿"
elif 3333 < comp <= 6666:
comp = "Бумага 📄"
elif 6666 < comp <= 9999:
comp = "Ножницы ✂"
# прием хода игрока с условиями
if db['player_win'] < 5 and db['bot_win'] < 5:
if message.text == "Играть 🕹" or message.text == "Играть без авторизации 🕹":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton("Камень 🗿")
btn2 = types.KeyboardButton("Ножницы ✂")
btn3 = types.KeyboardButton("Бумага 📄")
btn4 = types.KeyboardButton("Помощь ❓")
markup.add(btn1, btn2, btn3, btn4)
bot.send_message(message.from_user.id, text="Выберите свой ход или Помощь ❓",
reply_markup=markup)
elif message.text == "Камень 🗿" or message.text == "Бумага 📄" or message.text == "Ножницы ✂":
bot.send_message(message.from_user.id, f"Ход Бота - {comp}")
if message.text == "Камень 🗿":
if comp == message.text:
bot.send_message(message.from_user.id,
f"Игрок и Бот выбрали одинаковый ход. Ничья! 🤝")
elif comp == "Бумага 📄":
bot.send_message(message.from_user.id, f"Игрок проиграл... 😱")
db['bot_win'] = db['bot_win'] + 1
else:
bot.send_message(message.from_user.id, f"Игрок выиграл! ✌")
db['player_win'] = db['player_win'] + 1
elif message.text == "Ножницы ✂":
if comp == message.text:
bot.send_message(message.from_user.id,
f"Игрок и Бот выбрали одинаковый ход. Ничья! 🤝")
elif comp == "Камень 🗿":
bot.send_message(message.from_user.id, f"Игрок проиграл... 😱")
db['bot_win'] = db['bot_win'] + 1
else:
bot.send_message(message.from_user.id, f"Игрок выиграл! ✌")
db['player_win'] = db['player_win'] + 1
elif message.text == "Бумага 📄":
if comp == message.text:
bot.send_message(message.from_user.id,
f"Игрок и Бот выбрали одинаковый ход. Ничья! 🤝")
elif comp == "Ножницы ✂":
bot.send_message(message.from_user.id, f"Игрок проиграл... 😱")
db['bot_win'] = db['bot_win'] + 1
else:
bot.send_message(message.from_user.id, f"Игрок выиграл! ✌")
db['player_win'] = db['player_win'] + 1
elif message.text == "Проверка аккаунта 🚪":
if message.from_user.id not in id_lst:
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton("Играть без авторизации 🕹")
markup.add(btn1)
bot.send_message(message.from_user.id, f"Вас нет в базе данных...Просто играйте без авторизации!",
reply_markup=markup)
else:
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton("Играть 🕹")
markup.add(btn1)
bot.send_message(message.from_user.id, f"Вы в базе данных! Привет!", reply_markup=markup)
elif message.text == "Очистить 🧽":
bot.send_message(message.from_user.id,
f"Игра окончена со счетом Игрок {db['player_win']} - Бот {db['bot_win']}, "
f"счет обнулен")
bot.send_message(message.from_user.id, f"Напишите Играть 🕹 для начала новой игры")
db['bot_win'] = 0
db['player_win'] = 0
elif message.text == "Счет 🧮":
bot.send_message(message.from_user.id, f"Игрок {db['player_win']} - Бот {db['bot_win']}")
bot.send_message(message.from_user.id,
"Нажмите Играть 🕹 для продолжения игры")
elif message.text == "Серия побед 🏆":
if db['player_win'] > db['bot_win']:
bot.send_message(message.from_user.id, f"Серия побед Игрока - {db['player_win']} 🏆")
elif db['player_win'] < db['bot_win']:
bot.send_message(message.from_user.id, f"Серия побед Бота - {db['bot_win']} 🏆")
else:
bot.send_message(message.from_user.id,
f"У Вас и Бота одинаковое число побед Игрок - {db['player_win']} "
f"Бот - {db['bot_win']}")
bot.send_message(message.from_user.id,
"Нажмите Играть 🕹 для продолжения игры")
elif message.text == "Помощь ❓":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton("Играть 🕹")
btn2 = types.KeyboardButton("Счет 🧮")
btn3 = types.KeyboardButton("Серия побед 🏆")
btn4 = types.KeyboardButton("Очистить 🧽")
btn5 = types.KeyboardButton("Проверка аккаунта 🚪")
markup.add(btn1, btn2, btn3, btn4, btn5)
bot.send_message(message.from_user.id, text="Выберите Играть 🕹 для начала игры, Счет 🧮, Серия побед "
"🏆 или Очистить 🧽 для сброса счета", reply_markup=markup)
else:
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton("Камень 🗿")
btn2 = types.KeyboardButton("Ножницы ✂")
btn3 = types.KeyboardButton("Бумага 📄")
btn4 = types.KeyboardButton("Помощь ❓")
btn5 = types.KeyboardButton("Проверка аккаунта 🚪")
markup.add(btn1, btn2, btn3, btn4, btn5)
bot.send_message(message.from_user.id, text="Выберите свой ход для начала игры, Помощь ❓ "
"или Проверка аккаунта",
reply_markup=markup)
elif db['player_win'] == 5:
bot.send_message(message.from_user.id, f"Игрок выиграл матч, одержав {db['player_win']} побед! 🏆")
bot.send_message(message.from_user.id, f"Бот набрал {db['bot_win']}")
db['bot_win'] = 0
db['player_win'] = 0
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton("Играть 🕹")
markup.add(btn1)
bot.send_message(message.from_user.id, f"Нажмите Играть 🕹 для нового матча!", reply_markup=markup)
elif db['bot_win'] == 5:
bot.send_message(message.from_user.id, f"Бот выиграл матч, одержав {db['bot_win']} побед!...😱")
bot.send_message(message.from_user.id, f"Игрок набрал {db['player_win']}")
db['bot_win'] = 0
db['player_win'] = 0
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
btn1 = types.KeyboardButton("Играть 🕹")
markup.add(btn1)
bot.send_message(message.from_user.id, f"Нажмите Играть 🕹 для нового матча!", reply_markup=markup)
bot.polling(none_stop=True, interval=0)