// This class represents a CrazyJumper with two feet.

import java.awt.Image;
import java.awt.Graphics;

public class CrazyJumper
{
  public static final int PIXELS_PER_INCH = 6;
  private Foot leftFoot, rightFoot;
  private int stepLength;
  private int stepsCount;
  
  // Constructor
  public CrazyJumper(int x, int y, Image leftPic, Image rightPic)
  {
    leftFoot =  new Foot(x, y - PIXELS_PER_INCH * 4, leftPic);
    rightFoot = new Foot(x, y + PIXELS_PER_INCH * 4, rightPic);
    stepLength = PIXELS_PER_INCH * 12;
  }  

  // Returns the left foot
  public Foot getLeftFoot()
  {
    return leftFoot;
  }

  // Returns the right foot
  public Foot getRightFoot()
  {
    return rightFoot;
  }

  // Makes first step, starting with the left foot
  public void firstStep()
  {
    leftFoot.moveForward(stepLength);
    rightFoot.moveForward(stepLength);
    rightFoot.turn(45);
    leftFoot.turn(45);
    stepsCount = 1;
  }

  // Makes next step
  public void nextStep()
  {
  	leftFoot.moveForward(stepLength);
  	rightFoot.moveForward(stepLength);
    
    if (stepsCount % 2 == 0)  // if stepsCount is even
    {
      rightFoot.turn(90);
      leftFoot.turn(90);
    }
      
    else  
    {
      rightFoot.turn(-90);
      leftFoot.turn(-90);
    }

    stepsCount++;  // increment by 1
  }

  // Stops this CrazyJumper (brings its feet together)
  public void stop()
  {
    if (stepsCount % 2 == 0)  // if stepsCount is even
    {
      rightFoot.turn(45);
      leftFoot.turn(45);
    }
      
    else  
    {
      rightFoot.turn(-45);
      leftFoot.turn(-45);
    }
  }

  // Returns the distance CrazyJumped
  public int distanceTraveled()
  {
    return stepsCount * stepLength;
  }

  // Draws this CrazyJumper
  public void draw(Graphics g)
  {
    leftFoot.draw(g);
    rightFoot.draw(g);
  }
}
