-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
222 lines (168 loc) · 6.47 KB
/
app.py
File metadata and controls
222 lines (168 loc) · 6.47 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
220
221
222
# Python For All, east-coast-group
# name = Garden-Game
# version = 0.1.0
# description = LPTHW Ex. 45 You Make a Game
# authors = Gillian, Grace, Haja, Lori, Natalie
# url = https://github.com/PythonForAll-east-coast-group/garden-game
from sys import exit
from random import randint
from textwrap import dedent
import weapons_tools
def print_inventory():
print("You currently have these items in your inventory:")
for item in weapons_tools.inventory:
print("- " + item.name)
print("Which item would you like to use?")
class Scene(object):
def enter(self):
print("This scene is not yet configured.")
print("Subclass it and implement enter().")
exit(1)
class Engine(object):
def __init__(self, garden_map):
self.garden_map = garden_map
pass
def play(self):
current_scene = self.garden_map.opening_scene()
last_scene = self.garden_map.next_scene('finished')
while current_scene != last_scene:
next_scene_name = current_scene.enter()
current_scene = self.garden_map.next_scene(next_scene_name)
current_scene.enter()
class DestroyedGarden(Scene):
quips = [
"Your garden is destroyed. The animals are formidable foes!",
"Maybe you should take up dirt farming.",
"Raking is not your strength.",
"Maybe some garden gnomes would help.",
"Better luck next season!",
]
def enter(self):
print(DestroyedGarden.quips[randint(0, len(self.quips) - 1)])
exit(1)
class HerbGarden(Scene):
def enter(self):
print(dedent("""
You enter a lovely herb garden bristling with life.
You can smell rosemary, lavender, and cilantro.
Faintly you can smell roses and strawberries, somewhere a bit away from here.
What would you like to do?
"""))
print_inventory()
answer = input("> ")
if 'rake' in answer:
print("You rake and tear up all the herbs. Why would you do such a thing?!")
return 'destroyed_garden'
elif 'spray bottle' in answer:
print(
"You use the spray bottle to give the herbs something to drink. They sparkle in the sunglight.")
print("You head towards the scent of roses.")
return 'rose_garden'
else:
print("That's not the right tool!")
return 'herb_garden'
class RoseGarden(Scene):
def enter(self):
print(dedent("""
You enter a rose garden with lots of blooming roses.
However there are thorns everywhere on the ground,
mice running through the plants, and Japanese beetles everywhere!!
"""))
print_inventory()
answer = input("> ")
if 'stones' in answer:
print(dedent("""
You try to hit the beetles with stones and end up pelting the roses.
Who taught you how to aim?
"""))
return 'destroyed_garden'
elif 'broom' in answer:
print(dedent("""
You move all of the thorns on the ground out of the way.
Now you can leave and let the small critters duke it out.
"""))
return 'strawberry_patch'
elif 'small trap' in answer:
print(dedent("""
You catch some mice with your small trap. If you release them
away from your gardens maybe they won't come back.
"""))
return 'strawberry_patch'
elif 'water hose' in answer:
print(dedent("""
You try to force the mice out by soaking them wet.
But the power of the hose makes the roses bend and some break.
"""))
return 'destroyed_garden'
else:
print(dedent("""
That's not the right tool! Try a different one.
"""))
return 'rose_garden'
class StrawberryPatch(Scene):
def enter(self):
print(dedent("""
You enter the Strawberry Patch. Just yesterday the patch
was full of ripe berries ready for picking. Your mouth is
watering as you bend down. But wait, as you move
the large green leaves aside to look for the berries
underneath, what you see shocks you.
There are hoof prints in the dirt and no berries!
"""))
print_inventory()
answer = input("> ")
if 'rake' in answer:
print(dedent("""
You angrily rake away the hoofprints leaving nothing behind.
You fall to the ground, devastated. The deer decimated your berries.
"""))
return 'destroyed_garden'
elif 'shovel' in answer:
print(dedent("""
You use the shovel to hold up some of the giant leaves.
You see more berries than ever! You gather as
many as you can hold. It's time for some well-
deserved rest in the hammock.
"""))
return 'hammock'
else:
print("DOES NOT COMPUTE!")
return "strawberry_patch"
class Hammock(Scene):
def enter(self):
print(dedent("""
You enter a grassy field with two trees and a hammock between them.
One of the trees is a bit wobbly and you are unsure if the hammock will hold you.
"""))
print_inventory()
answer = input("> ")
if 'fence board' in answer:
print(dedent("""
You use the fence board to steady the small tree and tie your hammock.
You climb in and get ready to watch the sun set after a hard day of gardening.
"""))
return 'finished'
else:
print("Why would you use that on a hammock?")
return 'hammock'
class Finished(Scene):
def enter(self):
print("You won! Good job.")
class Map(object):
scenes = {
'destroyed_garden': DestroyedGarden(),
'hammock': Hammock(),
'herb_garden': HerbGarden(),
'rose_garden': RoseGarden(),
'strawberry_patch': StrawberryPatch(),
'finished': Finished()
}
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('herb_garden')
a_game = Engine(a_map)
a_game.play()