The function printNow is not the only way to present information to the user during the running of a program. We might also use the function showInformation which takes a string as input, then displays it in a dialog box. Currently, our showRoom subfunctions presume that we will display the room information via printNow. If functions like showPorch returned a string with the description, then the function showRoom could either use printNow to display the room description or showInformation. Rewrite the room showing functions to return a string, then modify showRoom to easily change between printing the room information and showing it in a dialog box.

Note: As stated in the question, each of the show room functions has to be changed to return a string. In particular, in order to ensure that the text is still readable, the altered functions should make use of the new line character “\n”. Additionally, the easiest way to “choose” between two options is to make use of a Boolean to switch between printing and dialog boxes. There’s a number of different potential answers to this question, one approach (as below) is to just write a new function to handle text output, but one could also handle the switching entirely within showRoom.


```
#Determines whether to use printNow or showInformation
printOption = false
def showText(txt):
if printOption:
printNow(txt)
else:
showInformation(txt)
#This method just prints out the description for the current rooms
def showRoom(room):
toPrint = ("===========\n")
if room ==drawbridge:
toPrint= toPrint+showDrawbridge()
elif room == gate:
toPrint= toPrint+showGate()
elif room ==courtyard:
toPrint= toPrint+showCourtyard()
elif room==kitchens:
toPrint= toPrint+showKitchens()
elif room==stables:
toPrint= toPrint+showStables()
elif room==hallway:
toPrint= toPrint+showHallway()
elif room==pr:
toPrint= toPrint+showPR()
elif room == kr:
toPrint= toPrint+showKR()
elif room == skr:
toPrint= toPrint+showSKR()
elif room == wr:
toPrint= toPrint+showWR()
return toPrint

#This method prints the description for the Drawbridge
def showDrawbridge():
toReturn = ""
toReturn = toReturn +("You are on the drawbridge before the Dark Castle.\n")
toReturn = toReturn +("Towers like teeth jut into the sky above.\n")
toReturn = toReturn + ("You can go north to the castle gate. If you dare.\n")
return toReturn

#This method prints the description for the Gate
def showGate ():
toReturn = ""
toReturn = toReturn +("You are at the castle gate.\n")
toReturn = toReturn +("You feel a sense of dread.\n")

if not riddleAnswered:
toReturn = toReturn +("The gate is shut tight. A skull at the gate's top \n")
toReturn = toReturn +(" looks down upon you. In a shrill voice it says: \n")
toReturn = toReturn +(" \"This thing all things devours\"\n")
toReturn = toReturn +(" \"Birds, beasts, trees, flowers\"\n")
toReturn = toReturn +(" \"Gnaws iron, bits steel\"\n")
toReturn = toReturn +(" \"Grings hard stones to meal\"\n")
toReturn = toReturn +(" \"Slays king, ruins town, \"\n")
toReturn = toReturn +(" \"And beats mountain down.\"\n")
toReturn = toReturn +(" \"What am I?\"")
else:
toReturn = toReturn +("You can see a courtyard to the north.\n")
toReturn = toReturn +("The drawbridge is behind you to the south.\n")
return toReturn

#This method prints the description for the Courtyard
def showCourtyard ():
global evilWizardAppears
toReturn=""
toReturn = toReturn +("You are in the courtyard.\n")
toReturn = toReturn +("There are tattered flags flying, each one \n")
toReturn = toReturn +(" depicting the wolf's head, the symbol of\n")
toReturn = toReturn +(" the dark castle.\n")

if evilWizardAppears:
toReturn = toReturn +("A robed figure stands in the courtyard's center.\n")
toReturn = toReturn +(" \"You cannot take this castle from me!\" \n")
toReturn = toReturn +(" \"My power is absolute!\"\n")
evilWizardAppears = false
else:
evilWizardAppears = true

toReturn = toReturn +("To the west are the castle kitchens.\n") toReturn = toReturn +("To the east are the stables.\n")
toReturn = toReturn +("To the south is the castle gate.\n")
toReturn = toReturn +("To the north is the castle hallway.\n")
return toReturn

etc.
```

Computer Science & Information Technology

You might also like to view...

What type of HTML list would be good to use to display a list of terms and their definitions?

a. bullet list b. ordered list c. unordered list d. description list

Computer Science & Information Technology

Which of the following statements about a Microsoft account is FALSE?

A) You can sign onto any Windows 10 device using your Microsoft account. B) Your user settings are stored in the cloud. C) You do NOT have to use a Microsoft e-mail account. D) A Microsoft account requires a nominal annual fee.

Computer Science & Information Technology

________ Tiles give users a constant stream of information

Fill in the blank(s) with correct word

Computer Science & Information Technology

What is the BindingNavigator control? How is it used?

What will be an ideal response?

Computer Science & Information Technology