-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyMiniCommandGame.py
More file actions
203 lines (163 loc) · 5.52 KB
/
MyMiniCommandGame.py
File metadata and controls
203 lines (163 loc) · 5.52 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
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
from sys import exit
from random import randint
from textwrap import dedent
class Engine(object):
def __init__(self, scene_map):
self.scene_map = scene_map
def play(self):
current_scene = self.scene_map.opening_scene()
last_scene = self.scene_map.next_scene('finished')
while current_scene != last_scene:
next_scene_name = current_scene.enter()
current_scene = self.scene_map.next_scene(next_scene_name)
#printing out last scene
current_scene.enter()
class Scene(object):
def enter(self):
print("aint ready yet")
exit(1)
class Death(Scene):
quips = [
"You died. You kinda suck.",
"Do you even care?",
"Please use your useless brain",
"You dead..."
]
def enter(self):
print(Death.quips[randint(0, len(self.quips)-1)])
exit(0)
class MainRoom(Scene):
def enter(self):
print(dedent("""
Welcome to the darkness...
Here we tell you what to do!
if you have a problem, you have to find a way to escape
Now get back to work.\n
You have 3 options: work, escape, run
"""))
action = input("> ")
if action == 'run':
print(dedent("""
They killed you.
"""))
return 'death'
elif action == 'work':
print(dedent("""
You work for yor rest of your life there.
Bye.
"""))
return 'death'
elif action == 'escape':
print(dedent("""
Okay i will help you.
"""))
return 'laser_weapon_armory'
else:
print("\nNOT SUCH ACTION")
return 'main_room'
class LaserWeaponArmory(Scene):
def enter(self):
print(dedent("""
Good...
I am your imaginary guide.
I will help you to get out from here alive.
But you have to fight!
\n
You found a door who lead to the exit, but its locked.
Open it.
(3 digits)
"""))
code = f"{randint(1,9)}{randint(1,9)}{randint(1,9)}"
guess = input("[keypad]> ")
guesses = 0
while guess != code and guesses < 10:
print("Nope...Try again")
guesses += 1
guess = input("[keypad]> ")
print(f"The code is: {code}")
if guess == code:
print(dedent("""
Good!
You did open the door
"""))
return 'the_bridge'
else:
print(dedent("""
You failed to open the door and a hellboy found you
"""))
return 'death'
class TheBridge(Scene):
def enter(self):
print(dedent("""
Once you opened the door someone attacked you!
But with your ninja skills,
You grabbed his gun.
Do something......
"""))
action = input("> ")
if action == "run":
print(dedent("""
You tried to run,
Unfortunately he killed you with his knife.
"""))
return 'death'
elif action == "shoot":
print(dedent("""
You killed the hellboy!
Good.
That was a close one.
"""))
return 'escape_pod'
else:
print("Nope...Try again")
return 'the_bridge'
class EscapePod(Scene):
def enter(self):
print(dedent("""
WOW! You made it!
You reached the parking lot.
There are 5 spaceships.
One of them works.
Pick one and go!
Before any hellboys find you!
Be careful, ONLY ONE WORKS!
"""))
good_pod = randint(1,5)
guess = input("[pod #]> ")
if int(guess) != good_pod:
print(dedent("""
You picked a bad spaceship.
You failed to reach back to earth.
"""))
return 'death'
else:
print(dedent("""
Great job!
Fortune is with you!
You picked the working spaceship!
Congratulations!
"""))
return 'finished'
class Finished(Scene):
def enter(self):
print("You made it back alive!\n")
return 'finished'
class Map(object):
scenes = {
'main_room': MainRoom(),
'laser_weapon_armory': LaserWeaponArmory(),
'the_bridge': TheBridge(),
'escape_pod': EscapePod(),
'death': Death(),
'finished': Finished(),
}
def __init__(self, start_scene):
self.start_scene = start_scene
def next_scene(self, scene_name):
val = Map.scenes.get(scene_name)
return val
def opening_scene(self):
return self.next_scene(self.start_scene)
a_map = Map('main_room')
a_game = Engine(a_map)
a_game.play()