import java.awt.Color;

public class PredatorFish extends Fish
{
  private int turnsNotEating;

  public PredatorFish(Environment env, Location loc)
  {
    super(env,loc);
    turnsNotEating = 0;
  }

//// The above is the code required for part a ////

  public PredatorFish(Environment env, Location loc, Direction dir)
  {
    super(env,loc, dir);
    turnsNotEating = 0;
  }

  public PredatorFish(Environment env, Location loc, Direction dir, Color col)
  {
    super(env,loc, dir, col);
    turnsNotEating = 0;
  }

  protected boolean eat()
  {
	Environment env = environment();
    Location front = env.getNeighbor(location(), direction());
    Locatable lunch = env.objectAt(front);  //don't have to use objectAt - see if

    if(lunch != null)	// if (!env.isEmpty(front)) --> -1/2 since must also check
    {					// if (!env.isEmpty(front) && env.isValid(front))
	  env.remove(lunch);
      return true;
    }
    return false;
  }

  public void act()
  {
    if (!isInEnv())	//am I still alive?		// lots of students missed this
        return;

    if(eat())
      turnsNotEating = 0;
    else
      turnsNotEating++;

    if(turnsNotEating == 5)
      die();
    else	// else not needed as first thing act will do is isInEnv()
      super.act();
  }

    protected void generateChild(Location loc)
    {
        // Create new fish, which adds itself to the environment.
        Fish child = new PredatorFish(environment(), loc,
                                      environment().randomDirection(), color());
        Debug.println("  New Fish created: " + child);
    }
}

