-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathex43.py
154 lines (112 loc) · 4.72 KB
/
ex43.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
from sys import exit
from random import randint
class Scene(object):
def enter(self):
print("This scene is not yet configured. Subclass it and implement enter().")
exit(1)
class Engine(object):
def __init__(self, scene_map):
self.scene_map = scene_map
def play(self):
current_scene = self.scene_map.opening_scene()
while True:
print("\n--------")
next_scene_name = current_scene.enter()
current_scene = self.scene_map.next_scene(next_scene_name)
class Death(Scene):
quips = [
"You died. You kinda suck at this.",
"Your mom would be proud... if she were smarter",
"Such a luser.",
"I have a small puppy that's better at this."
]
def enter(self):
print(Death.quips[readint(0, len(self.quips)-1)])
exit(1)
class CentralCorridor(Scene):
def enter(self):
print("The Gothons of Planet Percal #25 have invaded your ship and destroyed")
print("your entire crew. You are the last surviving member and your last")
print("mission is to get the neutron destruct bomb from the Weapons Armory,")
print("put it in the bridge, and blow the ship up after getting into an ")
print("escape pod.")
print("\n")
print("You're running down the central corridor to the Weapons Armory when")
print("a Gothon jumps out, red scaly skin, dark grimy teeth, and evil clown costume")
print("flowing around his hate filled body. He's blocking the door to the")
print("Armory and about to pull a weapon to blast you.")
action = input("> ")
if action == "shoot!":
print("Quick on the draw you yank out your blaster and fire it at the Gothon.")
print("His clown costume is flowing and moving around his body, which throws")
print("off your aim. Your laser hits his costume but misses him entirely. This")
print("completely ruins his brand new costume his mother bought him, which")
print("makes him fly into a rage and blast you repeatedly in the face until")
print("you are dead. Then he eats you.")
return 'death'
elif action == "dodge!":
print("Like a world class boxer you dodge, weave, slip and slide right")
return 'death'
elif action == "tell a joke":
print("Lucky for you they made you learn Gothon insults in the academy.")
return 'laser_weapon_armory'
else:
print("DOES NOT COMPUTE!")
return 'central_corridor'
class LaserWeaponArmory(Scene):
def enter(self):
print("You do a dive roll into the Weapon Armory, crouch and scan the room")
code = "%d%d%d" % (randint(1,9), randint(1,9), randint(1,9))
guess = input("[keypad]> ")
guesses = 0
while guess !=code and guesses < 10:
guesses +=1
guess = input("[keypad]> ")
if guess == code:
print("The container clicks open and the seal breaks, letting gas out.")
return 'the_bridge'
else:
print("The lock buzzes one last time and then you hear a sickening")
return 'death'
class TheBridge(Scene):
def enter(self):
print("You burst onto the Bridge with the neutron destruct bomb")
action = input("> ")
if action == "throw the bomb":
print("In a panic you throw the bomb at the group of Gothons")
return 'death'
elif action == "slowly place the bomb":
print("You point your blaster at the bomb under your arm")
return 'escape_pod'
else:
print("DOES NOT COMPUTE!")
return "the_bridge"
class EscapePod(Scene):
def enter(self):
print("You rush through the ship desperately trying to make it to")
good_pod = randint(1,5)
guess = input("[pod #1]> ")
if int(guess) != good_pod:
print("You jump into pod %s and hit the eject button." % guess)
return 'death'
else:
print("You jump into pod %s and hit the eject button." % guess)
print("You won!")
return 'finished'
class Map(object):
scenes = {
'central_corridor': CentralCorridor(),
'laser_weapon_armory': LaserWeaponArmory(),
'the_bridge': TheBridge(),
'escape_pod': EscapePod(),
'death': Death()
}
def __init__(self, start_scene):
self.start_scene = start_scene
def next_scene(self, scene_name):
return Map.scenes.get(scene_name)
def opening_scene(self):
return self.next_scene(self.start_scene)
a_map = Map('central_corridor')
a_game = Engine(a_map)
a_game.play()