Hello great coders,
I am writing a chess game in c# using windows forms and i need your help. I already wrote the code to get me the chess board but i need to populate the chess board with officials and this is where i got stuck. Here is my code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace chess5
{
public partial class Form1 : Form
{
private Panel[,] chessBoardPanels;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
const int tileSize = 60;
const int gridsize = 12;
var clr1 = Color.DarkGray;
var clr2 = Color.White;
chessBoardPanels = new Panel[gridsize, gridsize];
for (var n = 0; n < 8; n++)
{
for (var m = 0; m < 8; m++)
{
var newPanel = new Panel
{
Size = new Size(tileSize, tileSize),
Location = new Point(tileSize * n, tileSize * m),
};
Controls.Add(newPanel);
chessBoardPanels[n, m] = newPanel;
if (n % 2 == 0)
{
newPanel.BackColor = m % 2 != 0 ? clr1 : clr2;
}
else
newPanel.BackColor = m % 2 != 0 ? clr2 : clr1;
}
}
}
}
}
That is the code that designs my chess board for me. but am kind of stuck on how to populate it with officials. Any help will be appreciated. Thanks