-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathex45.py
More file actions
219 lines (164 loc) · 6.28 KB
/
ex45.py
File metadata and controls
219 lines (164 loc) · 6.28 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
from sys import exit
from textwrap import dedent
from os import system, name
# define clear function
def screen_clear():
if name == 'nt':
_ = system('cls')
# for mac and linux(here, os.name is 'posix')
else:
_ = system('clear')
class Scene(object):
def next(self):
pass
class Engine(object):
def __init__(self, battle, phase):
self.battle = battle
self.phase = phase
def play(self):
current_scene = self.battle.opening_scene()
last_scene = self.battle.play_scene('finished')
while current_scene != last_scene:
# self.battle.play_scene('look')
next_scene_name = current_scene.start()
current_scene = self.battle.play_scene(next_scene_name)
current_scene.start()
class Tools(object):
avaiable = ['Rock', 'Pitchfork', 'Bomb', 'Double Ax', 'Sunglasses']
inventory = []
class Phase(object):
def __init__(self, phase, battle):
self.phase = phase
self.battle = battle
def get_phase(self):
return self.phase
def next_phase(self):
self.phase += 1
if(self.phase == 1):
self.battle.play_scene('phase1')
elif(self.phase == 2):
self.battle.play_scene('phase2')
elif(self.phase == 3):
self.battle.play_scene('phase3')
class Opening(Scene):
def start(self):
print(dedent("""
You are in a beautiful garden, with vine covered cobblestone walls, a small waterfall trickling down a rock face,
and right in front of you, an empty plot of tilled land.
That is, empty except for a single red flower, in the very center of the plot of land.
You see a watering can to your right, under a large fern. Will you be kind and water the flower?"""))
what = input("> ")
if what.lower() == 'yes':
return 'phase1'
class Phase1(Scene):
def start(self):
screen_clear()
print(dedent("""
Out of the watering can emerges clear, pure water, sparkling in the midday sun. It runs down the flower's leaves and covers it's crimson petals.
...Then the flower starts to shake.
It vibrates mysteriously, becoming faster and faster untill...
The ground around you explodes with a collosal force, sending you backwards several feet, landing on your rump.
In front of you emerges the giant face of a dragon, with a viny, leaf-covered neck that emerges from the ground like a worm."""))
return 'look'
class Look(Scene):
def start(self):
print(dedent(""" You look around... you see: """))
for i in a_tools.avaiable:
print(dedent('* ' + i))
print("What do you do?")
take = input("> ")
words = take.split()
print(words[0])
if words[0].lower() == "use":
if words[1].lower() == "rock" and "Rock" in a_tools.inventory:
return 'useRock'
if words[1].lower() == "pitchfork" and "Pitchfork" in a_tools.inventory:
return 'usePitch'
if words[1].lower() == "bomb" and "Bomb" in a_tools.inventory:
return 'useBomb'
if words[1].lower() == "ax" and "Double Ax" in a_tools.inventory:
return 'useAx'
if words[1].lower() == "sunglasses" and "Sunglasses" in a_tools.inventory:
return 'useSun'
if words[0].lower() == "take":
for x in a_tools.avaiable:
if x in take:
a_tools.inventory.append(x)
a_tools.avaiable.remove(x)
print(a_tools.inventory)
print(a_tools.avaiable)
return 'look'
class Phase2(Scene):
def start(self):
pass
class Phase3(Scene):
def start(self):
pass
class Death(Scene):
def start(self):
print(dedent(""" Sorry, guy. You're are pretty bad if you knows what im sayingg """))
exit(1)
class UseRock(Scene):
def start(self):
print(dedent(""" You threw the rock. That didn't do much. """))
return 'look'
class UsePitch(Scene):
def start(self):
print(dedent("""
You threw the pitchfork like a javelin, but the dragon fires a great ball of fire, melting the fork and
killing you. """))
return 'death'
class UseBomb(Scene):
def start(self):
if a_battle.phase_num == 1:
print(dedent(""" Your bad. """))
return 'look'
elif a_battle.phase_num == 2:
print(dedent(""" Your good! """))
return 'finished'
class UseAx(Scene):
def start(self):
print(dedent(""" You swung the axe with all your might at the base of the dragon's viny neck. It sticks there as the dragon lifts up his head in a mighty roar. """))
a_battle.next_phase()
print(dedent(""" It's hurt! what will you do to finish it off? """))
return 'look'
class UseSunglasses(Scene):
def start(self):
print(dedent(""" You look cool. So cool, your DEFENSE increased! """))
return 'look'
class Finished(Scene):
def start(self):
print(dedent("""
You threw the bomb into the dragon's gaping maw. A couple seconds later, a muffled BOOM eminates from the dragon's jaw, along with a great
amount of black smoke...
When the smoke clears, the garden is covered in flowers."""))
class Battle(object):
phase_num = 1
scenes = {
'look' : Look(),
'opening' : Opening(),
'phase1' : Phase1(),
'phase2' : Phase2(),
'phase3' : Phase3(),
'useRock' : UseRock(),
'usePitch': UsePitch(),
'useBomb' : UseBomb(),
'useAx': UseAx(),
'useSun' : UseSunglasses(),
'death' : Death(),
'finished' : Finished()
}
def __init__(self, start_scene):
self.start_scene = start_scene
def play_scene(self, scene_name):
val = Battle.scenes.get(scene_name)
return val
def opening_scene(self):
return self.play_scene(self.start_scene)
def next_phase(self):
self.phase_num += 1
a_tools = Tools()
a_battle = Battle("opening")
a_phase = Phase(0, a_battle)
a_game = Engine(a_battle, a_phase)
a_game.play()