Computer Science I for majors by James Tam |
Due Tuesday Nov 15 at 4 PM
Implement the functionality for the previous assignment using functions. One way of decomposing your program is to implement the process of instructions for a room as a function or functions. Because there are six rooms that will mean that your program will consist of at least 7 functions (1 per room plus a starting function). You may be able to subdivide your program using an alternate approach to writing 1 function per room but your program must follow good design principles for using functions.
This program includes everything needed for the program to perform the actions specified in the previous assignment (e.g. display menus, get user input, verify user input etc.) but adds three additional rooms. All instructions must be enclosed within the body of a function. The exceptions could include: import statements (not really needed for this assignment), the creation of global constants and the call to the initial start or main function. You will be penalized heavily if functions are not used or improperly used. A solution for the previous assignment can be found in UNIX under: /home/231/assignments/assignment3/assignment2Solution if you didn't fully complete the assignment. It's recommended that you don't take the entire solution and just include it in your program. Instead you should just use the solution to help you understand how to produce your own solution. Also you can find sample outputs of my solution to this assignment under: /home/231/assignments/assignment3/outputs
Part I:
Your first part of this program is identical to the previous assignment except your solution will be implemented into separate functions. Once the player passes through the locked door into Part II there is no way to return the original three rooms in Part I
Part II:
Living room contents: a pot of soil, stairs going up, a dark entranceway, a ball of a string
- Viewing the pot of soil: 1) Default state when viewed, it looks dry 2) After it's been fertilized by the mouse (bedroom) when the soil is viewed a vine will grow that takes the player to paradise (game won and the program ends).
- Stairs going up: takes the player to the attic.
- Dark entranceway: takes the player into the bedroom.
- Ball of string: the player can pick up this object. There is only one ball of string, once it has been picked up it should not show up again in this room.
Attic contents: a tiny hole in the floor, an unlimited supply of cheese, stairs going down.
- Hole: 1) player can pick up some cheese and try to drop it down the hole, the game indicates that the cheese is too big 2) If the player has the string then an option is provided to drop the string down the hole. When this occurs the string should be removed from the player's inventory (the string doesn't reappear anywhere in the game, nor does the option to drop the string down the hole appear in this room).
- Cheese: player can pick some up, the supply is unlimited so repeatedly picking up the cheese won't diminish the supply (or change the room description). However the game should track that the player is carrying cheese (this will allow the player to feed the mouse the cheese).
- Stairs going down: takes the player back down to the living room.
Bedroom contents: a tomcat which is intently watching a mouse hole (default), mouse (after cat leaves).
- Tomcat: when the player isn't carrying the string no interaction is displayed. When the player is carrying the string then there is a option to play with the cat using the string whereby the cat looks briefly at the player and then goes back to watching the mouse hole (the motion isn't enough to distract the cat).
- Mouse: after the player drops the string down the hole from the attic the large motion distracts the cat sufficiently so that it leaves the room. The mouse then comes out of it's hole. Only if the player is carrying some cheese will the game display an option to feed the cheese to the mouse. When this occurs the mouse will leave the room and fertilize the pot of soil. (The vine will grow and the player will only wine the game when the soil is viewed again from the living room). After fertilizing the soil the mouse will return to the room so there is the possibility of the player repeatedly feeding the mouse. If the player hasn't picked up any cheese then the room description should show that the mouse is in the room but there is no option to interact with it.
- Dark entranceway: takes the player into the living room.
As was the case with the previous assignment each room will provide a description of the contents, display a menu of options (which varies depending upon the actions of the player), get and error check the player's selection as long as the player remains in the room. (In the case of the bedroom the menu may stop displaying after the player has won the game).
In addition to grading on whether the above functionality was correctly implemented TAs will also look at style and documentation.
Style (synopsis from the intro to programming notes)
Principles of good design for functions (most of it is a synopsis from the decomposition notes)