-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
366 lines (307 loc) · 11.5 KB
/
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
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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
'''
7 Days - The Game - Example Code
Text-based game where the user must survive their first 7 days on a foreign planet.
'''
import os
import random
import time # add delay between events
# local imports
from cprint import cprint
from title import display_title_screen
import art
def display_day01():
'''
Display day 01 in story
'''
clear_screen()
# Spaceship ASCII art
# Add animation "effect" using
# decreasing image width - see art.py file
cprint(art.ASCII_SPACESHIP_01, fg='g')
time.sleep(0.5)
clear_screen()
cprint(art.ASCII_SPACESHIP_02, fg='g')
time.sleep(0.5)
clear_screen()
cprint(art.ASCII_SPACESHIP_01, fg='g')
time.sleep(0.5)
clear_screen()
cprint(art.ASCII_SPACESHIP_02, fg='g')
time.sleep(0.5)
clear_screen()
cprint(art.ASCII_SPACESHIP_03, fg='g')
time.sleep(2)
clear_screen()
# Blue text
cprint("DAY 1", fg='b')
cprint("===============", fg='b')
# create random delay between 1 and 2 seconds
time.sleep(random.randrange(1, 2))
print("")
print("You wake up.")
time.sleep(random.randrange(1, 2))
print("Looking down at your watch, you notice that it's 8 AM. ⏰")
print("...")
time.sleep(random.randrange(1, 2))
print("You are not sure where you are, 🗺")
print("but you begin to remember a crash landing in your space vehicle,")
print("")
time.sleep(random.randrange(1, 2))
print("🚀")
time.sleep(random.randrange(1, 2))
print("🌠")
time.sleep(random.randrange(1, 2))
print("🔥 🔥 🔥")
time.sleep(random.randrange(1, 2))
print("")
print("which you now see approximately 20 feet behind you.")
time.sleep(random.randrange(1, 2))
# Get main character name (still day 01)
# Add color: Yellow text for user input
cprint("\nWhat was your name again?: ", fg='y')
name = input()
# Use str.title method to capitalize first letter of user name
print("\nWell,", name.title(), ", you tell yourself...")
print("It's time to figure out what's going on.")
time.sleep(random.randrange(1, 2))
# Give the user a decision to make. Depending on their answer,
# the game either ends here or they continue on to day 2
question = '''\nWould you like to
[1] Go back to the spaceship to repair it 🛠 or
[2] go explore the forest? 🌲 🌲 🌲
\nType 1 or 2 and press ENTER to continue:\
'''
# Yellow text
cprint(question, fg='y')
answer = input()
print("\n>> Your answer was: ", answer, "<<\n")
if answer == "1":
# Player is going back to the spaceship.. bad choice
game_over_because("Your choice to go back to the spaceship was ultimately the wrong one.")
else:
# Player moves on to day 02
display_day02()
def display_day02():
'''
Display day 02 in the story.
'''
clear_screen()
# Blue text
cprint("DAY 2", fg='b')
cprint("===============", fg='b')
# create random delay between 1 and 2 seconds
time.sleep(random.randrange(1, 2))
print("")
print("Forget the space ship! 🚀 ... ")
time.sleep(random.randrange(1, 2))
print("")
print("It's time that I live a little! 🎉")
print("Let's see what this forest has to offer.")
time.sleep(random.randrange(2, 3))
print("...")
print("")
print("As you stumble along in the forest, you come across a pizza! 🍕")
time.sleep(random.randrange(2, 3))
print("...")
print("")
print("Wait a minute ... thinking outloud, you realize ...")
time.sleep(random.randrange(1, 2))
print("...")
print("")
time.sleep(random.randrange(1, 2))
print("I am super hungry, but this seems too good to be true!")
print("You have a decision to make:")
time.sleep(random.randrange(2, 3))
# Give the user a decision to make. Depending on their answer,
# the game either ends here or they continue on to day 3
question = '''\nWould you like to
[1] Eat the pizza. You're the master of danger! 🍕 + 🌳 = ❓
[2] Try your hand at fishing instead 🐟 🐟 🐟
\nType 1 or 2 and press ENTER to continue:\
'''
# Yellow text
cprint(question, fg='y')
answer = input()
print("\n>> Your answer was: ", answer, "<<\n")
if answer == "1":
# Player decides to eat the forest pizza (gross!)
game_over_because("\nYour choice to eat a random pizza that you found on the forest floor was a poor one. \nYou must suffer the consequences!\n")
else:
# Player moves on to day 02
display_day03()
def display_day03():
'''
Display day 03 in the story.
'''
clear_screen()
# Blue text
cprint("DAY 3", fg='b')
cprint("===============", fg='b')
# create random delay between 1 and 2 seconds
time.sleep(random.randrange(1, 2))
print("")
print("You continue on walking through the forest. 🌲 🌲 🌲")
time.sleep(random.randrange(1, 2))
print("")
print("Your mission is to find a stick so that you can make a fishing pole and finally eat! 🎣")
time.sleep(random.randrange(2, 3))
print("")
print("You manage to find 🔍 a stick and put together a simple, although functional fishing pole. 😎")
time.sleep(random.randrange(3, 4))
print("")
print("Luckily 🍀 you also come across a small lake")
time.sleep(random.randrange(1, 2))
print("")
print("Now, about to faint due to lack of food, you sit down and begin fishing.")
print("")
time.sleep(random.randrange(2, 3))
# Sun / lake with fish
# sun copied from wego project https://github.com/schachmat/wego/blob/master/frontends/ascii-art-table.go
# Note: the blinking text doesn't work on repl.it
cprint(" \\ / ", fg='y')
cprint(" .-. ", fg='y')
cprint(" ‒ ( ) ‒ ", fg='y')
cprint(" `-᾿ ", fg='y')
cprint(" / \\ ", fg='y')
cprint(" ")
cprint(r"\🐟/\ /\ /\🐟/\ /\ /\🐟/\ /\ /", fg='b', style='x')
cprint(r" \/ \/🐟\/ \/ \/🐟\/ \/ \/🐟\/ ", fg='b', style='x')
time.sleep(4)
clear_screen()
# stop the blinking to avoid rage quit
cprint(" \\ / ", fg='y')
cprint(" .-. ", fg='y')
cprint(" ‒ ( ) ‒ ", fg='y')
cprint(" `-᾿ ", fg='y')
cprint(" / \\ ", fg='y')
cprint(" ")
cprint(r"\🐟/\ /\ /\🐟/\ /\ /\🐟/\ /\ /", fg='b')
cprint(r" \/ \/🐟\/ \/ \/🐟\/ \/ \/🐟\/ ", fg='b')
print("")
print("After waiting about 10 minutes 🕑 you feel a tug on the line.")
time.sleep(random.randrange(2, 3))
print("You caught a fish! Good job. 🏆")
time.sleep(random.randrange(2, 3))
print("")
print("You cook the fish over a fire and feel satisfied. 🔥 🐟")
time.sleep(random.randrange(2, 3))
print("It's now almost night time. The sun begins to disappear into the horizon. 🌇")
time.sleep(random.randrange(2, 3))
print("")
print("You have a decision to make:")
time.sleep(random.randrange(1, 2))
# Give the user a decision to make. Depending on their answer,
# the game either ends here or they continue on to day 4
question = '''\nWould you like to
[1] Sleep on the lake shore under the stars. 🌃 ⛺
[2] Go to the cave you see in the distance. That looks like a warm place to stay for the night. 👻
\nType 1 or 2 and press ENTER to continue:\
'''
# Yellow text
cprint(question, fg='y')
answer = input()
print("\n>> Your answer was: ", answer, "<<\n")
if answer == "1":
# Player decides to sleep on the lake shore and moves on to day 4.
display_day04()
else:
# Player decides to go to the cave
game_over_because("\nYour choice to sleep in a cave was not a wise one. You found a bear, and the bear found dinner. 🐻 \n")
def display_day04():
'''
Display day 04 in the story.
'''
clear_screen()
# Blue text
cprint("DAY 4", fg='b')
cprint("===============", fg='b')
# create random delay between 1 and 2 seconds
time.sleep(random.randrange(1, 2))
print("")
print("You wake up on day 4 and continue on your journey. 🌅")
time.sleep(random.randrange(1, 2))
print("")
print("What a nice morning! The sun is bright, the air is clean, the ...")
time.sleep(random.randrange(1, 2))
print("")
print("Cell phone is ringing? ♬ ♫ ♪ ♪")
time.sleep(random.randrange(3, 4))
print("")
print("""As your gaze lowers to the forest 🌳 floor, you see a phone screen lit up and ringing with the
most annoying ring tone you've ever heard 📱 ❗-- {insert your favorite song here}
""")
print("")
print("You have a decision to make:")
time.sleep(random.randrange(1, 2))
# Give the user a decision to make. Depending on their answer,
# the game either ends here or they continue on to day 5
question = '''\nWould you like to
[1] Answer the cell phone - it would be rude not to! 🖁
[2] Keep walking - it's really none of your business anyways. 👞 🏔
\nType 1 or 2 and press ENTER to continue:\
'''
# Yellow text
cprint(question, fg='y')
answer = input()
print("\n>> Your answer was: ", answer, "<<\n")
if answer == "1":
# Player decides to answer the cell phone
game_over_because("\nYour choice to answer the cell phone was the wrong one. As you pick up the phone, you aren't paying attention to your surroundings. A majestic bald eagle swoops down and carries you away. 📵 🦅\n")
else:
# Player decides to go to the cave
game_over_because("\nYour choice to sleep in a cave was not a wise one. You found a bear, and the bear found dinner. 🐻 \n")
def display_day05():
'''
Display day 05 in the story.
'''
clear_screen()
# Blue text
cprint("DAY 5", fg='b')
cprint("===============", fg='b')
# create random delay between 1 and 2 seconds
time.sleep(random.randrange(1, 2))
##############
# Run the game
# Add helper/utility functions
##############################
def ask_play_again():
'''
Offer to play game again.
'''
print("")
question = "Play again? (Y/N): "
cprint(question, fg='g', bg='k')
answer = input()
if answer.upper() == "Y":
start_game()
else:
print("Thank you for playing!")
def clear_screen():
'''
Clear the terminal screen.
'''
os.system('clear')
def game_over_because(reason):
'''
Display game over screen.
'''
cprint("\nGAME OVER\n===============\n" + reason + "\nBetter luck next time!", fg='r')
# Ask if the user wants to play again
ask_play_again()
def start_game(day=1):
'''
Main function. This runs when the game is started or
the player chooses to replay (after game over)
Default start day is 1, but can be changed by day= parameter. This is helpful
when testing days further into the game so that you don't have to wait to
get to the day you're working on.
'''
clear_screen()
display_title_screen()
if day == 1:
display_day01()
else:
day_string = 'display_day0' + str(day)
globals()[day_string]() # start_game(day=2) -> display_day02
# Main loop
start_game(day=1)