I am making a minesweeper game in C #, and this part of my code checks to see if the user has pressed a specific button on the grid. However, the way to do this I believe that he broke the xy coordinates of the button that he pressed.
The value of the way the code works is that there are two two-dimensional arrays. There are 100 buttons on the button [10,10]. and behind the grid, the grid is called [10,10], and on the grid I said that -1 is a bomb, and 1 is empty space. I am trying to extract the xy coordinate, which he clicks on a button and checks the grid. And this is the code below:
However, when I click the button - in the code int x = System.Convert.ToInt32 (split [0]); I get a "Fix System.FormatException".
What am I doing wrong?
void bttnOnclick(object sender, System.EventArgs e)
{
Button bttnClick = sender as Button;
string[] split = bttnClick.Name.Split(new Char[] { ' ' });
int x = System.Convert.ToInt32(split[0]);
int y = System.Convert.ToInt32(split[1]);
if (grid[x, y] == -1)
{
for (int xx = 0; xx < SizeX; xx++)
{
for (int yy = 0; yy < SizeY; yy++)
{
if (grid[xx, yy] == -1)
{
buttons[xx, yy].Visible = false;
}
}
}
}
}