CS 102 Lab # 6
Objective: To gain experience with interface and objects implementing interface
.
For this lab, you will write an arcade game
in which the player controls a plane to fight with an enemy plane.
Below is a demo of what we have in mind. You may notice that the animation is not perfectly smooth when it is viewed in a browser. This is not an issue of the program.
The program consists of four classes and one interface:
- The ArcadeGame class extends FrameWindowController. The window has width 500 and height 600, which can be set by resize(500,600); In order to interact with the keyboard, ArcadeGame must implement Keylistener, which requires methods keyPressed, keyReleased, and keyTyped. We will use keyPressed, and keyReleased to control the play pane and fire. keyTyped is of uno use to our program, but we still need to include its header in ArcadeGame.
- The Bullet class models the bullets fired by both the enemy plane and the player plane.
When it hits its target (which can be either the enemy plane or the player plane), the health of the target is reduced.
When the health of the plane reaches zero, it is destroyed. Once an enemy plane is destroyed, a new one is created. One the player plane is destroyed, the instruction is displayed and the player can click the mouse to create a new player plane.
- The EnemyPlane class models the enemy plane. The enemy plane moves at a random x-speed and y-speed in the upper half of the window and bounces when it hits the upper, left, right boundary of the window or when it moves below the middle of the window.
The enemy plane fires bullets at a constant rate.
When the enemy plane is hit, it briefly displays a red flash. When the health of the enemy plane drops below 50%, the red flash will stay on. The red flash is effected by setting the image of the enemy plane with enemyPlaneDamaged.gif.
- The PlayerPlane models the plane that is controller by the player. The movement of the player plane is controlled by pressing the "W, S, A, D" keys of the keyboard. The plane should start moving in the right direction immediately after the player presses the key(s) that control the direction of the plane. The plane should move continuously at a constant speed when the player holds the key(s). The direction of the player plane is stored in an array of 4 booleans, indicating whether the plane is moving up, down, left or right, as follows:
boolean[] direction = new boolean[4];
Pressing and releasing the keys "W, S, A, D" set the values of the array.
The play plane fires once when the player presses the "J" key of the keyboard.
- We also need an interface Plane. Both EnemyPlane and PlayerPlane implement the Plane interface. The use of interface simplifies our program: we only need one class for bullets fired by both the enemy plane and the player plane.
We have started in class with partial implementations of the class ArcadeGame, Bullet, EnemyPlane, and PlayerPlane. To start, create a folder CS102/lab6, and place those files in the folder. The following image files should also be saved in the same folder.
| Value | Feature |
| Style (6 pts total) |
2 |
Appropriate comments |
1 | Good choice of names |
1 | Good use of boolean expressions |
1 | Not doing more work than necessary |
1 | Appropriate parameters |
|
|
Correctness (14 pts total) |
2 |
Correctly display the planes |
2 |
Correctly move the player plane and the enemy plane |
2 |
Correctly implement the interface |
2 |
Correctly lose and win the game
animation |
2 |
Correctly display the damaged image when the enemy plane is hit |
2 |
Your game should play in a similar fashion as the demo |
2 |
No other problems |
|
|