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

2015/10/1

Need Help with Greenfoot Scenario

letin letin

2015/10/1

#
So, I am trying to i. Turn the worms randomly left or right up to 18 degrees when they reach the end of the World. ii. Give the worms a chance to survive! Have the worms respond to the “up” and “down” arrow keys on the keyboard by moving the worms up or down. This is what I have so far, but every time I run the scenario, nothing happens! The worms don't move no matter how much I press the up and down keys. Can someone help me? I really have absolutely no idea what I am doing wrong. " import greenfoot.*; /** * Worm. A sand worm. Very yummy. Especially crabs really like it. */ public class Worm extends Actor { /** * Check whether we are at the edge of the world. If we are, turn a bit. * If not, do nothing. */ public void turnAtEdge() { if ( isAtEdge() ) { turn(-18); turn(18); } } /** * Check whether a control key on the keyboard has been pressed. * If it has, react accordingly. */ public void checkKeypress() { if (Greenfoot.isKeyDown("left")) { move(3); } if (Greenfoot.isKeyDown("right")) { move(3); } } } "
Mack Mack

2015/10/2

#
TRY THIS public class Worm extends Actor { public void act() { if ( isAtEdge() ) { turn(3); } if ( Greenfoot.getRandomNumber(100) < 10) { turn(Greenfoot.getRandomNumber(60) - 18); } move(3); } public void checkKeypress() { if (Greenfoot.isKeyDown("down")) { turn(-3); } if (Greenfoot.isKeyDown("up")) { turn(3); } } }
letin letin

2015/10/3

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