CS 51 Test Programs #1
Due: Friday, October 19 at 5PM

A test program is a laboratory that you complete on your own, without the help of others. It is a form of take-home exam. You may consult your text, your notes, your lab work, or our on-line examples and web pages, but use of any other source for code is forbidden. You may not discuss these problems with anyone aside from the course instructors. You may only ask the TA's for help with hardware problems or difficulties in retrieving your program from a disk or network.

Complete each of the following problems, documenting your code well. You are encouraged to reuse the code from your labs or our class examples. Submit your code in the usual way by dragging it into the Dropoff folder for your section. Please do not submit three separate folders. Instead, place the folders for all three of your complete programs into one folder, make sure that your name appears in the title of the main folder and each of the subfolders, and then place the main folder in our dropoff folder.

If you are claiming extra credit for any of the questions, please indicate what you have done clearly in your comments for that question. If you do not claim it, we will likely miss it and you will not get the extra credit.

Problem 1: Robot sumo, begin!

To celebrate the end of the season for one of Professor Yu's favorite sports, sumo wrestling, you are to write a robot sumo game for your first problem. Start by drawing a 300 ×300 framed square as your ring. Inside the ring you are to draw a 30 ×30 filled square as your robot and a 50 ×50 filled square as the opponent robot. While the mouse is pressed, the small square (your robot) can be dragged along by the mouse. If your robot bumps into the bigger square (the opponent robot) during a drag, the opponent will move the same distance (and in the same direction) as your robot to simulate being pushed.

The goal of this game is to push the opponent robot out of the ring, while keeping your robot inside the ring. That is, you win if, when the mouse is released, the opponent is entirely out of the ring, while your robot is at least partially in the ring.

You should create a text display at the bottom of the ring. At the start, the text should display "Robot sumo, begin!". After the first game has finished (upon the first release of the mouse press), the text display at the bottom should become a score counter. Each time the mouse is released, if your robot has won, the score counter at the bottom should increase the winning score by one. Otherwise, the score counter should increase the losing score by one. In either case the robots should be placed back at their starting positions for the next game.



A demo version of this program is on the on-line version of this handout. You can play with it to see what we have in mind. Please note that the robots are still "inside the ring" when part of their bodies still overlaps with the ring. A robot is only "out of the ring" when none of the filled square overlaps with the framed square.

Please use the method overlaps to determine if the small square has been moved over the big square.

A very small amount of extra credit is available for creating better images of the sumo wrestlers and the ring. Appropriate sound effects are also welcome.

Problem 2: Go Fish!

To help yourself relax as you head into midterms, you have decided to write a program that simulates a fish tank.

To feed the fish, click on the fish's mouth with the mouse. This will cause the fish to grow a little bit, but not move left or right. If the user clicks on the fish's body, but not in the mouth, it hurts the fish. When that happens a text item should appear on the bottom of the window stating "Ouch!". If the next click is either in the mouth or outside the fish's body then the text item should disappear.

If the user taps on the glass, the fish will move away from the tap. To tap, click the mouse somewhere outside of the fish. If the user clicks to the right of the fish's center, then the fish will move to the left a little bit. If the user clicks to the left of the center of the fish, the fish will move right by the same amount.



Possible extensions for extra credit - limit the fish's movement so it can't leave the screen, center the text item on the screen (no matter what the size of the window is at the start), or cause the fish to die (with appropriate graphics) if it eats too much.

Problem 3: Venutian Rover

You may have heard that a new robotic rover landed on Mars this summer. It is not widely known that NASA originally intended to place a rover on Venus first, but the fierce conditions on that planet resulted in the mission to Venus being cancelled.

The difficulty is that the Venutian atmosphere has an abundance of acid rain, which can damage the rover. NASA originally assumed this would not be a problem, but simulations showed just how dangerous this could be.

Your job is to model the Venutian landscape that the rover would land on, including the acid rain droplets that can destroy the rover. When your program is started it should create an ActiveObject class named Cloud. A Cloud object will generate circular drops of acid (one every 0.5 seconds) that rain on the window on the computer. Use a random number generator to generate the locations of the acid drops on the window.

When each drop appears, it should have a radius of 3 pixels (and hence a diameter of 6 pixels). Its radius should increase by 1 pixel every 200 milliseconds until the radius is 30 pixels. The increase in size should leave the center of the drop at the same position. That is, it increases equally in all directions. When the radius exceeds 30 pixels, the drop should disappear from the screen (it evaporates!).

Of course you will need to model the Venutian rover (with a separate Rover class) as well as the acid drops. The rover image is in file "venusrover.jpg". It should appear on the screen with size 66 by 52 pixels and should appear with upper left hand corner in the center of the window.

The rover's movements are controlled by the user with the computer mouse (the rover goes wherever the cursor moves). The user attempts to keep the rover from being disabled by the acid drops. If the mouse overlaps with any active acid drop it will die. To give the rover a fair chance, there is a two second delay between the time a drop appears on the screen and it starts to grow and become dangerous to the rover. (You might imagine that the acid reacts with something planet's surface to become dangerous.) If the rover dies, it should stop moving (i.e., it doesn't react to movements of the computer mouse). However, if the user clicks the mouse somewhere on the screen the rover will become resuscitated at that spot.



Extra credit can be obtained by providing appropriate special effects when the rover is burned by the acid rain. A small shelter to protect the rover from the rain would also be interesting.

Tentative Grading Point Allocations

Value

Feature
Style (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)
Robot Sumo
4 pts. Drawing the screen initially
4 pts. Dragging your player
4 pts. Pushing the opponent
4 pts. Scoring properly & resetting
Go Fish!
4 pts. Drawing the Fish
4 pts. Increasing the size of the fish
4 pts. Reacting to tapping properly
4 pts. Displaying and hiding "Ouch" properly
Venutian Rover
4 pts. Growing an acid drop
4 pts. Having drop disappear at right time
4 pts. Continuous creation of drops in random positions
4 pts. Rover object lives, dies, & moves correctly
Miscellaneous (4 pts total)
Extra Credit (4 pts maximum)