generated from Code-Institute-Org/python-essentials-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.py
235 lines (205 loc) · 6.66 KB
/
run.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
# import random
from random import randint
# import os module
import os
# import pyfiglet module
import pyfiglet
def clear():
"""
Function for clearing terminal.
"""
input('''\n\n--------------------------
\nPress Enter To Continue...
\n--------------------------''')
os.system("cls" if os.name == "nt" else "clear")
def start_game():
"""
This function is called when the player is
at start of game and includes Intro.
"""
shotgun = False
gun = False
score = 0
welcome = pyfiglet.figlet_format("Walkers", justify="center")
print(welcome)
print("Zombie Apocalypse Text Adventure Game".center(80) + "\n")
print("Created by Miriam Payne".center(80) + "\n")
name = input("Please confirm your name:\n")
while True:
try:
age = int(input("Please confirm your age:\n"))
break
except ValueError:
print("That's not a number!")
if age > 0 and age < 12:
print("You're young ... chances of survival are slim ... ")
elif age >= 12 and age < 75:
print("I hope you're a good shot")
elif age >= 75:
print("You're as slow as the walkers ... chances are slim")
clear()
print("Mission: Survive or die trying")
print("Chapter 1")
clear()
print("You walk into an abandoned Dublin city center tower block car park")
clear()
print("Outbreak has turned 95% the population into zombies aka walkers")
clear()
print("Your sat nav shows you are 8 miles from a safe haven")
clear()
print("A zombie horde appears... you grab your hurley from your backpack")
print("")
score = stage_one(age)
score, shotgun = stage_two(score)
score = stage_three(score, shotgun)
return score
def win(score):
"""
This function is
called when the player wins!
"""
winner = pyfiglet.figlet_format("WINNER", font="digital")
loser = pyfiglet.figlet_format("LOSER", font="digital")
if score >= 5:
print(winner)
else:
print(loser)
def retry_game():
"""
This function is called when the player is
offered a retry of the game.
"""
print("Would you like to go again? Reply (Y)ES or (N)O")
answer = input("").upper().strip()
while answer not in ["YES", "NO", "Y", "N"]:
print("Invalid input. Please try again.")
answer = input("").upper().strip()
if answer in ["YES", "Y"]:
print("Great! lets go again.")
start_game()
elif answer in ["NO", "N"]:
print("See you again next time!")
def stage_one(age):
"""
This function is called
for user input to stay and fight
or to run and hide, score depends on age.
"""
action = input("(F)ight or (R)un? ").upper()
while action not in ["FIGHT", "RUN", "F", "R"]:
clear()
print("\nThat is not a valid action")
action = input("Fight or Run?\n").upper()
if action == "FIGHT" or action == 'F':
if age >= 12:
print("\nYour youthfulness helps you avoid being chomped")
clear()
print("You made it this time")
score = 2
else:
print("\nYou attack")
clear()
print("Combo of old age and slowness cause you to be bitten")
clear()
print("You're too old to be fighting zombies")
score = 1
elif action == "RUN" or action == 'R':
if age <= 12:
print("\nYou run from the zombie, but are too slow")
clear()
print("This walker has some agility and catches up quick")
score = 1
else:
print("\nYou run from the zombie")
clear()
print("Your athletic legs carry you to safety")
score = 2
return score
def stage_two(score):
"""
This function is only called
if you have survived with a score of 2 now.
"""
if score == 2:
shotgun = False
clear()
print("Chapter 2")
clear()
print("You come across an old abandoned house, barn and store")
choice = input("\nEnter (H)ouse, (B)arn or (S)tore? ").upper()
while choice not in ["HOUSE", "BARN", "STORE", "H", "B", "S"]:
print("Sorry. I don't understand, please try again!")
choice = input("Enter house or barn or store?\n").upper()
if choice in ["HOUSE", "H"]:
print("\nYou enter the house, rummaging around ... ")
clear()
print("You find a shot gun and three shot gun shells")
clear()
shotgun = True
score = 3
elif choice in ["STORE", "S"]:
print("\nYou enter the store, rummaging around ... ")
clear()
print("You stock up on supplies and find a gun with 4 bullets")
clear()
gun = True
score = 3
elif choice in ["BARN", "B"]:
print("\nYou enter the barn where you could hear odd noises ... ")
clear()
print("You encounter a mob of zombies")
clear()
print("You didn't survive")
else:
print("\nYou enter the store and slip going down the escalater ")
clear()
print("You fall to your death")
clear()
print("You didn't survive")
return (score, shotgun)
def stage_three(score, shotgun):
"""
This function is only called
if you have survived with a score of 3 now.
"""
if score == 3:
print("Chapter 3")
clear()
print("You make it to the perimeter of the safe haven")
clear()
print("Only one problem ... ")
clear()
print("Two Zombies")
clear()
if shotgun:
print("You have three shots to hit two targets")
shots = 3
else:
print("You have four shots to hit two targets")
shots = 4
zombies = 2
while shots > 0 and zombies > 0:
hit = randint(1, 3)
if hit in [1, 2]:
clear()
print("A lucky shot, you killed a zombie")
shots = shots - 1
zombies = zombies - 1
else:
clear()
print("You fire a shot, but miss")
shots = shots - 1
clear()
if zombies == 0:
print("You made it!\n")
score = 5
else:
print("You fired all shots and the zombies are enclosing!\n")
score = 4
return score
# Step 0: Call main menu procedure
if __name__ == '__main__':
while True:
win(start_game())
if not retry_game():
exit(1)