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!
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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | 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); } } } |