Add another global variable for the player, called a hand. Make the hand initially empty. Change the description so that there is a “key” in the Living Room. If the player types the command key while in the Living Room, the key gets put in the hand. Now, if the player has the key when entering the Kitchen, the stairs become accessible, allowing the player to go “west” and up the stairs. You will have to add some rooms to the game to make this work.

Note: The rooms the question refers to are the stairs and some room for the stairs to lead up to. Below are the methods that need to be changed for this question, with the addition of the hand variable at the file level as well.

```
#The variable to track what's in the player's hand
hand = "Empty"

#This method prints out the description for the current rooms
def showRoom(room):
printNow("===========")
if room =="Porch":
showPorch()
elif room == "Entryway":
showEntryway()
elif room =="Kitchen":
showKitchen()
elif room=="LivingRoom":
showLR()
elif room=="DiningRoom":
showDR()
elif room=="Stairs":
showStairs()
elif room=="MysteryRoom":
showMR()
#This method prints the description for the Kitchen
def showKitchen ():
global ghost
printNow("You are in the kitchen. ")
printNow("All the surfaces are covered with pots,")
printNow(" pans, food pieces, and pools of blood.")
printNow("You think you hear something up the stairs")
printNow(" that go up the west side of the room.")
printNow("It's a scraping noise, like something being dragged")
printNow(" along the floor.")
#This section adds a description if the ghost is "in" the room
if ghost ==1:
printNow("You see the mist you saw earlier.")
printNow("But now it's darker, and red.")
printNow("The moan increases in pitch and volume")
printNow(" so now it sounds more like a yell!")
printNow("Then it's gone.")
#This sets the ghost to be "in" the Entryway
ghost = 0

if hand=="Key":
printNow("You notice a hidden, locked door to the west.")
printNow("Good thing you found that key.")
printNow("You can go to the south or east.")
#showLR prints the description of the LivingRoom
def showLR():
printNow("You are in a living room.")
printNow("There are couches, chairs, and small tables.")
printNow("Everything is covered in dust and spider webs.")
printNow("You hear a crashing noise in another room.")
printNow("You can go north or west.")
if not hand=="Key":
printNow("There is a key here.")
#showStairs prints the description of the Stairs
def showStairs():
printNow("You are at the bottom of the stairs.")
printNow("The wood of the stairs is old and rotten.")
printNow("To your east is the Kitchen.")
printNow("You can go up the stairs to the Mystry Room.")
#showMR prints the description of the MysteryRoom
def showMR():
printNow("What could this room be?")
printNow("You can go down to the stairs")
#This method actually parses user directions to determine what changes should occur
def pickRoom(direction , room):
global hand
#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"
#"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":
return "Stairs"
#"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"
#"Stairs" room direction handling
elif room=="Stairs":
if direction =="east":
return "Kitchen"
elif direction == "up":
return "MysteryRoom"
elif room == "MysteryRoom":
if direction == "down":
return "Stairs"

#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...

Switching between PowerPoint views help you review your presentation's design, content, and organization.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Information about individual visits to a website is called __________ information.

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

Computer Science & Information Technology