Professional Documents
Culture Documents
A. Visit my adventure. Run the Adventure Game Find My Keys code from Moodle and
play the game at least twice. Answer these questions:
1. List the classes that are defined in this code. Room and House
2. For each class, list the methods that are defined in this code. describeDoor,
describeRoom, setIsKeyHere, getRoomName
3. How do we start playing the game? Is that function a method in a class?
playGame() it is not a method
4. What makes the game stop? Under what condition does the while loop exit?
Finding the keys makes it stop, when done = true
5. For the House class, what are the parameters for the __init__ method (constructor)?
(self,roomList,doorList)
What attributes are set in the constructor?
self.roomList = roomList
self.doorList = doorList
6. For the Room class, what are the parameters for the __init__ method (constructor)?
(self,roomName,description,doorList)
What attributes are set in the constructor?
self.roomName = roomName
self.description = description
self.doorList = doorList
self.isKeyHere = false
7. Explain what each line of the describeDoors method for a room does.
Line one defines the basic door description.
Line two starts a for loop for the number of doors.
Line three modified the door description
The last line returns the description.
8. What Boolean variables are used in this code? On which line of code is each one
initialized?
isKeyHere has a Boolean variable and is located on line 20
B. Pictures and Sounds. Turn in your finished code after completing this part.
First, change my code to add sound and picture attributes to the room class.
1. In the room class, change the __init__ method to add two more parameters for sound
and picture. Make two new attributes called roomSound and roomPic, and set their
values in the constructor.
2. In the main program at the top of the code, set the media path. Then make a sound
object and a picture object by giving the name of a file for each one. For now, we’ll
just use one sound and one picture for all the rooms. Use a small picture, such as arch
or Barbara. Add that sound object and picture object to each of the constructors for
the five rooms in my house.
3. Run the code. Now each time you enter a room, the picture should display and the
sound should play.