Skip to content

Commit 8df4139

Browse files
committed
Merged changes from working branch
2 parents 3a0fbb8 + 2431704 commit 8df4139

File tree

1 file changed

+105
-33
lines changed

1 file changed

+105
-33
lines changed

Zombie-House/main.py

Lines changed: 105 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,21 @@ def showInstructions():
2323
Protect yourself against the Poisons with a potion
2424
2525
Commands:
26-
go [direction] (Options -> north, south, east or west)
27-
get [item] (Options -> key, sword or potion)
28-
exit (Exit the game)
26+
go [direction]
27+
get [item]
28+
exit
2929
3030
''')
3131

3232
def showStatus():
3333
# print the player's current status
3434
print("---------------------------")
3535
print(f"You are in the {currentRoom}")
36+
# print the room description, if given
37+
if "description" in rooms[currentRoom]:
38+
print(f"{rooms[currentRoom]['description']}")
39+
# print your health score
40+
print(f"Health : {health}")
3641
# print the current inventory
3742
print(f"Inventory : {str(inventory)}")
3843
# print the available directions
@@ -44,12 +49,18 @@ def showStatus():
4449
if "monster" in rooms[currentRoom]:
4550
print(f"There is a {rooms[currentRoom]['monster']} in the room!")
4651
if "poison" in rooms[currentRoom]:
47-
print(f"There is some {rooms[currentRoom]['poison']} in the room!")
52+
print(f"There is some poison {rooms[currentRoom]['poison']} in the room!")
4853
print("---------------------------")
4954

50-
# An inventory, which is initially empty
55+
# Create inventory, which is initially empty
5156
inventory = []
5257

58+
# Initial health points
59+
health = 3
60+
61+
# start the player in the Hall
62+
currentRoom = 'Hall'
63+
5364
'''
5465
A dictionary is used to link a room to other rooms and
5566
define what is contained inside the room.
@@ -68,34 +79,38 @@ def showStatus():
6879
'north' : 'Atrium',
6980
'west' : 'Library'
7081
},
71-
'item' : 'key'
82+
'description' : 'The main downstairs hallway. \nYou see more rooms in every direction.'
7283
},
7384

7485
'Kitchen' : {
7586
'directions' : {
7687
'north' : 'Hall',
7788
'east' : 'Pantry'
7889
},
79-
'monster' : 'Zombie',
80-
'item' : 'flower'
90+
'monster' : 'Yellow Zombie',
91+
'item' : 'flower',
92+
'description' : 'A large, very clean kitchen. \nWhy is that flower here?'
8193
},
8294

8395
'Dining Room' : {
8496
'directions' : {
8597
'west' : 'Hall',
8698
'south' : 'Pantry',
87-
'north' : 'Bedroom'
99+
'north' : 'Guest Bedroom'
88100
},
89-
'item' : 'sword'
101+
'item' : 'sword',
102+
'description' : 'A grand dining room. There is a long, majestic \nmahagony table in the center of the room'
90103
},
91104

92105
'Atrium' : {
93106
'directions' : {
94107
'south' : 'Hall',
95108
'west' : 'Parlor',
96-
'east' : 'Bedroom',
97-
'north' : 'Garden'
98-
}
109+
'east' : 'Guest Bedroom',
110+
'north' : 'Garden',
111+
'up' : 'Upstairs Hall'
112+
},
113+
'description' : 'An atrium with a high, vaulted ceiling. \nThere are stairs leading up.'
99114
},
100115

101116
'Library' : {
@@ -104,51 +119,96 @@ def showStatus():
104119
'south' : 'Study',
105120
'north' : 'Parlor'
106121
},
107-
'item' : 'potion'
122+
'item' : 'potion',
123+
'description' : 'An impressive collection of very old books.'
108124
},
109125

110126
'Study' : {
111127
'directions' : {
112128
'north' : 'Library'
113129
},
114-
'poison' : 'hemlock'
130+
'poison' : 'hemlock',
131+
'description' : 'A quiet room with large, comfortable chairs.'
115132
},
116133

117134
'Parlor' : {
118135
'directions' : {
119136
'south' : 'Library',
120137
'east' : 'Atrium'
121138
},
122-
'monster' : 'Zombie'
139+
'monster' : 'Red Zombie',
140+
'description' : 'A nicely decorated room with a \nnumber of chairs arranged in a circle.'
123141
},
124142

125143
'Pantry' : {
126144
'directions' : {
127145
'west' : 'Kitchen',
128146
'north' : 'Dining Room'
129147
},
130-
'monster' : 'Zombie'
148+
'monster' : 'Green Zombie',
149+
'description' : 'Rows of shelves containing kitchen utensils \nand an ample supply of canned goods.'
131150
},
132151

