我正在制作井字游戏。我需要检查玩家是否点击了他们已经点击过的方块。
问题是第一次点击本身显示错误。我的更新代码是:
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
每当单击左键时设置为 0。我的矩阵是用于存储信息的 3x3 矩阵。如果它是 0 意味着它已经被点击了。所以在循环中我检查是否store[i,j] == 0
设置showerror
为 1。现在在绘图函数中我调用了 showerror
spriteBatch.Begin();
if (showerror == 1)
{
spriteBatch.Draw(invalid, new Rectangle(25, 280, 105, 19), Color.White);
}
spriteBatch.End();
问题是每当我点击空白方块时,它会变成十字但会显示错误。请帮帮我