i m writing a simple chess game that has 3pieces,a king and a queen one side and other side just a king,the king and queen should mate alone king with less movements.in this project,first we should get the place of alone king from user and then according to that do other works,i want to know how can i get from user that in which place should king stay?i implemented form with 64 pictureboxes.i will write class for positions,thanks so much
edited:
i wrote this code from Mr Jon Skeet answer:
what mistake does it have?because it doesnt do anything when i click,thanks
PictureBox[,] pic = new PictureBox[8, 8];
public PictureBox SetKingImage(int x,int y)
{
pic[x,y].Image=Image.FromFile("pic/siyahsah2.JPG");
return pic[x, y];
}
public void GetClickedPicturebox()
{
int x, y;
for(x=0;x<8;x++)
{
for(y=0;y<8;y++)
{
pic[x, y] = new PictureBox();
pic[x, y].Click += (object sender, System.EventArgs e) =>SetKingImage(x, y);
}
}
}
The simplest approach would be to ask the user to click on the relevant picture box. You could determine which PictureBox was clicked on in one of three ways:
sender) to find which one it was and get the coordinates appropriatelySubscribe using a lambda expression which encapsulates the position, like this:
One problem with the latter approach is that unsubscribing from an event via a lambda expression is relatively painful – and you probably want to unsubscribe all the event handlers when the first button is clicked.
An alternative is to leave the event handlers in place, and ignore them when it’s not the right time 🙂