-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathspace_game.py
More file actions
170 lines (141 loc) · 5.2 KB
/
space_game.py
File metadata and controls
170 lines (141 loc) · 5.2 KB
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
"""
Space Travel Game
A simple text adventure written for a refactoring tutorial.
"""
TEXT = {
"OPENING_MESSAGE": """
-------------------------------------------------------------------------------
You and your trusted spaceship set out to look for
fame, wisdom, and adventure. The stars are waiting for you.
""",
"EARTH_DESCRIPTION": "\nYou are on Earth. Beautiful is better than ugly.",
"CENTAURI_DESCRIPTION": "\nYou are on Alpha Centauri. All creatures are welcome here.",
"HYPERDRIVE_SHOPPING_QUESTION": """There is a brand new hyperdrive with a built-in GPU for sale.
Would you like to buy one [yes/no]""",
"HYPERDRIVE_TOO_EXPENSIVE": """
You cannot afford it. The GPU is too expensive.""",
"SIRIUS_DESCRIPTION": """
You are on Sirius. The system is full of media companies and content delivery networks.""",
"SIRIUS_QUIZ_QUESTION": """You manage to get a place in *Stellar* - the greatest quiz show in the universe.
Here is your question:
Which star do you find on the shoulder of Orion?
[1] Altair
[2] Betelgeuse
[3] Aldebaran
[4] Andromeda
""",
"SIRIUS_QUIZ_CORRECT": """
*Correct!!!* You win a ton or credits.
""",
"SIRIUS_QUIZ_INCORRECT": """
Sorry, this was the wrong answer. Don't take it too sirius.
Better luck next time.
""",
"ORION_DESCRIPTION": """
You are on Orion. An icy world inhabited by furry sentients.""",
"ORION_HIRE_COPILOT_QUESTION": """A tech-savvy native admires your spaceship.
They promise to join as a copilot if you can answer a question:
What is the answer to question of life, the universe and everything?
What do you answer?""",
"COPILOT_QUESTION_CORRECT": """
Your new copilot jumps on board and immediately starts
configuring new docker containers.
""",
"COPILOT_QUESTION_INCORRECT": """
Sorry, that's not it. Try again later.
""",
"BLACK_HOLE_DESCRIPTION": """
You are close to Black Hole #0997. Maybe coming here was a really stupid idea.
Do you want to examine the black hole closer? [yes/no]
""",
"BLACK_HOLE_CRUNCHED": """
The black hole condenses your spaceship into a grain of dust.
THE END
""",
"BLACK_HOLE_COPILOT_SAVES_YOU": """
On the rim of the black hole your copilot blurts out:
Turn left!
You ignite the next-gen hyperdrive, creating a time-space anomaly.
You travel through other dimensions and experience wonders beyond description.
""",
"END_CREDITS": """
THE END
""",
}
def travel():
print(TEXT["OPENING_MESSAGE"])
planet = "earth"
engines = False
copilot = False
credits = False
game_end = False
while not game_end:
# display inventory
print("-" * 79)
inventory = "\nYou have: "
inventory += "plenty of credits, " if credits else ""
inventory += "a hyperdrive, " if engines else ""
inventory += "a skilled copilot, " if copilot else ""
if inventory.endswith(", "):
print(inventory.strip(", "))
#
# interaction with planets
#
if planet == "earth":
destinations = ["centauri", "sirius"]
print(TEXT["EARTH_DESCRIPTION"])
if planet == "centauri":
print(TEXT["CENTAURI_DESCRIPTION"])
destinations = ["earth", "orion"]
if not engines:
print(TEXT["HYPERDRIVE_SHOPPING_QUESTION"])
if input() == "yes":
if credits:
engines = True
else:
print(TEXT["HYPERDRIVE_TOO_EXPENSIVE"])
if planet == "sirius":
print(TEXT["SIRIUS_DESCRIPTION"])
destinations = ["orion", "earth", "black_hole"]
if not credits:
print(TEXT["SIRIUS_QUIZ_QUESTION"])
answer = input()
if answer == "2":
print(TEXT["SIRIUS_QUIZ_CORRECT"])
credits = True
else:
print(TEXT["SIRIUS_QUIZ_INCORRECT"])
if planet == "orion":
destinations = ["centauri", "sirius"]
if not copilot:
print(TEXT["ORION_DESCRIPTION"])
print(TEXT["ORION_HIRE_COPILOT_QUESTION"])
if input() == "42":
print(TEXT["COPILOT_QUESTION_CORRECT"])
copilot = True
else:
print(TEXT["COPILOT_QUESTION_INCORRECT"])
else:
print(TEXT["ORION_DESCRIPTION"])
if planet == "black_hole":
print(TEXT["BLACK_HOLE_DESCRIPTION"])
destinations = ["sirius"]
if input() == "yes":
if engines and copilot:
print(TEXT["BLACK_HOLE_COPILOT_SAVES_YOU"])
game_end = True
else:
print(TEXT["BLACK_HOLE_CRUNCHED"])
return
if not game_end:
# select next planet
print("\nWhere do you want to travel?")
position = 1
for d in destinations:
print(f"[{position}] {d}")
position += 1
choice = input()
planet = destinations[int(choice) - 1]
print(TEXT["END_CREDITS"])
if __name__ == "__main__":
travel()