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!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | 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--; } } } |