Currently, the user must get the case right when typing the directions. Use the lower() method on strings to make the input all in lowercase, so that both “North” and “north” will work as input.
Note: This only needs to be included in the “pickRoom” function
```
#This method actually parses user directions to determine what changes should occur
def pickRoom(direction , room):
global hand
global stairsUnlocked
global ogreAlive
#Set the direction to the "lower" of the direction
direction = direction.lower()
#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 uw
elif direction == "Lantern":
hand = "Lantern"
return porch
#"Entryway" room direction handling
elif room == entryway:
if direction == "north":
return kitchen
elif direction == "east":
return lr
elif direction == "south":
return porch
#"Kitchen" room direction handling
elif room == kitchen:
if direction == "east":
return dr
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":
hand = "Crowbar"
return kitchen
#"Livingroom" room direction handling
elif room == lr:
if direction == "west":
return entryway
elif direction == "north":
return dr
elif direction == "key":
hand = "Key"
return lr
#"DiningRoom" room direction handling
elif room == dr:
if direction == "west":
return kitchen
elif direction == "south":
return lr
elif direction == "bomb":
hand = "Bomb"
return dr
#"Stairs" room direction handling
elif room==stairs:
if direction =="east":
return kitchen
elif direction == "up":
if hand=="Bomb":
return mr
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 exitLoc
elif room == mr:
if direction == "down":
return stairs
elif direction=="bomb":
printNow("You drop the bomb, blasting the ogre into smithereens.")
ogreAlive = false
return mr
elif room == uw:
if direction == "up":
return porch
if direction =="north" and hand=="Lantern":
return tunnel
elif room == tunnel:
if direction =="south":
return uw
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 exitLoc
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
```
You might also like to view...
Answer the following statements true (T) or false (F)
1) The StackTrace property keeps track of all the method calls that occur in a program, and that's how a program knows which method caused the error. 2) The constructor method for an exception class should be overloaded to allow the customizing of the display message. 3) Each Exception should have three constructors: A default constructor, one that receives a string, and one that receives a string and an exception. 4) By convention, the name of each user-defined exception should end with Exception.
When a cout statement prints a string that tells the person at the terminal what should be typed, the output string used in this manner is called a(n) ____.
A. prompt B. checkpoint C. interrupt D. pause
When executing a mail merge operation for mailing labels using the task pane method, you need to insert merge fields on the first label, then click the ____ button to copy the layout of the first label to the other labels.
A. Preview your labels B. Finish & Merge C. Edit individual labels D. Update all labels
Educational institutions were some of the first adopters of WLANs because of their dramatic advantages in teaching and learning.
Answer the following statement true (T) or false (F)