This site requires JavaScript, please enable it in your browser!
Greenfoot back
letin
letin wrote ...

2015/10/2

Having a Lobster Eat Every Other Crab

letin letin

2015/10/2

#
I am trying to program my scenario so that after every other Crab my Lobster encounters, it eats it. So far, I have this and need help moving on. " public void lookForCrab() { if ( isTouching(Crab.class) ) { removeTouching(Crab.class); Greenfoot.playSound("au.wav"); Greenfoot.stop(); } } "
Mack Mack

2015/10/2

#
I posted the same question on here and I got some help! Try this code, it should work perfectly! // instance field private int touchCounter; // the 'lookForCrab' method public void lookForCrab() { // check for change in touching state if (isTouching(Crab.class) == (touchCounter % 2 == 0)) { // track state touchCounter = (touchCounter+1) % 4; // check for second touch if (touchCounter == 3) { removeTouching(Crab.class); Greenfoot.playSound("au.wav"); } } }
letin letin

2015/10/3

#
Thank you!
You need to login to post a reply.