// Class: AbstractRacer // // Author: Alyce Brady // // License Information: // This class is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation. // // This class is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. import edu.kzoo.grid.Grid; import edu.kzoo.grid.GridObject; import edu.kzoo.grid.Location; /** * Obstacle Course Program:
* * An AbstractRacer object represents a racer * in an obstacle course race. * * @author Alyce Brady * @version 29 February 2004 **/ public abstract class AbstractRacer extends GridObject { /** Constructs an abstract racer. * @param grid the grid holding this racer * @param loc the location of the racer in grid **/ public AbstractRacer(Grid grid, Location loc) { // Initialize the GridObject aspects of this SimpleRacer. super(grid, loc); } // redefined method from GridObject /** Modifies this grid object's location and notifies the grid. * If newLoc is not a valid, empty location, this * version of the changeLocation method does nothing; in other * words, the SimpleRacer will not move. * (Precondition: this object is in a grid and newLoc * is not null.) * @param newLoc new location value * @throws IllegalArgumentException if the precondition is not met **/ protected synchronized void changeLocation(Location newLoc) { if ( ! grid().isEmpty(newLoc) ) return; // If newLoc is a valid, empty location, change the racer's location // just as any other grid object would change location. super.changeLocation(newLoc); } /** Acts: makes one move (or takes one turn) in the race. **/ public abstract void act(); }