I have an assignment using Trick the Turtle, where I must currently spawn random numbers of lettuce at random locations, while also spawning a turtle, two snakes, and a bug at random locations as well. However, when I try to spawn the turtle, snakes, and bug, they all spawn at the same location. Could someone examine my code and tell me what I'm doing wrong?
public class TurtleWorld extends World
{
/**
* Create the turtle world. Our world has a size
* of 560x460 cells, where every cell is just 1 pixel.
*/
public TurtleWorld()
{
super(600, 480, 1);
prepare();
}
/**
* Prepare the world for the start of the program. That is: create the initial
* objects and add them to the world.
*/
private void prepare()
{
Counter myCounter = new Counter();
addObject(myCounter, 50, 30);
int numberOfLettuce=Greenfoot.getRandomNumber(15)+1;
int count=1;
while (count<=numberOfLettuce)
{
Lettuce newLettuce = new Lettuce();
int randomX=Greenfoot.getRandomNumber(getWidth());
int randomY=Greenfoot.getRandomNumber(getHeight());
addObject(newLettuce, randomX, randomY);
count++;;
}
int randomX=Greenfoot.getRandomNumber(getWidth());
int randomY=Greenfoot.getRandomNumber(getHeight());
Snake snake = new Snake();
addObject(snake, randomX, randomY);
Bug bug = new Bug();
addObject(bug, randomX, randomY);
Snake snake2 = new Snake();
addObject(snake2, randomX, randomY);
Turtle turtle = new Turtle();
addObject(turtle, randomX, randomY);
}
}