对于我正在制作的游戏,我需要在10x10的游戏板上放置类似俄罗斯方块的棋子。
如果玩家尝试将棋子放在我板上的棋盘上,我想返回“棋盘”。
为此,我制作了一个初始方法,如果正方形被占用,则返回true。
//Return true if the cell is occupied
public boolean isOccupied(int x, int y){
if (board.get(x).get(y) != null){
// The problem seems to be in the line directly above
return true;
}
return false;
}
但是当我尝试编译时,它给了我一个编译错误,说-找不到符号-方法get(int)
我不知道为什么会收到此错误或如何解决它。
任何帮助将非常感激。
最佳答案
您的电路板类未定义get(int x)方法。因此,您必须像这样尝试..
if (board[x][y] !=null) { // since its a 2d array (x row , y column)
return true;
}