-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathhangman_game.py
More file actions
174 lines (151 loc) · 12 KB
/
hangman_game.py
File metadata and controls
174 lines (151 loc) · 12 KB
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
import random
print('''
██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
█░░░░░░██████████░░░░░░█░░░░░░░░░░░░░░█░░░░░░█████████░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░██████████░░░░░░█░░░░░░░░░░░░░░█
█░░▄▀░░██████████░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░█████████░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░░░░░░░░░░░░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█
█░░▄▀░░██████████░░▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░█████████░░▄▀░░░░░░░░░░█░░▄▀░░░░░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░░░░░░░░░█
█░░▄▀░░██████████░░▄▀░░█░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░▄▀░░░░░░▄▀░░░░░░▄▀░░█░░▄▀░░█████████
█░░▄▀░░██░░░░░░██░░▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░░░░░░░░░█
█░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█
█░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░▄▀░░██░░░░░░██░░▄▀░░█░░▄▀░░░░░░░░░░█
█░░▄▀░░░░░░▄▀░░░░░░▄▀░░█░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░▄▀░░██████████░░▄▀░░█░░▄▀░░█████████
█░░▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░░░░░░░░░█░░▄▀░░░░░░░░░░█░░▄▀░░░░░░▄▀░░█░░▄▀░░██████████░░▄▀░░█░░▄▀░░░░░░░░░░█
█░░▄▀░░░░░░▄▀░░░░░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░██████████░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█
█░░░░░░██░░░░░░██░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░██████████░░░░░░█░░░░░░░░░░░░░░█
██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
''')
print('''
───────────────────────────────
─██████████████─██████████████─
─██░░░░░░░░░░██─██░░░░░░░░░░██─
─██████░░██████─██░░██████░░██─
─────██░░██─────██░░██──██░░██─
─────██░░██─────██░░██──██░░██─
─────██░░██─────██░░██──██░░██─
─────██░░██─────██░░██──██░░██─
─────██░░██─────██░░██──██░░██─
─────██░░██─────██░░██████░░██─
─────██░░██─────██░░░░░░░░░░██─
─────██████─────██████████████─
───────────────────────────────
''')
print('''
██╗░░██╗░█████╗░███╗░░██╗░██████╗░███╗░░░███╗░█████╗░███╗░░██╗ ░██████╗░░█████╗░███╗░░░███╗███████╗
██║░░██║██╔══██╗████╗░██║██╔════╝░████╗░████║██╔══██╗████╗░██║ ██╔════╝░██╔══██╗████╗░████║██╔════╝
███████║███████║██╔██╗██║██║░░██╗░██╔████╔██║███████║██╔██╗██║ ██║░░██╗░███████║██╔████╔██║█████╗░░
██╔══██║██╔══██║██║╚████║██║░░╚██╗██║╚██╔╝██║██╔══██║██║╚████║ ██║░░╚██╗██╔══██║██║╚██╔╝██║██╔══╝░░
██║░░██║██║░░██║██║░╚███║╚██████╔╝██║░╚═╝░██║██║░░██║██║░╚███║ ╚██████╔╝██║░░██║██║░╚═╝░██║███████╗
╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝░╚═════╝░╚═╝░░░░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝ ░╚═════╝░╚═╝░░╚═╝╚═╝░░░░░╚═╝╚══════╝
''')
print('''
█▀▀ ▄▀█ █▀▄▀█ █▀▀ █▀█ █░░ ▄▀█ █▄█
█▄█ █▀█ █░▀░█ ██▄ █▀▀ █▄▄ █▀█ ░█░
''')
print('''
1. The computer will give you a word or phrase to guess.
2. The player will try to guess the given word what it is one letter at a time.
3. The computer draws a number of dashes equivalent to the number of letters in the word.
4. If the player suggests a letter that occurs in the word, the computer will fill in the blanks with that letter in the
right places.
5. If the word does not contain the suggested letter, the computer will draw one element of a hangman’s gallows. As the
game progresses, a segment of the gallows and of a victim is added for every suggested letter not in the word.
6. The number of incorrect guesses before the game ends is up to the players, but completing a character in a noose
provides a minimum of six wrong answers until the game ends.
''')
print('''
█▀█ █▄▄ ░░█ █▀▀ █▀▀ ▀█▀ █ █░█ █▀▀ ▀
█▄█ █▄█ █▄█ ██▄ █▄▄ ░█░ █ ▀▄▀ ██▄ ▄
''')
print('''
Guess the word/phrase before your man gets hung!
''')
stages = ['''
+---+
| |
O |
/|\ |
/ \ |
|
=========
''', '''
+---+
| |
O |
/|\ |
/ |
|
=========
''', '''
+---+
| |
O |
/|\ |
|
|
=========
''', '''
+---+
| |
O |
/| |
|
|
=========''', '''
+---+
| |
O |
| |
|
|
=========
''', '''
+---+
| |
O |
|
|
|
=========
''', '''
+---+
| |
|
|
|
|
=========
''']
word_list = ["banana", "apple", "cherry","january","border","image","film","promise","kids","lungs","doll","rhyme","damage"
,"plants",'rainbow', 'computer', 'science', 'programming','python', 'mathematics', 'player', 'condition',
'reverse', 'water', 'board']
word_choice = word_list[random.randint(0, 24)]
length = len(word_choice)
lives=6
start=int(input("Press 1 to start the game!\n"))
if start == 1:
display = []
for _ in range(length):
display += "_"
print(f"{' '.join(display)}")
end_of_game = False
while end_of_game == False:
guess = input("\nGuess a letter \n").lower()
for pos in range(length):
letter = word_choice[pos]
if (letter == guess):
display[pos] = letter
if guess not in word_choice:
lives-=1
if lives == 0:
end_of_game = True
print(f"{' '.join(display)}")
print(stages[lives])
if lives==0:
print("You Loose!")
print("You failed to guess the correct word!")
print(f"The correct world is: {word_choice} ")
if "_" not in display:
end_of_game = True
print("You Win!")
else:
print("You entered wrong choice!")