For this lab, you will write a game in which a cannon is fired to clear a mine field.
In this game, you fire cannon balls from a cannon positioned on a platform to clear mines in a grass field. Each click of the mouse fires a cannon ball. When the cannon ball hits the ground, it explodes and clear the mines that are hit by the explosion. There are three mines in total in the field. Whenever a mine is cleared by the explosion of a cannon ball, a new mine is created at a random position in the field. The hit and miss counts are display on the screen. The number of hits counts the number of mines that have been cleared, and the number of misses counts the number of cannon balls that have been fired and that did not hit any mine. So if a single cannon ball clears more than one mine, then it counts for multiple hits, and if a cannon ball does not clear any mine, it is a miss. The player can adjust the speed of the next cannon ball by dragging the mouse up or down. Dragging up increases the speed and dragging down decrease the speed. The speed of the next cannon ball is displayed in a speed bar on the screen.
We have provided your with a partially completed class MineGame. The code for setting up the scene has been provided. You need to add the code for firing a cannon ball, for display the score, and for adjusting the speed of the next cannon ball. The places where your code is needed has been indicated. However, you will need to write new methods or add other code. However, you should keep your code simple and clear and should not do more than necessary work. Keep in mind that before you write any code, you need to write the design.
You will write a new class CannonBall that extends ActiveObject. This is the class where you will create the animations. Before you write any code, you need to write a complete design of the class.
To begin, create a folder CS102/lab5, and download and save the following files into the folder.
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.
Grading Points
|