public class Ant extends Creature
{
private boolean canCarryFood = true;
/**
* Create an ant with a given home hill. The initial speed is zero (not moving).
*/
public Ant(AntHill home)
{
setHomeHill(home);
}
/**
* Do what an ant's gotta do.
*/
public void act()
{
searchFood();
if (canCarryFood = false){
walkTowardsHome();
}
}
private boolean canCarryingFood()
{
return canCarryFood;
}
private void searchFood()
{
Food food = (Food)getOneIntersectingObject(Food.class);
randomWalk();
if (food != null && canCarryFood){
canCarryFood = false;
this.setImage("ant-with-food.gif");
food.updateImage();
food.lostFood();
}
}
}
