In the castle game, the player must answer a riddle correctly or provide a password in order to pass through to the Courtyard. Add that to your game.
Note: The answer will need to include a new file-level variable, a change to the showGate function (to prompt the riddle/password) and a change to the pickRoom function (to allow for the riddle/password answer).
```
#variable to track if the riddle has been answered
riddleAnswered = false
#This method prints the description for the Gate
def showGate ():
printNow("You are at the castle gate.")
printNow("You feel a sense of dread.")
if not riddleAnswered:
printNow("The gate is shut tight. A skull at the gate's top ")
printNow(" looks down upon you. In a shrill voice it says: ")
printNow(" \"This thing all things devours\"")
printNow(" \"Birds, beasts, trees, flowers\"")
printNow(" \"Gnaws iron, bits steel\"")
printNow(" \"Grings hard stones to meal\"")
printNow(" \"Slays king, ruins town, \"")
printNow(" \"And beats mountain down.\"")
printNow(" \"What am I?\"")
else:
printNow("You can see a courtyard to the north")
printNow("The drawbridge is behind you to the south.")
#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=="north":
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 == "south":
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":
return wr
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
```
You might also like to view...
To indicate words that might be misspelled because they are not in Word's dictionary, Word flags text with:
a. bluewavy underlines b. green wavy underlines c. red wavy underlines
Critical Thinking QuestionsCase 1Ellie wants to use Office 2013 for her catering business. For example, she plans to use Word to maintain her collection of recipes, and Excel to manage her budget. To get started, Ellie turns to you for help in understanding the components that appear in the Microsoft Word window. Ellie next asks you about the component located near the top of the window below the title bar. You explain that it provides easy, central access to the tasks performed while creating a document. What is the name of this component? a.scroll barc.ribbonb.status bard.mini toolbar
What will be an ideal response?