-
Notifications
You must be signed in to change notification settings - Fork 0
/
hangman.py
189 lines (164 loc) ยท 5.54 KB
/
hangman.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
import discord
import random
from words import *
HANGMAN0 = "-------"
HANGMAN1 = " |\n" \
" |\n" \
" |\n" \
" |\n" \
" |"
HANGMAN2 = " -------\n" \
" |\n" \
" |\n" \
" |\n" \
" |\n" \
" |"
HANGMAN3 = " -------\n" \
" |/\n" \
" |\n" \
" |\n" \
" |\n" \
" |"
HANGMAN4 = " -------\n" \
" |/----|\n" \
" |\n" \
" |\n" \
" |\n" \
" |"
HANGMAN5 = " -------\n" \
" |/----|\n" \
" |---- 0\n" \
" |\n" \
" |\n" \
" |"
HANGMAN6 = " -------\n" \
" |/----|\n" \
" |---- O\n" \
" |-----|\n" \
" |\n" \
" |"
HANGMAN7 = " -------\n" \
" |/----|\n" \
" |---- O\n" \
" |----/|\n" \
" |\n" \
" |"
HANGMAN8 = " -------\n" \
" |/----|\n" \
" |---- O\n" \
" |----/|\\ \n" \
" |\n" \
" |"
HANGMAN9 = " -------\n" \
" |/----|\n" \
" |---- O\n" \
" |----/|\\ \n" \
" |----/\n" \
" |"
HANGMAN10 = " -------\n" \
" |/----|\n" \
" |---- O\n" \
" |----/|\\ \n" \
" |----/ \\ \n" \
" |"
HANGMEN = [HANGMAN10, HANGMAN9, HANGMAN8, HANGMAN7, HANGMAN6,
HANGMAN5, HANGMAN4, HANGMAN3, HANGMAN2, HANGMAN1, HANGMAN0]
async def hangman(ctx, bot):
alphabet = ['๐ฆ', '๐ง', '๐จ', '๐ฉ', '๐ช', '๐ซ', '๐ฌ', '๐ญ', '๐ฎ', '๐ฏ', '๐ฐ', '๐ฑ', '๐ฒ',
'๐ณ', '๐ด', '๐ต', '๐ถ', '๐ท', '๐ธ', '๐น', '๐บ', '๐ป', '๐ผ', '๐ฝ', '๐พ', '๐ฟ']
emojis = {
'๐ฆ': 'a',
'๐ง': 'b',
'๐จ': 'c',
'๐ฉ': 'd',
'๐ช': 'e',
'๐ซ': 'f',
'๐ฌ': 'g',
'๐ญ': 'h',
'๐ฎ': 'i',
'๐ฏ': 'j',
'๐ฐ': 'k',
'๐ฑ': 'l',
'๐ฒ': 'm',
'๐ณ': 'n',
'๐ด': 'o',
'๐ต': 'p',
'๐ถ': 'q',
'๐ท': 'r',
'๐ธ': 's',
'๐น': 't',
'๐บ': 'u',
'๐ป': 'v',
'๐ผ': 'w',
'๐ฝ': 'x',
'๐พ': 'y',
'๐ฟ': 'z'
}
lives = 10
word = random.choice(WORDS)
print(word)
guess_word = ['?' for i in word]
while ("".join(guess_word).find('?') != -1):
guess_word_str = " ".join(guess_word)
embed = discord.Embed(
title="Your life is in your hands!",
description=f"Tries left: {lives}\n\n" + HANGMEN[lives]
)
await ctx.send(embed=embed)
await ctx.send(f"Current word: {guess_word_str}")
if lives == 0:
break
await showLetters(ctx, alphabet)
def checkNotBot(reaction, user):
return user != bot.user
reaction, user = await bot.wait_for("reaction_add", timeout=60.0, check=checkNotBot)
guess = str(reaction.emoji)
found = checkGuess(guess, word, guess_word, emojis, alphabet)
lives = checkLives(lives, found)
await ctx.channel.purge(limit=4)
if (lives == 0):
msg = await ctx.send(f"You died! The word was {word}! Do you want to play again?")
await msg.add_reaction('โ
')
await msg.add_reaction('โ')
reaction, user = await bot.wait_for("reaction_add", timeout=30.0, check=checkNotBot)
if str(reaction.emoji) == 'โ
':
alphabet = ['๐ฆ', '๐ง', '๐จ', '๐ฉ', '๐ช', '๐ซ', '๐ฌ', '๐ญ', '๐ฎ', '๐ฏ', '๐ฐ', '๐ฑ', '๐ฒ',
'๐ณ', '๐ด', '๐ต', '๐ถ', '๐ท', '๐ธ', '๐น', '๐บ', '๐ป', '๐ผ', '๐ฝ', '๐พ', '๐ฟ']
await ctx.channel.purge(limit=3)
await hangman(ctx, bot)
else:
await ctx.channel.purge(limit=3)
await ctx.send("Thank you for playing Hangman!")
else:
msg = await ctx.send(f"You gussed it! Do you want to play again?")
await msg.add_reaction('โ
')
await msg.add_reaction('โ')
reaction, user = await bot.wait_for("reaction_add", timeout=30.0, check=checkNotBot)
if str(reaction.emoji) == 'โ
':
alphabet = ['๐ฆ', '๐ง', '๐จ', '๐ฉ', '๐ช', '๐ซ', '๐ฌ', '๐ญ', '๐ฎ', '๐ฏ', '๐ฐ', '๐ฑ', '๐ฒ',
'๐ณ', '๐ด', '๐ต', '๐ถ', '๐ท', '๐ธ', '๐น', '๐บ', '๐ป', '๐ผ', '๐ฝ', '๐พ', '๐ฟ']
await ctx.channel.purge(limit=1)
await hangman(ctx, bot)
else:
await ctx.channel.purge(limit=1)
await ctx.send("Thank you for playing Hangman!")
async def showLetters(ctx, alphabet):
msg1 = await ctx.send("Choose!")
for i in range(int(len(alphabet) / 2)):
await msg1.add_reaction(alphabet[i])
msg2 = await ctx.send("A letter!")
for i in range(int(len(alphabet) / 2), len(alphabet)):
await msg2.add_reaction(alphabet[i])
def checkGuess(guess, word, guess_word, emojis, alphabet):
found = False
letter = emojis[guess]
alphabet.remove(guess)
for i in range(len(word)):
if word[i] == letter:
found = True
guess_word[i] = letter
return found
def checkLives(lives, flag):
if not flag:
return lives - 1
return lives