CS 51 Test Program #1
Due: Friday,
October 19, 2007 at 4 PM
You will find demos and starter files for these questions in the tp1 folder in the labs folder of CS051 on the server. Complete each of the following problems, documenting your code well. You are encouraged to reuse the code from your labs or our class examples. Place the folders for your three problems in a larger folder whose name includes your name and tp1. Submit that folder in the usual way by dragging it into the dropbox folder.
For the first problem, you are to write a program that emulates a broom that can sweep a rectangle around the screen. The broom will be represented by a small ball with diameter 10 that appears when the mouse is pressed and disappears when the mouse is released. While the mouse is depressed, the ball is dragged along by the mouse (the upperleft corner of the ball is always at the mouse location). There is also a filled square (30 pixels to a side) showing on the screen. If the broom bumps into the square during a drag, then the square will move the same distance (and in the same direction) as the broom, as indeed it would if you had a real broom.
One warning: If you are pushing the square diagonally, the square will have a tendency to slide off of the broom. This is because movements parallel to the side of the square will not affect the square (and the computer is so fast that some of your diagonal moves will end up parallel to the square). This is a "feature" not a "bug" (this is what happens with real brooms), so don't worry about it as long as the square generally is moved along with the broom.
For this program you are to create a class to represent a window on a computer screen. The diagram below shows what such a window should look like (except that your window should have a title with your name replacing "Kim").
Like most computer windows, windows from your class can be dragged by grabbing them on the title bar and dragging. They can also be resized by grabbing the small square in the lower right hand corner and dragging that around. The window is closed if the user clicks on the "go-away circle".
We have supplied you with a class, WindowManager, extending WindowController, that creates a window on the screen and then determines whether the window should be dragged or resized (or indeed do nothing at all) in response to user actions, and sends appropriate messages to the window.
You are to write a class Window that can be used with class WindowManager and that has the appropriate behavior. As well as the constructor, the class should support methods
You should not modify the WindowManager class in any way to accomplish the required parts of this program. Feel free to add other graphic items to the Window class to make it look more attractive.
The last program is an homage to James Turrell and his skyscape sculpture in the courtyard between Edmunds and Lincoln. You are to implement a program that draws a picture simulating the view that you would see if you were floating on your back in the pool while looking up at the sky. To make it interesting, every time the user clicks in the window, a cloud should be created at that spot and then slowly float from left to right across the sky. Because the cloud is above the roof of the skyscape, it will be obscured when it is behind it.
To make it clear that this is an homage, please have the program place the text "Turrell" (in blue) on the right edge of the screen each time a cloud passes out of the window. The y-coordinate of the text item should be the same as the middle of the cloud that has disappeared.
The window is 600 pixels wide and 600 pixels high. The roof should be 400 by 400, while the interior is 200 by 200. Hint: The roof is actually composed of 4 rectangles as the blue sky needs to be behind the roof. I suggest that you first get it to work without drawing the blue sky and only add the sky after everything else is already working.
Value | Feature |
Code Quality (16 pts for each of 3 programs) | |
2 pts. | use of boolean conditions |
2 pts. | ifs/whiles |
2 pts. | appropriate vble (instance/local, public/private) |
2 pts. | Descriptive comments |
2 pts. | Good names |
2 pts. | Good use of constants |
2 pts. | Appropriate formatting (indenting, white space, etc. |
2 pts. | Parameters used appropriately |
Correctness (16 pts for each of 3 programs) | |
Broom | |
4 pts. | Drawing the screen initially |
4 pts. | Dragging the broom |
4 pts. | Pushing the "dirt" |
4 pts. | Showing/hiding the broom |
Windows | |
4 pts. | Drawing a window |
3 pts. | Moving the window |
3 pts. | Resizing the window |
3 pts. | Making the window go away |
3 pts. | Centering title at all sizes |
Skyscape | |
3 pts. | Initial screen drawn correctly |
3 pts. | Cloud created at click location |
3 pts. | Cloud floats correctly from left to right |
3 pts. | Cloud floats behind roof correctly |
4 pts. | "Turrell" written at proper location |
Miscellaneous (4 pts total) | |
Extra Credit (4 pts maximum) | |