public class Background extends World
{
/**
* Constructor for objects of class MyWorld.
*
*/
int width = 900;
int height = 600;
int rows = 25;
int cols = 25;
public Background()
{
super(900, 600, 1);
}
public void act()
{
GreenfootImage gfim = new GreenfootImage(width, height);
int rectWidth = getWidth() / cols;
int rectHeight = getHeight() / rows;
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
if (Greenfoot.mouseClicked(this))
{
MouseInfo mi = Greenfoot.getMouseInfo();
int x = mi.getX();
int y = mi.getY();
addObject(new Blue(), x+rectWidth, y+rectHeight);
//gfim.setColor(Color.BLUE);
//gfim.fillRect(x, y, rectWidth, rectHeight);
}
}
}
drawGrid();
}
public void drawGrid()
{
GreenfootImage grid = new GreenfootImage(width, height);
grid.setColor(Color.BLUE);
for (int i = 0; i <= width; i+=25)
{
for (int j = 0; j <= height; j+=25)
{
grid.drawRect(i, j, 25, 25);
}
}
setBackground(grid);
}
}

