public class Background extends World
{
public void act()
{
{
{
{
if(Greenfoot.getRandomNumber(100)<10){
addObject(new Mushroom(),0,20);
if (getObjects(Mushroom.class).size() == 0) addMushrooms(3);
/**
* Constructor for objects of class Background.
*
*/
}
} }
}
}
/**
* Constructor for objects of class Background.
*
*/
public Background()
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 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()
{
Fish fish = new Fish();
addObject(fish, 296, 357);
theCounter=new Counter();
addObject(theCounter, 73, 378);
Mushroom mushroom = new Mushroom();
addObject(mushroom, 433, 242);
Mushroom mushroom2 = new Mushroom();
addObject(mushroom2, 103, 287);
Mushroom mushroom3 = new Mushroom();
addObject(mushroom3, 250, 84);
Zombie zombie = new Zombie();
addObject(zombie, 492, 77);
Zombie zombie2 = new Zombie();
addObject(zombie2, 138, 175);
Zombie zombie3 = new Zombie();
addObject(zombie3, 169, 50);
}
private Counter theCounter;
public Counter getCounter()
{
return theCounter;
}
private void addMushrooms()
{
Mushroom mushroom = new Mushroom();
addObject(mushroom, 433, 242);
Mushroom mushroom2 = new Mushroom();
addObject(mushroom2, 103, 287);
Mushroom mushroom3 = new Mushroom();
addObject(mushroom3, 250, 84);
}
}

