I am using a couple of methods that I think danpost suggested for adding actors (in this case bombs) to random empty spaces in my world. The code is:
The problem is that the first bomb is always at 0,0. If I change the initial x, y values the first bomb is always at that location. The second bomb is always random though.
What is this happening and what could I do to fix it?
public MyWorld(){
super(600, 600, 1);
Bomb bomb1 = new Bomb();
Bomb bomb2 = new Bomb();
addToRandomEmptyCell(bomb1);
addToRandomEmptyCell(bomb2);
}
public int getRandomNumber(int start,int end)
{
int normal = Greenfoot.getRandomNumber(end-start+1);
return normal+start;
}
private void addToRandomEmptyCell(Actor actor)
{
int x = 0, y = 0;
while (!getObjectsAt(x, y, null).isEmpty())
{
x = getRandomNumber(50, 550);
y = getRandomNumber(50, 550);
}
addObject(actor, x, y);
}
