2014-03-04 77 views
0

我想使用this website作爲幫助,但代碼似乎不工作了,所以我正在修復它,現在我得到一個C#標識符預期錯誤C#XNA標識符預計

public Point PickRandomCellAndMarkItVisited() 
{ 
    Random rnd = new Random(); 
    Point randomLocation = new Point(rnd.Next(1, 10), rnd.Next(1, 10)); 
    this.[randomLocation] = true; 
    return randomLocation; 
} 
+3

'this。[randomLocation] = true;'是無效的代碼。你可能的意思是'this [randomLocation] = true;'請注意,在你連接的代碼中,'PickRandomCellAndMarkItVisited'方法在'this'之後沒有'.' ... –

回答

0

根據你的代碼和tutorial,它看起來像你試圖將隨機單元格標記爲已訪問。我想你應該試試這個:

public class Map 
{ 

    private readonly bool[, ] cells;  
    public Point PickRandomCellAndMarkItVisited() 
    { 
     Random rnd = new Random(); 
     Point randomLocation = new Point(rnd.Next(1, 10), rnd.Next(1, 10)); 
     this.cells[randomLocation.X, randomLocation.Y] = true; 
     return randomLocation; 
    } 
} 

這將從網格中選取一個隨機單元格,並將相應的布爾值標記爲true。

+0

那麼爲什麼會有類索引器呢? :) – Krekkon

+0

不再有任何錯誤,所以可能已經奏效,謝謝! –

+0

當然!很高興幫助。 @Krekkon,我不確定爲什麼本教程的作者補充說。國際海事組織,只要使用'this.cells'甚至'cells [,]''會更容易。 – davidsbro