Java Programming


Question description



In this project, you will create a graphical simulation of an aerial dogfight game.  As a minimum, your completed project shall contain:


a movable friendly fighter aircraft which shall defend itself against a squadron of enemy fighters using weapons which can be fired by the user using the keyboard.

a number of enemy fighters which shall attempt to destroy your friendly fighter.  Enemy fighters shall destroy your friendly fighter by either crashing into it or optionally firing projectiles to hit it.

The user is the person playing the game and will be playing the role of the friendly fighter. The simulation will continue until all of the enemy aircraft have been destroyed, your friendly aircraft has been destroyed, or the user decides to quit.  The user will "communicate" with the friendly fighter by entering commands via the keyboard.  These commands will move the defender up and down on the display and fire the projectiles.  When fired, the projectiles shall provide a display of the projectile’s path traveled and shall destroy any target they hit.  The user will determine the number of enemy fighters via a dialog box.

Graphics Support


You will use the StdDraw package introduced below to provide the graphical elements of your simulation. This software is courtesy of Robert Sedgewick and Kevin Wayne from Princeton University’s Computer Science Department. See the following description for details on its use, or you can find information on the Princeton Intro to CS website.


StdDraw is used to produce graphical output.  In order to use the class you must first add it to your project.  The easiest way to do this is to download and save it to the src directory of your project.

StdDraw is similar to the Math class in that you can’t create a StdDraw object.  Everything you need is accessed via static methods and static variables. Documentation for the class can be found here, or at under the Standard Drawing heading along with multiple examples.  Some of the methods you’ll use in this project are:


voidsetXscale(double x0, x1) - used to set the dimensions for the display area.  For example setXscale(-20, 20) creates a display area where x ranges from -20 to 20.


voidsetYscale(double y0, y1) – same as above, except it sets the y dimensions.


voidsetPenColor(Color c) – set the color that will be drawn.  The colors can be accessed as static variables in StdDraw.  Ex: setPenColor(StdDraw.BLUE).


voidfilledCircle(double x, double y, double r) – draws a solid circle with the center at position x, y and a radius of r.


void show(int t) – shows the drawing and pauses for t milliseconds.


Additional methods from the StdDraw package may be needed and can be discovered by reading the StdDraw documentation.


Project specifications


Your project must include the following classes which are derived from class AerialObject (which you also shall provide): an EnemyAircraft class, a FriendlyAircraft class, a Projectile class.  In addition, should you choose to add any moveable GroundObjects to your project (for extra credit), you should include an additional DogfightObject class from which classes AerialObject and GroundObject inherit.  In addition, your project shall include a class Pos to define the coordinates of your objects in the x-y coordinate space, as well as a class BattleSpace to hold all of the objects in your BattleSpace (EnemyAircraft, FriendlyAircraft, Projectile).  It shall also include an execution class AerialDogfight used to control the execution of your simulation. You will need to import the code into your project so you will actually have at least nine classes (see me if you have an alternate architecture in mind) in your project.


Figure 1 below provides a partial UML Class Diagram for the above recommended architecture.  You should provide additional classes as well as addition attributes and methods for the existing classes as you feel necessary to meet the project specifications.




Figure 1: Project 1 “TopGun” UML Class Diagra


DogfightObject Class


Class DogfightObject is a top-level class to contain all of the attributes and methods which are common to the other entity classes in the simulation.  It will contain commonly used constants as well as attributes and methods common to both aerial and ground objects used in the simulation.


AerialObject Class

Class AerialObject is an abstract class used as the base class for creating classes EnemyAircraft, FriendlyAircraft, and Projectile.  It will also be used for creating a reference object that will be used to invoke polymorphic behavior of these classes when drawing an instance of these classes in the window.


FriendlyAircraft Class

