Use the in operator to provide some flexibility to the castle game. Allow the player in the Courtyard to go "north" or "up" to the upper Hallway, or "down" or "south" to return to the Courtyard from the Hallway.

Note: Since this method requires the use of the in keyword, it’s asking that the answer make use of strings or collections that combine both direction possibilities. So in the Hallway example, to go north or up would be represented with the string “north up”, as seen below. Alternatively one could make use of a list of both words.

```
#This method actually parses user directions to determine what changes should occur
def pickRoom(direction , room):
global riddleAnswered
#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 exitLoc
#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
#"Drawbridge" room direction handling
if room == drawbridge:
if direction == "north":
return gate
#"Gate" room direction handling
elif room == gate:
if direction == "north" and riddleAnswered:
return courtyard
if direction == "time":
riddleAnswered = true
printNow("\"That's it!\" cackles the skull and disappears.")
printNow(" The castle gate opens.")
return room
elif direction == "south":
return drawbridge
#"Courtyard" room direction handling
elif room == courtyard:
if direction == "east":
return stables
elif direction == "south":
return gate
elif direction=="west":
return kitchens
elif direction in "north up":
return hallway
#"Kitchens" room direction handling
elif room == kitchens:
if direction == "east":
return courtyard
#"Stables" room direction handling
elif room == stables:
if direction == "west":
return courtyard
#"Hallways" room direction handling
elif room==hallway:
if direction =="north":
return pr
elif direction == "east":
return skr
elif direction in "south down":
return courtyard
elif direction == "west":
return kr
#Princess Room direction handling
elif room == pr:
if direction == "south":
return hallway
#Sir Knight's Room direction handling
elif room == skr:
if direction == "west":
return hallway
#King's Room direction handing
elif room == kr:
if direction =="south":
printNow("===========")
printNow("You enter the room of the Evil Wizard")
printNow(" The robed figure appears, chanting words of power.")
printNow(" You cut him off with your sword, ridding the")
printNow(" castle of his evil magics.")
printNow("You Win")
return exitLoc
if direction == "east":
return hallway
#Wizard's Room direction handling
elif room == wr:
if direction =="north":
return kr

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

Instant messaging uses ____ technology, which lets one computing device identify the status of another.

A. asynchronous B. threaded C. routed D. presence

Computer Science & Information Technology

A PowerPoint screen element that displays a large image of the active slide.

A. Normal view B. Placeholder C. Slide pane

Computer Science & Information Technology