133-
'Bedroom' : {
152+
'Guest Bedroom' : {
134153
'directions' : {
135154
'south' : 'Dining Room',
136155
'west' : 'Atrium'
137156
},
138-
'poison' : 'hemlock'
157+
'poison' : 'hemlock',
158+
'description' : 'A small, cozy bedroom with a window looking out on the Garden'
139159
},
140160

141161
'Garden' : {
142162
'directions' : {
143163
'south' : 'Atrium'
144-
}
164+
},
165+
'description' : 'A magnificent, sprawling garden with every \nimaginable type of flower, shrubbery and trees.'
166+
},
167+
168+
'Upstairs Hall' : {
169+
'directions' : {
170+
'north' : 'Master Bedroom',
171+
'down' : 'Atrium'
172+
},
173+
'description' : 'A narrow upstairs hallway leading to the Master Bedroom. \nThere are stairs leading down.'
174+
},
175+
176+
'Master Bedroom' : {
177+
'directions' : {
178+
'south' : 'Upstairs Hall',
179+
'east' : 'Bathroom',
180+
'west' : 'Office',
181+
'north' : 'Sun Room'
182+
},
183+
'description' : 'A large, luxurious bedroom with a king sized bed and canopy, \nand bedside tables with lamps on both sides.'
184+
},
185+
186+
'Office' : {
187+
'directions' : {
188+
'east' : 'Master Bedroom'
189+
},
190+
'item' : 'key',
191+
'description' : 'A small room with only a desk, chair and lamp. \nThere is a telephone on the desk.'
192+
},
193+
194+
'Bathroom' : {
195+
'directions' : {
196+
'west' : 'Master Bedroom'
197+
},
198+
'monster' : 'Purple Zombie',
199+
'description' : 'A bright, clean room with white tiled floor and \nabundant towels neatly folded on a side table.'
200+
},
201+
202+
'Sun Room' : {
203+
'directions' : {
204+
'south' : 'Master Bedroom'
205+
},
206+
'poison' : 'belladonna',
207+
'description' : 'A beautiful view of the neighboring \nwoods can be see in all directions.'
145208
}
146209

147210
}
148211

149-
# start the player in the Hall
150-
currentRoom = 'Hall'
151-
152212
showInstructions()
153213

154214
# loop forever
@@ -196,19 +256,31 @@ def showStatus():
196256
if move[0] == 'exit':
197257
break
198258

199-
# Player loses game if they enter room with Zombie without a Sword
259+
# Player loses health if they enter room with Zombie without a Sword
200260
if 'monster' in rooms[currentRoom] and 'Zombie' in rooms[currentRoom]['monster'] and 'sword' in inventory:
201-
print('You have defended yourself from the Zombie attack! ... Continue On')
261+
print('You have defended yourself from the Zombie attack! ... Fantastic!')
202262
elif 'monster' in rooms[currentRoom] and 'Zombie' in rooms[currentRoom]['monster']:
203-
print('A Zombie has eaten your brainz. You need to defend yourself ... GAME OVER!!!')
204-
break
263+
# If monster is in room, subtract a health point
264+
health -= 1
265+
if health >= 1:
266+
print("The Zombie took a bite out of you! You need to defend yourself with a sword!")
267+
else:
268+
# Game ends once health reaches zero
269+
print('A Zombie has eaten your brainz ... GAME OVER!!!')
270+
break
205271

206-
# Player loses game if they enter room with poison without a potion
207-
if 'poison' in rooms[currentRoom] and 'hemlock' in rooms[currentRoom]['poison'] and 'potion' in inventory:
208-
print('The potion has protected you from the Poison! ... Continue On')
209-
elif 'poison' in rooms[currentRoom] and 'hemlock' in rooms[currentRoom]['poison']:
210-
print('The Poison Hemlock has killed you. A potion will protect you ... GAME OVER!!!')
211-
break
272+
# Player loses health if they enter room with poison without a potion
273+
if 'poison' in rooms[currentRoom] and 'potion' in inventory:
274+
print('The potion has protected you from the Poison! ... Good Deal!')
275+
elif 'poison' in rooms[currentRoom]:
276+
# If poison is in room, subtract a health point
277+
health -= 1
278+
if health >= 1:
279+
print("You are weakened by the Poison! A potion will protect you!")
280+
else:
281+
# Game ends once health reaches zero
282+
print('The Poison has killed you ... GAME OVER!!!')
283+
break
212284

213285
# Player wins game if they get to the Garden with the key and magic potion
214286
if currentRoom == 'Garden' and 'key' in inventory and 'potion' in inventory:

0 commit comments

Comments
 (0)