CS 201 - Computer Science I - Fall 2008
Project 3
Loyola College >
Department of Computer Science >
Dr. James Glenn >
CS 201 >
Projects >
Project 3
Due
Monday, November 10th at 11:59pm.
Projects submitted after the due date will be assessed a 20% penalty per day.
Projects will not be accepted more than four days late.
Objectives
- to use the Graphics class
- to use selection statements
Assignment
This applet requires Java 2 and so will not work with some browsers.
Use the arrow keys to guide your frogs home.
The supplied code does not do a good job drawing things: the frogs and
turtles are simple green ovals, and the logs and vehicles are plain rectanges.
Furthermore, the way things are drawn does not convey necessary information
to the player: the turtles always look the same whether they are under water
or not; and the home bays look the same whether or not they are occupied.
All of the drawing is done by methods in the CalaverasCrossingPainter
class. In particular, you will be writing code in the
paintFrog, paintHome, paintTurtle, paintLog,
paintTractor, paintCar, paintRacecar, and
paintTruck methods. Each of those methods is passed four arguments:
the Graphics object to use for drawing; the width and height
of the area to draw in; and the game element that is being drawn. Check the
code to see what identifiers are used for these values.
You should use the Graphics object to draw the game element.
The Graphics object you use to draw has been translated
so that no matter
where the game element is on the screen, you should draw within the
rectangle whose opposite corners are at (0, 0), and (width - 1, height - 1).
Anything you draw outside this region will not show up on the screen.
The Graphics object has also been rotated so that you should
always draw the frog facing straight up and the obstacles moving towards
the left.
You will have to use methods in the Frog, Turtle,
and Home classes to determine how to draw instances of those
classes. For example, the Home objects should be drawn differently
when they are empty compared to when they are occupied by a frog.
(Note that when a frog makes it home and then respawns at the bottom of the
screen there is no longer a Frog object in the top row.
It is therefore the responsibility of paintHome rather than
paintFrog to draw the frogs that have made it home.)
You will
have to use the documentation to determine
which methods to use.
Files
The files needed to play the game are in an
archive file. The only source code
the archive contains is
CalaverasCrossingPainter.java. You should use your CalaverasCrossingWindow.java from Project 2,
or download a
copy that creates no
obstacles if you want to start from scratch. Make sure you do not save the new copy over your P2 code.
You should compile and run CalaverasCrossingWindow.java to test your code.
Advice
- Because the area you have to draw in is fairly small (each lane is about
60 pixels high by default),
you shouldn't try to draw things too intricately.
- To make your drawings easier to see, you can switch the cases around
for testing. For example, since the frog's jumps only last a fraction
of a second, you can draw the frog as if it is jumping when it is
really sitting.
- It can be difficult to see which shapes are not being drawn correctly
when many of the same color overlap. You can temporarily change the
color of each shape to determine which is not correct. For example,
you can draw the frog's head blue and its body green.
Grading
- Correctness: 75%; for full credit you must
- remove dead execution paths from your selection statements;
- avoid repetitive code;
- draw the frog, which should appear different when it is sitting
compared to when it is jumping or dead;
- draw the frog home bays in such a way so that the player can tell
when a frog has already jumped into one;
- draw the turtles, which should appear in at least four different ways:
above water, just above water, just underwater, and underwater;
- draw at least one of the other five kinds of objects; and
- use at least three non-constant colors (colors other than
Color.BLUE,
etc.) including at least one obtained using the brighter
or darker methods in the Color class and one
created by passing RGB components to the Color
constructor;
- use at least three different Graphics methods;
- draw to fill the area defined by the w and h
arguments passed to the paintXXX methods; and
- use layering.
-
Comments and Style: 20% (you must make a good faith effort towards correctness
to earn this part of the grade)
-
Creativity: 5%
Submissions
Submit by e-mail the source code (.java file) for your edited version
of CalaverasCrossingPainter.java.