Games often have nonplayer characters (NPC) which are characters that are not controlled by the player. Add an Evil Wizard to the castle game. When you first play the game, the Evil Wizard is in the Courtyard, and his description says that he is in the Courtyard, but then disappears. Every other time after the first time you enter the Courtyard, the Evil Wizard does not appear in the description. But if you visit the Wizard’s Room, the Evil Wizard can be found there. You defeat him and win the game.

Note: This question requires the addition of a variable to track the appearance of the evil wizard in the courtyard, a change to the showCourtyard function to switch whether or not he appears, and a change in pickRoom or showWR to lead to a win state.

```
#This variable tracks whether or not the evil wizard appears
evilWizardAppears = true
#This method prints the description for the Courtyard
def showCourtyard ():
global evilWizardAppears
printNow("You are in the courtyard.")
printNow("There are tattered flags flying, each one ")
printNow(" depicting the wolf's head, the symbol of")
printNow(" the dark castle.")

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

printNow("To the west are the castle kitchens.")
printNow("To the east are the stables.")
printNow("To the south is the castle gate.")
printNow("To the north is the castle hallway.")
#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":
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...

A split form is helpful when you want to work with one record at a time and still see the big picture in the main table

Indicate whether the statement is true or false

Computer Science & Information Technology

Linking and importing produce the same result in Access

Indicate whether the statement is true or false

Computer Science & Information Technology