Hi,
I've been playing around with randomisation and I have been trying to have a scenario where a grass square appears in a random position and you press space and there is a 1 in 2 chance it will duplicate itself on the screen. I can't figure out how to get it to work. I've looked at the example of the crab and worms but I want to add an object of itself. It is hard to do this because I cannot declare it. Here is my code:
import greenfoot.*;
/**
* Write a description of class Grass here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Grass extends Actor
{
int lucky = Greenfoot.getRandomNumber(2);
/**
* Act - do whatever the Grass wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
if (Greenfoot.isKeyDown("right"))
{
if (lucky == 1)
{
if (grass != null)
{
World world;
world.getWorld();
world.removeObject(grass);
}
}
}
}
}

