I am making a Tic-Tac-Toe game. I need to check if the player clicked on the square that I already clicked.
The problem is that the error is displayed in the first click. My update code:
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 set to 0 each time the left button is pressed. My matrix is a 3x3 matrix for storing information. If it is 0, it means that it is already pressed. So, in the loop, I check if store[i,j] == 0 , and then set showerror to 1. Now in the drawing function, I made this call for a shower
spriteBatch.Begin(); if (showerror == 1) { spriteBatch.Draw(invalid, new Rectangle(25, 280, 105, 19), Color.White); } spriteBatch.End();
The problem is, whenever I click on an empty square, it turns into a cross, but an error appears. Please help me
Sudo reboot
source share