@@ -22,16 +22,18 @@ def showInstructions():
2222Protect yourself against the Poisons with a potion
2323
2424Commands:
25- go [direction] (Options -> north, south, east or west)
26- get [item] (Options -> key, sword or potion)
27- exit (Exit the game)
25+ go [direction]
26+ get [item]
27+ exit
2828
2929''' )
3030
3131def showStatus ():
3232 # print the player's current status
3333 print ('---------------------------' )
3434 print (f"You are in the { currentRoom } " )
35+ # print your health score
36+ print (f"Health : { health } " )
3537 # print the current inventory
3638 print (f"Inventory : { str (inventory )} " )
3739 # print the available directions
@@ -46,9 +48,15 @@ def showStatus():
4648 print (f"There is some { rooms [currentRoom ]['poison' ]} in the room!" )
4749 print ("---------------------------" )
4850
49- # An inventory, which is initially empty
51+ # Create inventory, which is initially empty
5052inventory = []
5153
54+ # Initial health points
55+ health = 3
56+
57+ # start the player in the Hall
58+ currentRoom = 'Hall'
59+
5260'''
5361A dictionary is used to link a room to other rooms and
5462define what is contained inside the room.
@@ -145,9 +153,6 @@ def showStatus():
145153
146154 }
147155
148- # start the player in the Hall
149- currentRoom = 'Hall'
150-
151156showInstructions ()
152157
153158# loop forever
@@ -195,19 +200,31 @@ def showStatus():
195200 if move [0 ] == 'exit' :
196201 break
197202
198- # Player loses game if they enter room with Zombie without a Sword
203+ # Player loses health if they enter room with Zombie without a Sword
199204 if 'monster' in rooms [currentRoom ] and 'Zombie' in rooms [currentRoom ]['monster' ] and 'sword' in inventory :
200- print ('You have defended yourself from the Zombie attack! ... Continue On ' )
205+ print ('You have defended yourself from the Zombie attack! ... Fantastic! ' )
201206 elif 'monster' in rooms [currentRoom ] and 'Zombie' in rooms [currentRoom ]['monster' ]:
202- print ('A Zombie has eaten your brainz. You need to defend yourself ... GAME OVER!!!' )
203- break
207+ # If monster is in room, subtract a health point
208+ health -= 1
209+ if health >= 1 :
210+ print ("The Zombie took a bite out of you! You need to defend yourself with a sword!" )
211+ else :
212+ # Game ends once health reaches zero
213+ print ('A Zombie has eaten your brainz ... GAME OVER!!!' )
214+ break
204215
205- # Player loses game if they enter room with poison without a potion
216+ # Player loses health if they enter room with poison without a potion
206217 if 'poison' in rooms [currentRoom ] and 'hemlock' in rooms [currentRoom ]['poison' ] and 'potion' in inventory :
207- print ('The potion has protected you from the Poison! ... Continue On ' )
218+ print ('The potion has protected you from the Poison! ... Good Deal! ' )
208219 elif 'poison' in rooms [currentRoom ] and 'hemlock' in rooms [currentRoom ]['poison' ]:
209- print ('The Poison Hemlock has killed you. A potion will protect you ... GAME OVER!!!' )
210- break
220+ # If poison is in room, subtract a health point
221+ health -= 1
222+ if health >= 1 :
223+ print ("You are weakened by the Poison! A potion will protect you!" )
224+ else :
225+ # Game ends once health reaches zero
226+ print ('The Poison has killed you ... GAME OVER!!!' )
227+ break
211228
212229 # Player wins game if they get to the Garden with the key and magic potion
213230 if currentRoom == 'Garden' and 'key' in inventory and 'potion' in inventory :
0 commit comments