/**
 * Tadpole is a black fish that, after a set lifespan, may die, or become a frog.
 * 
 * @author Jeff Minucci
 * @version 5/05/05
 */

import java.util.Random;
import java.awt.Color;

public class Tadpole extends Minnow
{
	// instance variables - replace the example below with your own
	private int lifespan;
	private int acts;
	private Environment itsEnv;

	/**
	 * Constructor for objects of class Tadpole
	 */
	public Tadpole(Environment env, Location loc)
	{
		super(env,loc);
		itsEnv = env;
		Random generator = RandNumGenerator.getInstance();
		lifespan = (generator.nextInt(11) + 10);
		super.setColor(Color.black);	
	}
	
	public void act()
    {
        // A simulation asks objects to "act" -- to do whatever that
        // object should do in a single simulation timestep.  A minnow's
        // action is simply to move.
        super.move();
        acts++;
        if (acts==lifespan)
        {
            if (willDie())
            {
                death();
            }
            else
            {
                transform();
            }
        }
    }
    
    protected boolean willDie()
    {
        Random generator = RandNumGenerator.getInstance();
        int x = generator.nextInt(2);
        if (x==0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    
    protected void death()
    {
        theEnv.remove(this);
        //if (theEnv.isEmpty())
        //{
            //JOptionPane.showMessageDialog
        //}
    }
    
    protected void transform()
    {
        theEnv.remove(this);
        Frog froggy = new Frog(itsEnv, myLoc);
    }
    public String toString()
    {
        return "T" + myLoc.toString() + myDir.toString();
    }

}