Tuesday, 13 August 2013

C# Drawing Chess Board

C# Drawing Chess Board

I'm trying to draw a 8x8 chess board using C#. Here's my first attempt to
draw it. It won't draw the board and I haven't found what I'm missing.
public void Form1_Load(object sender, EventArgs e)
{
Bitmap bm = new Bitmap(8 * 100, 8 * 100);
Graphics g = Graphics.FromImage(bm);
Color color1, color2;
for (int i = 0; i < 8; i++)
{
if (i % 2 == 0)
{
color1 = Color.Black;
color2 = Color.White;
}
else
{
color1 = Color.White;
color2 = Color.Black;
}
SolidBrush blackBrush = new SolidBrush(color1);
SolidBrush whiteBrush = new SolidBrush(color2);
for (int j = 0; j < 8; j++)
{
if (j % 2 == 0)
g.FillRectangle(blackBrush, i * 100, j * 100, 100, 100);
else
g.FillRectangle(whiteBrush, i * 100, j * 100, 100, 100);
}
}
g.DrawImage(bm, 150, 200);
}

No comments:

Post a Comment