Hello! I've this situation: modify so that if I click on a wombat, it will be selected (idea: in the WombatWorld class add an instance variable that is null if no wombat is selected or a reference to the selected one. If it is selected and I also click on it If I click on another, it will become the selected one). Once a wombat is selected and the water the "<-" key rotates to the left
Thanks!
import greenfoot.*; // imports Actor, World, Greenfoot, GreenfootImage import java.util.Random; /** * A world where wombats live. * * @author Michael Kolling * @version 1.0.1 */ public class WombatWorld extends World { /** * Create a new world with 8x8 cells and * with a cell size of 60x60 pixels */ public WombatWorld() { super(8, 8, 60); setBackground("cell.jpg"); } /** * Populate the world with a fixed scenario of wombats and leaves. */ public void populate() { Wombat w1 = new Wombat(); addObject(w1, 3, 3); Wombat w2 = new Wombat(); addObject(w2, 1, 7); Leaf l1 = new Leaf(); addObject(l1, 5, 3); Leaf l2 = new Leaf(); addObject(l2, 0, 2); Leaf l3 = new Leaf(); addObject(l3, 7, 5); Leaf l4 = new Leaf(); addObject(l4, 2, 6); Leaf l5 = new Leaf(); addObject(l5, 5, 0); Leaf l6 = new Leaf(); addObject(l6, 4, 7); } /** * Place a number of leaves into the world at random places. * The number of leaves can be specified. */ public void randomLeaves(int howMany) { for(int i=0; i<howMany; i++) { Leaf leaf = new Leaf(); int x = Greenfoot.getRandomNumber(getWidth()); int y = Greenfoot.getRandomNumber(getHeight()); addObject(leaf, x, y); } } }