I am making a Tic-Tac-Toe game. I need to check if a player is clicking on a square they have already clicked.
Problem is error is shown in the first click itself. My update code is:
MouseState mouse = Mouse.GetState();
int x, y;
int go = 0;
if (mouse.LeftButton == ButtonState.Pressed)
{
showerror = 0;
gamestate = 1;
x = mouse.X;
y = mouse.Y;
int getx = x / squaresize;
int gety = y / squaresize;
for (int i = 0; i < 3; i++)
{
if (go == 1)
{
break;
}
for (int j = 0; j < 3; j++)
{
if (getx == i && gety == j)
{
if (storex[i, j] == 0)
{
showerror = 1;
}
go = 1;
if (showerror != 1)
{
loc = i;
loc2 = j;
storex[i, j] = 0;
break;
}
}
}
}
}
showerror
is set to 0 whenever left button is clicked. My matrix is a 3x3 matrix for storing information. If it is 0 that means it has been already clicked.So in the loop I check if store[i,j] == 0
then set showerror
to 1.
Now in the draw function I made this call for showerror
spriteBatch.Begin();
if (showerror == 1)
{
spriteBatch.Draw(invalid, new Rectangle(25, 280, 105, 19), Color.White);
}
spriteBatch.End();
Problem is whenever i click on empty square it turns into cross but error gets shown.Please help me out