Hello. I've been having this one issue with my code for quite some time. I'm trying to make a matching game, in which the first match to be made is a kangaroo. From one class, I want if the kangaroo is clicked, to respond by removing it, and playing an audio recording saying congratulations(these two parts aren't an issue, I know they aren't in my code). However, my class simply does not respond when the kangaroo is clicked. Right now I can click anywhere, and the kangaroo will still disappear(obviously not what I want). Any feedback would be greatly appreciated!.
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 | public class goButton extends Actor { public void act() { kangaroo(); } public void kangaroo() { Actor kangaroo; kangaroo = getOneIntersectingObject(Kangaroo. class ); if (Greenfoot.mouseClicked( this )) { Greenfoot.playSound( "kangaroo.wav" ); } if ( Greenfoot.mouseClicked(kangaroo)) { getWorld().removeObjects(getWorld().getObjects(Kangaroo. class )); // play congrats sound here } else { // play try again sound here } } } |