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
```

Computer Science & Information Technology

You might also like to view...

Which of the following statements about functional programming is false?

a) You do not need to specify how to iterate through the elements or declare and use any mutable (that is, modifiable) variables. This is known as internal iteration, because the library code (behind the scenes) iterates through all the elements to perform the task. b) A key aspect of functional programming is immutability—not modifying the data source being processed or any other program state, such as counter-control variables in loops. This eliminates common errors that are caused by modifying data incorrectly. c) A filter operation combines the elements of a collection into a single new value, typically using a lambda that specifies how to combine the elements. d) A map operation results in a new collection in which each element of the original collection is mapped to a new value (possibly of a different type). The new collection has the same number of elements as the collection that was mapped.

Computer Science & Information Technology

A(n) ________ constructs a query that will select all records from one table and only the matching ones from the other table

Fill in the blank(s) with correct word

Computer Science & Information Technology

The built-in Exceptions in a programming language can cover every condition that might be an Exception in your applications.

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

Computer Science & Information Technology

Case Based Critical ThinkingCase 1For the first time, Mark's team has been contracted to build a website. Mark has decided to use Illustrator to create the web graphics. Since these are all web graphics, Mark tells his team to set up all the files in what color mode?

What will be an ideal response?

Computer Science & Information Technology