-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex43.py
More file actions
101 lines (69 loc) · 2.79 KB
/
ex43.py
File metadata and controls
101 lines (69 loc) · 2.79 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
import random
class Scene(object):
def enter(self):
pass
class Engine(object):
def __init__(self, scene_map):
self.map = scene_map
def play(self):
while True:
self.map.opening_scene()
class Death(Scene):
def enter(self):
print("You are dead.")
exit(0)
class CentralCorridor(Scene):
def enter(self):
print("You are in an endless corridor. It gleams and sparkles like it was just washed this morning. In fact, it WAS just washed this morning.")
joke = input("A Gothon is guarding the way. Tell it a joke to defeat it: ")
if joke.strip() == "":
print("That wasn't much of a joke. The Gothon scowls and shoots you dead.")
return 'death'
else:
return 'laser_weapon_armory'
class LaserWeaponArmory(Scene):
def enter(self):
print("Racks upon racks of heavy weaponry are laid out before you.")
print("A keypad seals the entrace to the neutron bomb. You have 10 guesses to find out what the correct key value [1 to 100] is.")
ans = random.randint(1, 100)
for i in range(10):
guess = input()
if not guess.isdigit():
print("Wow, you just wasted one chance. Try a number next time alright?")
continue
guess = int(guess)
if guess == ans:
print("The door unlocks itself with a satisfying *CLICK*")
return 'the_bridge'
elif guess > ans:
print("Try lower.")
else:
print("Try higher.")
print("You've wasted your chances and the guards have arrived. Time to die.")
return 'death'
class TheBridge(Scene):
def enter(self):
print("Main screen turn on. A man is saying something about \"zigs\".")
input("Plant the bomb? [RETURN]")
return 'escape_pod'
class EscapePod(Scene):
def enter(self):
print("You fasten the safety harness and pray that you survive your landing.")
pod = input("There are two escape pods; one on the left and one on the right. Which do you take? ")
if 'left' in pod:
return 'death'
else:
print("You escaped successfully!")
exit(0)
class Map(object):
def __init__(self, start_scene):
self.scenes = {'central_corridor': CentralCorridor(), 'laser_weapon_armory': LaserWeaponArmory(), 'the_bridge': TheBridge(), 'escape_pod': EscapePod(), 'death': Death()}
self.scene = self.scenes[start_scene]
self.started = False
def next_scene(self, scene_name):
self.scene = self.scenes[scene_name]
def opening_scene(self):
self.next_scene(self.scene.enter())
a_map = Map('central_corridor')
a_game = Engine(a_map)
a_game.play()