forked from ElectroLodge/Hacktober_Fest_2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hangman.py
123 lines (112 loc) · 3.5 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
class Hangman():
def __init__(self):
print "Welcome to 'Hangman', are you ready to die?"
print "(1)Yes, for I am already dead.\n(2)No, get me outta here!"
user_choice_1 = raw_input("->")
if user_choice_1 == '1':
print "Loading nooses, murderers, rapists, thiefs, lunatics..."
self.start_game()
elif user_choice_1 == '2':
print "Bye bye now..."
exit()
else:
print "I'm sorry, I'm hard of hearing, could you repeat that?"
self.__init__()
def start_game(self):
print "A crowd begins to gather, they can't wait to see some real"
print "justice. There's just one thing, you aren't a real criminal."
print "No, no. You're the wrong time, wrong place type. You may think"
print "you're dead, but it's not like that at all. Yes, yes. You've"
print "got a chance to live. All you've gotta do is guess the right"
print "words and you can live to see another day. But don't get so"
print "happy yet. If you make 6 wrong guess, YOU'RE TOAST! VAMANOS!"
self.core_game()
def core_game(self):
guesses = 0
letters_used = ""
the_word = "pizza"
progress = ["?", "?", "?", "?", "?"]
while guesses < 6:
guess = raw_input("Guess a letter ->")
if guess in the_word and not in letters_used:
print "As it turns out, your guess was RIGHT!"
letters_used += "," + guess
self.hangman_graphic(guesses)
print "Progress: " + self.progress_updater(guess, the_word, progress)
print "Letter used: " + letters_used
elif guess not in the_word and not(in letters_used):
guesses += 1
print "Things aren't looking so good, that guess was WRONG!"
print "Oh man, that crowd is getting happy, I thought you"
print "wanted to make them mad?"
letters_used += "," + guess
self.hangman_graphic(guesses)
print "Progress: " + "".join(progress)
print "Letter used: " + letters_used
else:
print "That's the wrong letter, you wanna be out here all day?"
print "Try again!"
def hangman_graphic(self, guesses):
if guesses == 0:
print "________ "
print "| | "
print "| "
print "| "
print "| "
print "| "
elif guesses == 1:
print "________ "
print "| | "
print "| 0 "
print "| "
print "| "
print "| "
elif guesses == 2:
print "________ "
print "| | "
print "| 0 "
print "| / "
print "| "
print "| "
elif guesses == 3:
print "________ "
print "| | "
print "| 0 "
print "| /| "
print "| "
print "| "
elif guesses == 4:
print "________ "
print "| | "
print "| 0 "
print "| /|\ "
print "| "
print "| "
elif guesses == 5:
print "________ "
print "| | "
print "| 0 "
print "| /|\ "
print "| / "
print "| "
else:
print "________ "
print "| | "
print "| 0 "
print "| /|\ "
print "| / \ "
print "| "
print "The noose tightens around your neck, and you feel the"
print "sudden urge to urinate."
print "GAME OVER!"
self.__init__()
def progress_updater(self, guess, the_word, progress):
i = 0
while i < len(the_word):
if guess == the_word[i]:
progress[i] = guess
i += 1
else:
i += 1
return "".join(progress)
game = Hangman()