Add the ability for the player to win the game. When the player wins, the game should print what happened and exit the game. Perhaps finding the secret treasure room under the Porch would make the player win the game.

Note: This question seems to imply the existence of a treasure room, but a new room method does not need to be created to answer it.


```
#showTunnel prints the description of the tunnel off the underground world
def showTunnel():
printNow("You are in a dark, twisting tunnel")
printNow("You can see a shining gold light to the north")
printNow("You can go south to the Underground World.")
#This method actually parses user directions to determine what changes should occur
def pickRoom(direction , room):
global hand
global stairsUnlocked
global ogreAlive
#This code handles the command that quits the game
if (direction == "quit") or (direction == "exit"):
printNow("Goodbye!")
return "Exit"
#This section handles the help command which displays the introduction text again
if direction == "help":
showIntroduction()
return room

#The section below checks each room, then checks the possible directions in the room

#"Porch" room direction handling
if room == "Porch":
if direction == "north":
return "Entryway"
elif direction == "down":
return "UndergroundWorld"
elif direction == "Lantern" or direction == "lantern":
hand = "Lantern"
return "Porch"
#"Entryway" room direction handling
elif room == "Entryway":
if direction == "north":
return "Kitchen"
elif direction == "east":
return "LivingRoom"
elif direction == "south":
return "Porch"
#"Kitchen" room direction handling
elif room == "Kitchen":
if direction == "east":
return "DiningRoom"
elif direction == "south":
return "Entryway"
elif direction=="west" and (hand=="Key" or stairsUnlocked):
stairsUnlocked = true
return "Stairs"
elif direction=="north" and hand=="Crowbar":
return "Storage"
elif direction == "Crowbar" or direction == "crowbar":
hand = "Crowbar"
return "Kitchen"
#"Livingroom" room direction handling
elif room == "LivingRoom":
if direction == "west":
return "Entryway"
elif direction == "north":
return "DiningRoom"
elif direction == "key" or direction == "Key":
hand = "Key"
return "LivingRoom"
#"DiningRoom" room direction handling
elif room == "DiningRoom":
if direction == "west":
return "Kitchen"
elif direction == "south":
return "LivingRoom"
elif direction == "bomb" or direction=="Bomb":
hand = "Bomb"
return "DiningRoom"
#"Stairs" room direction handling
elif room=="Stairs":
if direction =="east":
return "Kitchen"
elif direction == "up":
if hand=="Bomb":
return "MysteryRoom"
else:
printNow("===========")
printNow("You get to the top of the stairs ")
printNow(" only to find a hungry Ogre. Without a ")
printNow(" weapon to fend him off, he gobbles you up.")
printNow("The End.")
return "Exit"
elif room == "MysteryRoom":
if direction == "down":
return "Stairs"
elif direction == "Bomb" or direction=="bomb":
printNow("You drop the bomb, blasting the ogre into smithereens.")
ogreAlive = false
return "MysteryRoom"
elif room == "UndergroundWorld":
if direction == "up":
return "Porch"
if direction =="north" and hand=="Lantern":
return "Tunnel"
elif room == "Tunnel":
if direction =="south":
return "UndergroundWorld"
if direction == "north":
printNow("===========")
printNow("You follow the winding tunnel until it ")
printNow(" opens out into a cave filled with gold ")
printNow(" you grab as much as you can and escape.")
printNow("You Win!")
return "Exit"
elif room == "Storage":
if direction =="south":
return "Kitchen"

#This last section handles invalid commands
printNow("You can't (or don't want to) go in that direction.")
return room
```

Computer Science & Information Technology

You might also like to view...

In order to hide functions that are defined in the implementation file, they should be part of the ______________ namespace.

a. global b. std c. class d. unnamed

Computer Science & Information Technology

The __________ __________ makes passes through an array, comparing consecutive pairs of elements and interchanging them if they are not in the correct order.

Fill in the blank(s) with correct word

Computer Science & Information Technology

Match the following terms to their meanings:

I. live preview II. drag-and-drop III. paste IV. cut V. wordwrap A. words within a paragraph automatically move to the next line B. shows result of formatting changes on selected text prior to applying C. add text or object to a new location D. text or object removed from its current location E. moving selected text with the mouse

Computer Science & Information Technology

The philosopher ____________________ is usually regarded as the father of utilitarianism.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology