I have a function that shrinks the size of a "Food bank" (represented by a rectangle in my GUI) once some of the food has been taken. I have the following function check for this:
public boolean tryToPickUpFood(Ant a)
{
int xCoord = a.getLocation().x;
int yCoord = a.getLocation().y;
for (int i = 0; i < foodPiles.size(); i++)
{
if (foodPiles.get(i).containsPoint(xCoord, yCoord))
{
foodPiles.get(i).decreaseFood();
return true;
}
}
return false;
}
Where decreaseFood shrinks the rectangle..
public void decreaseFood()
{
foodAmount -= 1;
shrinkPile();
}
private void shrinkPile()
{
WIDTH -=1;
HEIGHT = WIDTH;
}
However, whenever one rectangle shrinks, ALL of the rectangles shrink. Why would this be?
edit:
Food piles are being added like such:
addFoodPile(new Food(new Point(200,200)));
addFoodPile(new Food(new Point(400,340)));
public void addFoodPile(Food fp)
{
foodPiles.add(fp);
}