/**
 * This class simulates a dot race beween a red and a blue dot.  At every step,
 * each dot moves forward a random amount (as determined by the roll of a die).
 * 
 * @author Dave Reed 
 * @version 1/30/13
 */
public class DotRaceFinal {
    private Dot redDot;
    private Dot blueDot;  
    private int goalDistance;

    /**
     * Constructs a dot race where each dot's step is a random int in the range 1..maxStep
     *   @param maxStep the maximum distance a dot can cover in any one step
     *   @param goal the distance form start to finish line
     */
    public DotRaceFinal(int maxStep, int goal) {
        this.redDot = new Dot("red", maxStep);
        this.blueDot = new Dot("blue", maxStep);
        this.goalDistance = goal;
      }

    /**
     * Accessor method for determining the red dot's position.
     *   @return the position of the red dot (starting position = 0)
     */
    public int getRedPosition() {
        return this.redDot.getPosition();
    }
    
    /**
     * Accessor method for determining the blue dot's position.
     *   @return the position of the blue dot (starting position = 0)
     */
    public int getBluePosition() {
        return this.blueDot.getPosition();
    }   
    
      /**
     * Accessor method for determining the race's goal distance.
     *   @return the goal distance 
     */
    public int getGoalDistance() {
          return this.goalDistance;
    }

    
    /**
     * Simulates a random step for each of the dots (updating their positions).
     */
    public void step() {
         if (this.blueDot.getPosition() >= this.goalDistance || 
               this.redDot.getPosition() >= this.goalDistance) {
             System.out.println("The race is over!");
         }
         else {
             this.redDot.step();
             this.blueDot.step();
         }
    }
       
    /**
     * Displays the current status of the race.
     *   @return the position of the blue dot (starting position = 0)
     */   
    public void showStatus() {
        this.redDot.showPosition();
        this.blueDot.showPosition();
    }
    
    /**
     * Resets the race so that both dots are at the starting position (= 0).
     */
    public void reset() {
        this.redDot.reset();
        this.blueDot.reset();
    }
}
