I am trying to run a command through an object that would be in the list that I have created in a different object of the same class, but I have absolutely no understanding of how that might be done. Here is the code for the class in which I am trying to do this in:
Thanks!
import greenfoot.*;
import java.util.*;
public class Gifts extends Actor
{
int amountTouching; //counts how many teachers it is touching
int touchingZero; //looks for the adjacent gifts that are not next to a bomb
List<Gifts> gifts = new ArrayList<Gifts> ();
List<Gifts> gifts2 = new ArrayList<Gifts> ();
public void act()
{
amountTouching = getNeighbours(51, true, Teacher.class).size();
if (Greenfoot.mouseClicked(this))
{
checkProximity();
}
}
public void checkProximity()
{
if (amountTouching == 0)
{
setImage("empty.png");
checkGifts();
}
else
{
setImage(amountTouching + "adjacent.png");
}
}
public void checkGifts()
{
gifts = getNeighbours(51, true, Gifts.class);
int i = gifts.size();
int checkNumber = gifts.size() - 1;
while (i > 0)
{
if (gifts.get(checkNumber).amountTouching == 0)
{
gifts.get(checkNumber).setImage("empty.png");
}
else
{
gifts.get(checkNumber).setImage(gifts.get(checkNumber).amountTouching + "adjacent.png");
}
checkNumber--;
i--;
}
}
}

