2011-12-04 37 views
1

我正在嘗試創建一個代碼,將演員移動到隨機位置,如果它是開放的。但是,我遇到了這條線產生的錯誤。GridWorld實驗室問題

if (null == get(loc)) 

基本上我以爲這條線會檢查位置是否打開。不過,我得到這個錯誤任何人都可以幫助?

F:\Lab III Car and Teleporter\Teleporter Project\TeleporterActor.java:42: error: cannot find symbol 
      if (null == get(loc)) 
         ^
    symbol: method get(Location) 
    location: class TeleporterActor 
1 error 

Process completed. 

public void act() 
    { 
     Location place = getLocation(); 
     Grid<Actor> gr = getGrid(); 
     int cols = gr.getNumRows(); 
     int rows = gr.getNumCols(); 
     do 
     { 
      Location loc = new Location((int)(Math.random() * rows - 1), (int)(Math.random() * cols - 1)); 
      if (null == get(loc)) 
       moveTo(loc);  
     } 
     while (place == getLocation()); 
    } 
+0

添加的方法定義'得到()'和'getLocation()'。 – MockerTim

回答

1

的錯誤意味着你沒有get方法在你TeleporterActor類,因此編譯器不知道你用get的意思。

要麼添加這樣一個方法,你TeleporterActor類,或稱之爲另一個對象,例如

gr.get(loc); 

,我假定get方法適用於您的Grid

+0

非常感謝! –