我在使用这段代码时遇到了问题,如果有人能指出我正确的方向,我将不胜感激。已经卡了好几天了!!
基本上,我试图阻止船在到达边界后移动。边界是 6 和 -6。
这是代码。谢谢 :)
public void move (int direction) //if position exceeds 5 then playership will
//no long move in that direction.
{
if (position > 5)
{
.... ?? What to write here?
}
else if (position < -5)
{
.... ?? What to write here?
}
position = position + direction;
gun1.move(direction);
gun2.move(direction);
}