我是一名业余程序员,我正在 XNA 游戏工作室开发一个简单的 Noughts 和 Crosss 游戏。现在我要做一个左键点击触发移动,它正在工作。但是当我使用部分类命令将代码传输到两个文件时,我不小心更改了代码,现在右上角的方块不起作用。这是“更新”代码,用于检查:
private void MouseProcess()
{
MouseState mstate = Mouse.GetState();
Mouse_pos = new Vector2(mstate.X, mstate.Y);
float xpos = mstate.X;
float ypos = mstate.Y;
if (mstate.LeftButton.Equals(ButtonState.Pressed))
{
if (xpos >= Gamevar[0].Position.X && xpos <= Gamevar[0].Position.X + 72)
{
C = 1;
}
if (xpos >= Gamevar[1].Position.X && xpos <= Gamevar[1].Position.X + 72)
{
C = 2;
}
if (xpos >= Gamevar[2].Position.X && xpos <= Gamevar[2].Position.X + 72)
{
C = 3;
}
if (ypos >= Gamevar[0].Position.Y && xpos <= Gamevar[0].Position.Y + 75)
{
R = 1;
}
if (ypos >= Gamevar[3].Position.Y && xpos <= Gamevar[3].Position.Y + 75)
{
R = 2;
}
if (ypos >= Gamevar[6].Position.Y && xpos <= Gamevar[6].Position.Y + 75)
{
R = 3;
}
}
}
private void Turncode()
{
switch (turn)
{
case true:
switch (C)
{
case 1:
switch (R)
{
case 1:
Gamevar[0].owner = 1;
turn = false;
C = 0;
R = 0;
break;
case 2:
Gamevar[3].owner = 1;
turn = false;
C = 0;
R = 0;
break;
case 3:
Gamevar[6].owner = 1;
turn = false;
C = 0;
R = 0;
break;
}
break;
case 2:
switch (R)
{
case 1:
Gamevar[1].owner = 1;
turn = false;
C = 0;
R = 0;
break;
case 2:
Gamevar[4].owner = 1;
turn = false;
C = 0;
R = 0;
break;
case 3:
Gamevar[7].owner = 1;
turn = false;
C = 0;
R = 0;
break;
}
break;
case 3:
switch (R)
{
case 1:
Gamevar[2].owner = 1;
turn = false;
C = 0;
R = 0;
break;
case 2:
Gamevar[5].owner = 1;
turn = false;
C = 0;
R = 0;
break;
case 3:
Gamevar[8].owner = 1;
turn = false;
C = 0;
R = 0;
break;
}
break;
}
break;
case false:
switch (C)
{
case 1:
switch (R)
{
case 1:
Gamevar[0].owner = 2;
turn = true;
C = 0;
R = 0;
break;
case 2:
Gamevar[3].owner = 2;
turn = true;
C = 0;
R = 0;
break;
case 3:
Gamevar[6].owner = 2;
turn = true;
C = 0;
R = 0;
break;
}
break;
case 2:
switch (R)
{
case 1:
Gamevar[1].owner = 2;
turn = true;
C = 0;
R = 0;
break;
case 2:
Gamevar[4].owner = 2;
turn = true;
C = 0;
R = 0;
break;
case 3:
Gamevar[7].owner = 2;
turn = true;
C = 0;
R = 0;
break;
}
break;
case 3:
switch (R)
{
case 1:
Gamevar[2].owner = 2;
turn = true;
C = 0;
R = 0;
break;
case 2:
Gamevar[5].owner = 2;
turn = true;
C = 0;
R = 0;
break;
case 3:
Gamevar[8].owner = 2;
turn = true;
C = 0;
R = 0;
break;
}
break;
}
break;
}
}
它不是很复杂,但 Gamevar[1]、[2] 和 [5] 不起作用。