Now I'm working on a project, which needs to plant marbles inside a 12*12 world with random of x and increasing y as the coordinance, but I don't know how to properly states this in greenfoot. Here is my existed code for this:
/**
* Creates a new Ground object, with or without marbles.
* This constructor is useful for writing software tests.
* @param createBalls If true, the floor will be populated
* with Marbles.
*/
public Ground(boolean createMarbles)
{
super(12, 12, 60);
for (int i = 0; i < 12; i++)
{
this.addMarbles();
}
//if (createMarbles)
//{
// populate();
//}
}
/**
* This use random generator to plant a marble
* at a random x-ordinance.
*/
public void addMarbles()
{
Marble marbles = new Marble();
add(marbles, Random.generator().
nextInt(getWidth()));
}
