// Class: AbstractRacer
//
// Author: Alyce Brady
//    Modified 21 May 2017 to add @Override (prev version date was 2/29/04)
//
// 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:<br>
 *
 *    An <code>AbstractRacer</code> object represents a racer
 *    in an obstacle course race.
 *
 *  @author Alyce Brady
 *  @version 21 May 2017
 **/
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 <code>grid</code>
     **/
    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 <code>newLoc</code> 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 <code>newLoc</code>
     *  is not null.)
     *  @param  newLoc    new location value
     *  @throws       IllegalArgumentException if the precondition is not met
     **/
    @Override
    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();

}
