I am trying to write a Method, so that the automatically moving camels have a 50% chance to move forward (per act), but I don't know how to do it.
Here's my code:
for some reason, the method (Greenfoot.getRandomNumber(100)<50) is not working.
import greenfoot.*;
public class Buttercup extends Kamel
{
GreenfootSound sound = new GreenfootSound("bonk2.wav");
public void act()
{
win();
move();
Greenfoot.delay(1);
}
public void win(){
Actor z = getOneIntersectingObject(Ziel.class);
World w = getWorld();
if (z != null){
Endscreen b = new Endscreen();
Greenfoot.stop();
b.setImage("win1.2.png");
w.addObject(b, 7, 3);
Greenfoot.playSound("Won.wav");
}
}
public void move(){
if (isTouching(Stein.class)){
if((Greenfoot.getRandomNumber(100)<50) && getOneObjectAtOffset(1, 0, Stein.class) == null){
setLocation(getX() + 1, getY());
}
sound.play();
setLocation(getX(), getY()+1);
setLocation(getX(), getY()-1);
}
}
}

