java网格世界为列数分配变量
我很难为网格上的列数指定一个变量。我在实例化cols变量时收到一个错误。有人能帮我吗
public void act()
{
Location place = getLocation();
Grid<Actor> gr = getGrid();
int cols = gr.getNumCols;
if (place.getCol() + 1 < cols)
moveTo(new Location(place.getRow(), place.getCol() + 1));
else
moveTo(new Location(place.getRow(), 0));
这是我收到的错误消息
F:\Lab III Car and Teleporter\Car Project\Car.java:54: error: cannot find symbol
int cols = gr.getNumCols;
^
symbol: variable getNumCols
location: variable gr of type Grid<Actor>
1 error
Process completed.
# 1 楼答案
你错过了这里的偏执
这一行应该是(假设实际上有一个方法
getNumCols()
):