-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWalkthePlankTerminalGame.py
279 lines (219 loc) · 9 KB
/
WalkthePlankTerminalGame.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
import random
import time
intro = (
"""
, _
(| | |_/ _, |\ |) _|_ |) _ /|/ \ |\ _, |)
| | | / | |/ |/) | |/\ |/ |__/ |/ / | /|/| |/)
\/ \/ \/|_/ |_/ | \/ |_/ | |/ |_/ | |_/ \/|_/ | |_/ | \/
___________________________________________________________________
|| * * * ||
|| * * * ||
|| ___. * * ||
|| * ___.\__|.__. * ||
|| \__|. .| \_|. ||
|| . X|___|___| . * ||
|| .__/_||____ ||__. * /\ ||
|| * . |/|____ |_\|_ |/ _ / \ ||
|| \ _/ |_X__\|_ |\||~,~{ / \ ||
|| \/\ |/| |_ |/:|`X'{ _ _/ \__||
|| \ \/ |___ |_\|_.|~~~ / . .. . ..||
|| _|X/\ |___\|_ :| |_. - .......... . .||
|| | __\_:____ | ||o-| ___/........ . . .. ..||
|| |/_-|-_|__ \|_ |/--| ____/ . . .. . . .. ... . ||
|| ........:| -|- o-o\_:_\|o-/:....../...........................||
|| ._._._._._\=\====o==o==o=/:.._._._._._._._._._._._._._._._._._||
|| _._._._._._\_\ ._._._._.:._._._._._._._._._._._._._.__._._._._||
|| ._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._||
||---------------------------------------------------------------||
""")
plank = [
"""
Take a step forward!
| | |
)_) )_) )_)
)___))___))___)
)____)____)_____)
_____|____|____|____ *
\ /==================
^^^^^ ^^^^^^^^^^^^^^^^^^^^^
""",
"""
Another step forward!
| | |
)_) )_) )_)
)___))___))___)
)____)____)_____)
_____|____|____|____ *
\ /==================
^^^^^ ^^^^^^^^^^^^^^^^^^^^^
""",
"""
Getting nervous are you?
| | |
)_) )_) )_)
)___))___))___)
)____)____)_____)
_____|____|____|____ *
\ /===================
^^^^^ ^^^^^^^^^^^^^^^^^^^^^
""",
"""
I hope you know how to swim!
| | |
)_) )_) )_)
)___))___))___)
)____)____)_____)
_____|____|____|____ *
\ /==================
^^^^^ ^^^^^^^^^^^^^^^^^^^^^
""",
"""
There's no turning back soon...
| | |
)_) )_) )_)
)___))___))___)
)____)____)_____)
_____|____|____|____ *
\ /==================
^^^^^ ^^^^^^^^^^^^^^^^^^^^^
^^^^^ ^^^^^^^^^^^^^^^^^^^^^
""",
"""
Getting awfully close to the edge!
| | |
)_) )_) )_)
)___))___))___)
)____)____)_____)
_____|____|____|____ *
\ /==================
^^^^^ ^^^^^^^^^^^^^^^^^^^^^
""",
"""
Give it your best guess next time!
| | |
)_) )_) )_)
)___))___))___)
)____)____)_____)
_____|____|____|____ *
\ /==================
^^^^^ ^^^^^^^^^^^^^^^^^^^^^
""",
"""
That's the best you can do?
| | |
)_) )_) )_)
)___))___))___)
)____)____)_____)
_____|____|____|____ *
\ /==================
^^^^^ ^^^^^^^^^^^^^^^^^^^^^
""",
"""
Any last words?
| | |
)_) )_) )_)
)___))___))___)
)____)____)_____)
_____|____|____|____ *
\ /==================
^^^^^ ^^^^^^^^^^^^^^^^^^^^^
""",
"""
YOU ARE SHARKBAIT
^`. o
^_ \ \ o o
\ \ { \ o
{ \ / `~~~--__
{ \___----~~' `~~-_
\ /// a `~.___________
/ /~~~~-, ,__. , /// __,,,,) o ' |
\/ \/ `~~~; ,---~~-_`~---\ \----\-o--'
/ / / /
'._.' _/_/
';|\
"""]
parrot = ("""
__,---.
/__|o\ )
`-\ / /
,) (,
// \\
{( )}
=======""===""===============
|||||
|||
|
""")
def introduction():
"""Print game intro"""
print(intro)
time.sleep(2)
print("Loading game...")
time.sleep(4)
print("\n\nARRRRRR!!!\nYou were captured by pirates! \nThe crew is ready to see you walk the plank! \nLucky for you, if there is something Captain Morgan likes \nmore than rum, it's a good game. \n\nGuess the name of Captain Morgan's parrot \nand you won't have to sleep with the fishies. \n\nBEWARE: Every wrong letter inches you closer to your doom!")
introduction()
def choose_to_play():
while True:
"""asks player if they would like to play"""
print("\nWould you like to play Walk the Plank?\n[A]ye or [N]ay\n")
player_decision = input("> ").lower()
if player_decision == "a":
break
elif player_decision == "n":
print(
"Too bad for you pirates don't take no for an answer. Start guessing!\n")
break
else:
print("What was that, mate? We asked...")
choose_to_play()
def game_play(plank):
"""Main game play"""
list_of_names = ["polly", "crackers", "jose", "jack"]
parrot_name = random.choice(list_of_names)
player_guess = ""
display_word = [] # list stores display word
attempts = 10
for letter in parrot_name:
"""replace letters to hide name from player"""
display_word.append(" * ")
while (attempts > 0 and " * " in display_word):
"""While there are still attempts and letters to guess, get player guess"""
joined_word = "".join(
display_word) # returns the string concatenated with the elements of an iterable
print("His name is: {}".format(joined_word))
print("\nChoose a letter: ")
player_guess = input("")
player_guess = player_guess.lower()
for letter in range(len(parrot_name)):
""" Iterates over each character in parrot's name checking for a match"""
if player_guess == parrot_name[letter]:
# replace all letters in bird name that match the players guess
display_word[letter] = player_guess
if player_guess not in parrot_name:
"""Wrong guess deducts attempt by one, and displays corresponding plank image"""
attempts = attempts - 1
print("\nIncorrect! Attempts remaining: {}".format(attempts))
# decrements element in list by attempts made
print(plank[(len(plank) - 1) - attempts])
if " * " not in display_word:
"""No blanks remaining triggers a win"""
print("\nAye, mate, you guessed correctly!")
print(parrot)
print("\nNow give {} a cracker and live for another day!".format(parrot_name))
else:
"""Loop ends because attempts reached 0"""
time.sleep(3)
print(parrot)
print("\n{} the parrot wins!".format(parrot_name))
game_play(plank)
def play_again():
print("\nWould you like to play again? [A]ye or [N]ay]\n")
continue_game = input("> ").lower()
if continue_game == "a":
game_play(plank)
elif continue_game == "n":
print("Goodbye!")
else:
print("what was that, mate? [A]ye or [N]ay?")
play_again()