In this program you will implement the Obstacle Course specification from the Object-Oriented Design lab.
Design a program to simulate a race through an obstacle course. Racers start at the starting line and move one space at a time. The race ends when the first racer crosses the finish line.
Your program should be able to support a variety of racer classes with different movement strategies.
Your program should include a graphical user interface that allows a user to control creating the obstacle course and placing obstacles and racers in it. Here are several design alternatives for the initialization aspect of the graphical user interface:
Regardless of the program initialization design you choose, your program should be able to handle multiple types of racers (or multiple movement strategies). You could allow each racer on the course to be of a different type, or you could allow one type for each run of the simulation, with all racers in a given run having the same type. Your program should also provide start/stop buttons and/or a step button. Finally, your program should graphically display the state of the obstacle course and obstacles and racers in it at the end of each time unit and provide a slider bar for changing the speed of the racers. (Actually, the slider bar controls the speed of the animation -- how long the program pauses to let you view the display between time steps -- rather than the speed of the racers.) When the first racer crosses the finish line, your program should report which racer finished first, and its winning time.
You may use the following classes or files, which have been fully or partially implemented and are available in ObstacleCourse.zip and grid.jar. Alternatively, you may implement your own graphical user interface.
ObstacleRaceApp- a class containing a partially implemented main method for the Obstacle Course project
AbstractRacer- a class that extends GridObject; it redefines the changeLocation method to prevent racers from attempting to move into locations that already contain an obstacle or another racer (which would cause the program to throw an exception)
ObstCourseWindow- a fully implemented class that provides a graphical user interface for the Obstacle Course project
ObstCourseEditor- a fully implemented class that provides a second, "editing" window for adding racers to the course
ObstCourseFileMenuActionHandler- a fully implemented class that provides actions corresponding to the menu items in the File menu created by
ObstCourseDataFileHandler- a fully implemented class that reads the obstacle course information from a file and constructs the course
sixObstacles.dat- a sample initial configuration file for an obstacle course
images- a folder containing a number of pictures that could be used to represent racers and obstacles
grid.jar- the Java archive library for the Grid Package, containing classes such as
BasicGridFileMenu, etc. Class documentation for all classes in the Grid Package can be found here. (The
grid.jarfile is not included in the
ObstacleCourse.zipfile, and must be downloaded separately.)
Before you can compile the code provided above, you will need to implement or modify the following classes:
ObstacleCourse- a new class that extends the
BoundedGridclass (In order for
ObstCourseDataFileHandlerto work correctly, the new class must be called
ObstacleCourseand it must have a two-parameter constructor just like
BoundedGrid. You may decide to add or redefine other methods later.)
Obstacle- a new class that represents obstacles on the course. (Should this class extend or implement any class or interface?)
SimpleRacer- a new class that extends the
AbstractRacerclass to always move forward in the race.
Once you have a program that compiles and runs, you should modify it to stop
when the first racer reaches the finish line (and report which racer won) and
you should implement additional types of racers. If
you are using the graphical user interface classes provided above and want
different images, you will need to edit
to associate each
new type of racer with the appropriate image.