我很难为网格上的列数分配变量。我实例化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.
最佳答案
int cols = gr.getNumCols;
您在这里错过了偏执狂。
此行应该是(假设实际上有一个方法getNumCols()
):
int cols = gr.getNumCols();
关于java - 网格世界为cols数量分配变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8371202/