I am working on a ColorTest assignment, and need to create a checker board background. I have it compiled but instead of red and black squares i get Greenfeet in a grid pattern instead of red and black squares.
World- ColorTest
import greenfoot.*;
/**
* Write a description of class ColorTest here.
*
* @author (Tyler Schenk)
* @version (21July2015)
*/
public class ColorTest extends World
{
/**
* Constructor for objects of class ColorTest.
*
*/
public ColorTest()
{
super(400, 400, 1);
boolean black = true;
for (int x = 0; x < 8; x++)
{
if (black)
black = false;
else
black = true;
for (int y = 0; y < 8; y++)
{
if (black)
{
ColorPatch blackSquare = new ColorPatch (0, 0, 0);
addObject (blackSquare, x*50 + 25, y*50 + 25);
black = false;
}
else
{
ColorPatch redSquare = new ColorPatch (255, 0, 0);
addObject (redSquare, x*50 + 25, y*50 + 25);
black = true;
}
}
}
}
}
Actor - Class
import greenfoot.*;
/**
* Write a description of class ColorPatch here.
*
* @author (Tyler Schenk)
* @version (21July2015)
*/
public class ColorPatch extends Actor
{
/**
* Act - do whatever the ColorPatch wants to do. This method is called whenever
* the 'Act' or 'Run' button gets pressed in the environment.
*/
public void act()
{
// Add your action code here.
}
public ColorPatch (int r, int g, int b)
{
GreenfootImage img = new GreenfootImage (80, 20);
img.setColor (new java.awt.Color(201,0,153));
img.fill();
}
}
