【发布时间】:2016-04-26 04:22:58
【问题描述】:
我正在制作一个国际象棋游戏,我制作了一个 2D 的 vector2D 数组来保存棋子的位置,然后当首先单击它然后在棋盘上第二个它应该改变位置,但我遇到了 2 个问题。
首先:我必须单击所需框上方的一个框 第二:2个单次点击同时读取,所以当我点击片段时,它只是将它的位置更改为我点击它的位置
这是我的代码:
public void ChangePositionAfterDrag()
{
bool CheckifFound=false,Black=false,White=false ; // if the loops hits the _mousedownposition and which kind was in the box
// save the index
/* for (int i = 100; i < 100+(80*8); i += 80)
{
for (int j = 80; j < 80 + (80 * 8); j += 80)
{*/
lastMouseState = currentMouseState;
currentMouseState = Mouse.GetState();
if (lastMouseState.LeftButton == ButtonState.Released && currentMouseState.LeftButton == ButtonState.Pressed)
{
if (CheckifFound == false)
{
for (int k = 0; k < 2; k++)
{
for (int l = 0; l < 8; l++)
{
if (currentMouseState.X > _BlackPiecesPosition[k, l].X && currentMouseState.X < _BlackPiecesPosition[k, l].X + 80 && currentMouseState.Y < _BlackPiecesPosition[k, l].Y && currentMouseState.Y > _BlackPiecesPosition[k, l].Y-80 )
{
CheckifFound = true;
IndX = k;
IndY = l;
Black = true;
break;
}
if (currentMouseState.X > _WhitePiecesPosition[k, l].X && currentMouseState.X < _WhitePiecesPosition[k, l].X + 80 && currentMouseState.Y < _WhitePiecesPosition[k, l].Y && currentMouseState.Y > _WhitePiecesPosition[k, l].Y -80 )
{
CheckifFound = true;
IndX = k;
IndY = l;
White = true;
break;
}
}
if (CheckifFound == true)
break;
}
}
}
LastMouseState2 = CurrentMouseState2;
CurrentMouseState2 = Mouse.GetState();
if (LastMouseState2.LeftButton == ButtonState.Pressed && CurrentMouseState2.LeftButton == ButtonState.Released)
{
NewPosition.X = LastMouseState2.X;
NewPosition.Y = LastMouseState2.Y;
}
if(Black==true)
{
_BlackPiecesPosition[IndX, IndY].X = NewPosition.X;
_BlackPiecesPosition[IndX, IndY].Y = NewPosition.Y;
}
else if (White == true)
{
_WhitePiecesPosition[IndX, IndY].X = NewPosition.X;
_WhitePiecesPosition[IndX, IndY].Y = NewPosition.Y;
}
}
【问题讨论】:
-
也许你可以添加一些图片/截图来解释你的意图是什么,你的问题是什么?你的描述对我来说太模糊了。