We’re going to add a FriendlyAircraft to our dogfight to use in holding off the enemy (or to at least zap a few of them in the process!)  Our FriendlyAircraft will be a located along the left edge of the screen and shall be controlled using the “U” and “N” keys, indicating up and down respectfully, to move it along the left side of the window and the ‘F’ key to fire its Projectiles.  Use StdDraw to draw it using an appropriately sized icon.  Movement will be simulated by the right-to-left movement of the enemy aircraft across the screen.  Each time the fire key is pressed, your FriendlyAircraft shall fire its Projectile leaving a trail that shall travel directly to the right from its position, disappearing when it reaches the right side of the window (hopefully hitting an EnemyAircraft in the process!


EnemyAircraft Class

This class should be developed using the Figure 1 UML diagram as a basis.  As a minimum, you shall display your EnemyAircraft using an appropriately sized icon. The y location shall be randomly generated before the EnemyAircraft object is instantiated and the x location shall be set to the right of the display.  All three of these values should be passed to the constructor.  Use StdDraw to draw appropriately sized icons.  EnemyAircraft shall be removed from the display if hit by our FriendlyAircraft’s Projectiles.  Your life will be easier if you use class Pos to represent the position of the objects in your BattleSpace and make all your x and y's that designate the location doubles rather than ints.  Your toString method should return the location of the EnemyAircraft and obviously all EnemyAircraft should be instantiated as alive.  Your EnemyAircraft should start at the right side of the Window and move in a semi-random direction while moving from the right to the left side of your screen- changing direction each time it reaches the top and bottom boundaries of the BattleSpace (or otherwise decides it’s bored with the current direction it’s heading!).  Your directions are either directly left, diagonally down-left, or up-left.  Optionally, the EnemyAircraft may fire their own missiles at the FriendlyAircraft, destroying it and terminating the game if the FriendlyAircraft is hit.  The FriendlyAircraft may also be destroyed if an EnemyAircraft runs into it.


Projectile Class

The Projectile class shall be used to create the track of projectiles fired from the FriendlyAircraft’s weapons each time the fire key is pressed.  Projectiles shall originate at the FriendlyAircraft’s position and travel to the right until they either hit an invading EnemyAircraft (thereby destroying it) or travel beyond the limits of the viewer’s window.  Optionally, Projectiles may also be fired from the Enemy aircraft, either automatically or by the designer’s choice of key depression or mouse click.  If the Enemy aircraft fires a projectile, it shall travel in the same direction as the EnemyAircraft’s heading and it shall destroy any object (friend or foe) to which it contacts.


BattleSpace Class

I also defined a class BattleSpace to hold all of the various components for my simulation (EnemyAircraft, FriendlyAircraft, Projectile).  It includes methods for adding EnemyAircraft and a FriendlyAircraft to the simulation as well for firing Projectiles when the user hits the “f” key.  A draw( ) method is also provided to display these items in the window.  To keep track whether we’re winning the battle against the invading horde, we'll want to keep a count of and display the number of EnemyAircraft we’ve destroyed.


AerialDogfight Class

Finally, you’ll want to create an execution class that controls the whole simulation.  Class AerialDogfight contains the methods used to control the simulation operation.  Remember, the main method of your execution class should be very short (2-3 lines maximum); it will basically rely on the run() method and its helpers to control the execution.







The project will be graded using the following guidelines


Documentation (10%): All source files, except, must be documented using JavaDoc. You must submit completed UML diagrams for all three classes.

Encapsulation (10%): You are expected to use what we've learned with respect to proper use of the public and private access modifier to control access to the data members and hide the underlying implementation as much as possible. You must also use accessor/get and mutator/set methods to access the private data.

Style Guide (5%):Make sure you are familiar with the style guide in terms of formatting your code and proper use of variable and class names. See the course web page for a link to this guide.

Meeting Project Specifications (75%):Your project should meet the requirements as laid out in this project description and expanded on below.

1. Project must use inheritance.

2.   Project must use polymorphism.

3. Project must use Abstract classes.

4. Project must use ArrayLists to contain AerialObject and Ground objects.

5. Project must iterate through elements contained in ArrayListcontainer using for each loops.

6. Other requirement as called out in the above Project specifications.


Other Requirments


(+1 pt.) Put a counter in the loop in the simulate method and when all targets have been destroyed give the user his score via a JOptionPane dialog box.  The score should be the number of targets the FriendlyAircraft destroyed.

(+3 pts.) Stop the targets from ever overlapping each other.

(+5 pts.) Allow the EnemyAircraft to fire their own Projectiles, ending the simulation when one of their own Projectiles destroys the FriendlyAircraft.  The Projectile’s direction of motion shall be determined by the aircraft’s heading at the time the Projectile is fired.

(+3 pts.) In conjunction with 3 above, EnemyAircraft Projectiles shall destroy any EnemyAircraft or FriendlyAircraft they hit.

(+5 pts.) Allow the FriendlyAircraft movement to be controlled in a left-to-right or right-to-left direction as well as an up-down movement giving it full range across the entire battlefield.  When fired, the FriendlyAircraft’s Projectiles direction of motion shall be determined by the aircraft’s heading at the time the Projectile is fired.

(+3 pts.) Add scenery to the Battlefield (rocks, shrubs, trees, etc.), providing an overhead perspective of the Battlefield.

(+5 pts.) Add one or more AirArtillery positions to the simulation.  The AirArtillery battery shall fire Projectiles in a direction that is either controlled by the user via keyboard selection or simulated automatically using a random number generator to fire the projectile and determine direction.



Submission Instructions


Your submission should consist of:


Paper Submission: A printout of all files containing any source code that you either create or modify, the complete UML diagrams for all classes, and a screen capture of the execution.  Source code shall be properly annotated using appropriate JavaDoc notations. It is not necessary to turn in a hard-copy of any provided source files that you did not modify.

Electronic Submission: All source code, including files provided for your use (in other words everything we'll need to compile and run your program). These files shall be submitted to your instructor via BlackBoard by the deadline.  You do NOT need to submit


Tutor Answer

(Top Tutor) Daniel C.
School: Boston College
Studypool has helped 1,244,100 students
Ask your homework questions. Receive quality answers!

Type your question here (or upload an image)

1822 tutors are online

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors