import com.collegeboard.grid.Grid;
import com.collegeboard.grid.Location;
import com.collegeboard.sim.Actor;
import com.collegeboard.sim.Rock;

/*
 * Created on Apr 28, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */

public class TriangleWalker extends Actor
{
   public TriangleWalker(int size)
   {
      steps = size;
      if (size > 0) buddy = new TriangleWalker(size - 1);
   }
   
   public void act()
   {
      Grid<Actor> gr = getGrid();
      Location loc = getLocation();

      if (buddyLocation == null)
         buddyLocation = gr.getNeighborLocation(loc, Grid.NORTH);
      
      if (steps > 0) 
      {
         moveTo(gr.getNeighborLocation(loc, Grid.EAST));
         new Rock().putInGrid(gr, loc);
         steps--;         
      }
      else
      {
         if (buddy != null) buddy.putInGrid(gr, buddyLocation);
         removeFromGrid();
      }
   }
   
   private int steps;
   private TriangleWalker buddy;
   private Location buddyLocation;
}
