For this project we're going to build a small game, based on some of the pieces we've used in previous projects. The user will define a rectangular target area (using the X and Y coordinates of two opposite corner points,) and then fire projectiles at the target area using a cannon at the origin. The cannon fires shells at a fixed velocity, but the user controls the bearing and declination of the shot.
The goal of this project is primarily to practice breaking a problem down into a set of simpler pieces using classes and methods. To assist in this, we provide the following "skeleton" that should be used as a starting point:
Use the new and improved Point.java to represent cartesian coordinates.
The Target class will represent the target areas that the Cannon is attempting to hit. A Target can be defined by two points in the X-Y plane, and is assumed to be the rectangle with corners at those two locations. Your Target class should contain implementations of the following methods:
The Cannon class represents a cannon that fires simple projectiles at the target(s). It should have instance variables that represent the number of projectiles remaining, and a Point where the cannon is located.
Two fixed constants are used in this project, and it makes the most sense for them to belong in this class:
Your Cannon class should contain definitions of the following methods:
This class pulls together all of the pieces to run the game. It should take care of all of the input required from the player, and encode the rules for the game.
For each of the classes listed above, you may create as many additional helper methods as you need to solve the problem.
In the examples below, I use text in blue to distinguish the output of the program from the input I typed. This is for purpose of clarity only; your program will not print text in different colors.
Project 5 - Target Practice