找不到符号方法 get(int)

cannot find symbol method get(int)

对于我正在制作的游戏,我需要在 10x10 游戏板上放置一个类似俄罗斯方块的棋子。

我想 return "occupied" 如果玩家试图将棋子放在我棋盘上的已占用方格上。

为此,我制定了一个初始方法,如果方格被占用,return为真。

//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)

我不知道为什么会收到此错误或如何修复它。 任何帮助将不胜感激。

您的开发板 class 没有定义 get(int x) 方法。所以你必须像这样尝试..

if (board[x][y] !=null)  {   // since its a 2d array (x row , y column)

return true;
}

如果没有其他一些代码,很难看出正在做什么,但是它可能应该是这样的...

//Return true if the cell is occupied
    public boolean isOccupied(int x, int y){
        if (board.get(x,y) != null){
            return true;
        }
        return false;
    }

您要做的是检查单元格 x,y 是否已填充。你需要同时检查X和Y,否则没有意义。您的 get(x,y) 方法会同时检查 x,y 中的单元格。

您的代码中的错误是您正在调用 get(x),我猜 returns 是列的对象,然后您试图调用 get(y)在专栏上。但是,列对象没有在其上创建 get() 方法。