-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhangman_main.py
46 lines (33 loc) · 1.12 KB
/
hangman_main.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
import hangman_class as hc
def main_loop():
picked_word = hc.Words(hc.grab_words())
word = picked_word.return_word()
print(word)
charlist = picked_word.convert_word()
hangman = hc.GameFunctions(charlist, word)
hangman.return_lines()
hangart = hangman.hangman_art()
error_count = 0
playgame = True
while playgame:
hangman.display_lines()
user_input = hangman.take_input()
check_letter = True
while check_letter:
if user_input in hangman.list_of_chars:
letter_index = [i for i, n in enumerate(hangman.list_of_chars) if n == user_input]
for index in letter_index:
hangman.list_of_underscores[index] = user_input
check_letter = False
else:
print("Try again!")
error_count += 1
print(hangart[error_count - 1])
check_letter = False
if error_count == len(hangart):
print("Game over!")
playgame = False
else:
continue
if __name__ == "__main__":
main_loop()