In this assignment we will start fleshing out the simulation/game you started in Assignment 2. You can design the rules of the simulation, its graphic design, commands, and operations any way you like, as long as they match the general software design and features described in the assignments. (You need not be restricted by what you did in Assignment 2, you can redesign your program if you wish. But it should still provide all the features required by the previous assignments.)
For this assignment, we will create data structures to support a collection of "vehicles" that make up the simulation and provide a canvas and paint callback routine that can draw the vehicles on the screen from the stored data structures. Your program will then simply draw the Map onto the screen, along with its Vehicles. You will also provide some interactive widgets to control some aspects of the display.
Each vehicle object should have instance variables that store the data needed for drawing the object and for executing commands on it (and, later, for making it move). For a start, it might contain current position, direction, speed, altitude or depth (if applicable), color, a text label, and perhaps parameters about its appearance to be used by your draw routine.
Vehicle should have a constructor that specifies its initial position, orientation, label, or whatever other information you need.
Vehicle will also have a draw method, which is your own subroutine, and which would draw just that vehicle in its correct location onto the canvas. It can use regular Java Graphics or Graphics2D drawing methods to draw the vehicle onto the canvas. You can draw each Vehicle any way you want, as a simple 2D drawing made with lines, shapes, or polygons. Draw its ID or name next to it in text. Your different subclasses of Vehicles should look different (by overloading the draw method).
All drawing is done through the paintComponent() callback, which might be called by the system at any time. It will be called if the window is exposed or resized; and you will also need to trigger it manually when the state of the simulation changes due to a user command. Your paintComponent will likely call other routines (like the draw methods you have written in Map and Vehicle) to complete the job. Your paintComponent should always be prepared to draw the canvas from scratch, using data you have stored inside your objects. To redraw the canvas, first draw your background Map, and then call your draw method for each of the Vehicles in the simulation.
Your program design should exploit the features of object-oriented programming (encapsulation of code and data, support for abstract data types, polymorphism/overloading, inheritance). In particular, object-oriented programming provides us a good way to handle the various data needed in callback routines. You should use objects to encapsulate each interactive widget with the routines and data you need to use it.
You should provide an object for each interactive widget or small group of widgets you create. That object should hold anything you need to remember about the widget from one callback to another, all the data pertinent only to the command for that widget or that you need to operate this control, (including, in most cases, a pointer to the map or other outside object to perform the actual action the user requested), and the widget's own listener callback routines.
If you have several widgets that share some behavior or properties, you should organize your objects into an appropriate inheritance hierarchy.
You will have other data that must be accessed by several widgets, particularly shared information about the state of the program or global information about the state of the user interface. Provide additional classes and objects for holding this kind of information.
Remember to trigger your drawing to repaint itself explicitly whenever one of your commands causes a change that should be reflected on the screen. And remember that the way to change the screen is first to change the data stored your classes and then to trigger the repaint.
You should follow these general Java programming practices:
And, finally, on your Java programs, for uniformity, please
name your Java class that has your main program in it
Main, in file
In addition to your program, submit documentation about the design of your system in these forms:
ownwhich other objects)
Submit this documentation electronically in text form. Include it as part of the readme file that you submit with your assignment.