Freshman level Java frogger game

Freshman level Java frogger gameAssignment 7 due on March 26
Simple Frogger
Objectives: interface polymorphism, use listeners, draw images in Java
Note: You can work in a team of two.
Frogger is an arcade game introduced in 1981, where a player helps a frog cross a multi-lane road
and river (http://en.wikipedia.org/wiki/Frogger). A Flash version can be played online at
http://www.play-frogger.com/.
Task: Develop a simplified version of the game, that consists of a single car lane, a single car, and
a frog.
• The field is divided into three sections, top, car lane, and bottom. The field contains two
moving objects, a car, controlled by the computer, and a frog controlled by a human player.
The length of the field should be approximately 5x the car length, but you can experiment
with lengths.
• Car: The car starts on the left of the car lane and moves horizontally to the right of the lane.
The car moves by 1
4
of its length per timer interval. When it reaches the end, the car starts
moving back to the left end, . . .
• Frog: The frog can move left, right, up, and down. It jumps in height increments (Two jumps
to reach the top lane). The player can control the frog with the arrow keys on the keyboard.
When the frog reaches the top, the player wins. When the car hits the frog the game is over.
Design suggestions:
• Like the example posted online, the playing field can be implemented by deriving a class
FroggerComponent from JComponent that contains the game items (car and frogger). The
car and frog could be either drawn or implemented with BufferedImage objects. To load a
buffered image object from a file you can use:
BufferedImage img = null;
try { img = ImageIO.read(new File(”frog.jpg”)); } catch (IOException e) { . . . }
A BufferedImage object can be drawn on a Graphics2D screen:
g2.drawImage(img, x, y, null);
1
• The motion of the car can be controlled by timers. Start with 100ms, but you can experiment
with different timer intervals.
• The frog is controlled by user input with the four arrow keys. To this end you can install a
KeyListener in the JLabel, then set the label’s focusability to true and request the focus.
mylabel.addKeyListener(. . . );
mylabel.setFocusable(true);
mylabel.requestFocus();
The KeyListener will record which buttons were pressed. A KeyListener provides three
methods keyPressed, keyReleased, keyTyped. Please use keyReleased. A KeyListener
object can be created with an anonymous class.
mylabel.addKeyListener(new KeyListener() {
public void keyPressed(KeyEvent e) {}
public void keyReleased(KeyEvent e) { /* record key press */}
public void keyTyped(KeyEvent e) {}
});
When a key was pressed, record which key was pressed. To this end you can query the
parameter e and the constants VK UP, VK DOWN, VK LEFT, and VK RIGHT. The constants are
associated with the non numeric keypad arrow keys.
if (e.getKeyCode() == KeyEvent.VK UP) . . .
The frog does not have to be repainted immediately. This can be done the next time when
the timer expires.
• Timer events: whenever the timer expires
– calculate new positions for the car (based on speed) and frog (based on the recorded
keystroke; note that the frog cannot jump over the car lane). Neither object is allowed
to go out of bounds.
– When the new positions are known, repaint the panel.
– Check whether the car and frog have collided. It is sufficient to check that the frog is
in the car lane and that the car and frog overlap in their left and right bounds. If they
collide, the player looses and the game ends. Otherwise check, whether the frog has
reached the top, in which case the game ends and the player wins.
Turn in a zip file named blazerid hw7.zip. The file should contain an exported Eclipse project1
with the following items:
• All files needed to compile and run your implementation.
• Your tests.
• A document (or text file) that describes: (1) Your design; what guidelines did you follow?
What worked, what did not? (2) How did you test your program. (3) Comment on slightly
updated checkstyle rules posted on Canvas. (4) If you received help from somebody taking
the course, please give credit to that student.
1
If you do not use Eclipse, the turned in file also needs to have a file readme.txt in its top directory that explains
how to compile and test your code.
2
Grading (50 pts max)
• (10pts) Lab exercises and lab report (week of March 20)
• (10pts) Assignment report: design decisions are well described
• (10pts) Turned in code is well documented (Javadoc).
• (10pts) Turned in code is compilable.
• (10pts) The car moves back and forth according to the specification.
• (10pts) The frog moves based on user input. The game ends according to the specification.
• (10pts) Extended version: The game does not end when the frog reaches the top. Instead,
the player attempts to cross the road as often as possible (count number of times). As time
progresses, the car starts moving faster. Note, when the car starts moving faster, a collision
can also occur when the frog is located between the before and after position of the car.

find the cost of your paper