i want a loop that creates ONLY a car when it hits the middle of my world i want it to do this three times and only three times so i don't have a car pileup but when i compile and run the world it add 3 cars at once and piles up please help
public void addMore()
{
if (atMiddle())
{
addloop();
}
}
public void addloop()
{
for(int i=0; i<3; i++) {
rand1 = Greenfoot.getRandomNumber(10);
getWorld().addObject(new Car1(rand1),75,345);
}
}
public boolean atMiddle()
{
if ((618==this.getX()))
{
return true;
}
else
return false;
}
what am i doing wrong?

