我试图检查国际象棋游戏中是否有玩家。要做到这一点,我有以下变量this-> getLocX(),this-> getLocY()(玩家在哪里),x,y(玩家想要去的地方)
我有一个函数boardP-> hasPiece(x,y),如果在给定(x,y)的点中有一个玩家,则返回true(1)
我目前正在为Bishop做这个,所以它可以并且需要检查对角线的玩家(我已经检查过这个动作是否是这样的
在这里我尝试了它并不起作用,即使有一个玩家,玩家仍然可以移动,我可以知道,因为该程序是localHost到代表玩家的c#程序。
C ++:
if (abs(x - this->getLocX()) == abs(y - this->getLocY())) // THIS WORKS GOOD
{
cout << "\n" << abs(x - this->getLocX()) << abs(y - this->getLocY()) << x << y;
for (int i = 0; i < abs(x - this->getLocX()); i++)
{
cout << "\n" << boardP->hasPiece(this->getLocX() - 1, i-1) << "\n" << boardP->hasPiece(i, y) << "\n" << x << "\n" << y << "\n" << i << "\n";
if (boardP->hasPiece(this->getLocX() - 1, i-1)) // THIS DOESNT WORK
return 0; // THERE ARE PLAYERS IN THE WAY
}
return 2; // THERE ARE NO PLAYERS IN THE WAY
}
return 0;