爲了我個人的娛樂目的,我寫了我希望成爲稍後遊戲的基礎。目前,我正在製作遊戲「棋盤」。請考慮以下幾點:使用LINQ從多維數組中選擇未知項目
class Board
{
private Cube[,,] gameBoard;
public Cube[, ,] GameBoard { get; }
private Random rnd;
private Person person;
public Person _Person { get; }
//default constructor
public Board()
{
person = new Person(this);
rnd = new Random();
gameBoard = new Cube[10, 10, 10];
gameBoard.Initialize();
int xAxis = rnd.Next(11);
int yAxis = rnd.Next(11);
int zAxis = rnd.Next(11);
gameBoard[xAxis, yAxis, zAxis].AddContents(person);
}
}
這:
class Person : IObject
{
public Board GameBoard {get; set;}
public int Size { get; set; }
public void Move()
{
throw new NotImplementedException();
}
public void Move(Cube startLocation, Cube endLocation)
{
startLocation.RemoveContents(this);
endLocation.AddContents(this);
}
public Person(Board gameBoard)
{
Size = 1;
GameBoard = gameBoard;
}
public int[] GetLocation()
{
int[] currentLocation;
var location =
from cubes in GameBoard.GameBoard
where cubes.GetContents.Contains(this)
select cubes;
}
}
我知道這是錯的,它可能甚至不好笑,但是這是最惡劣的粗剪的。
我試圖讓GetLocation
返回其中Person
所在的Cube
的特定索引。因此,如果該人在Board.GameBoard[1, 2, 10]
中,我將能夠檢索該位置(可能是上面列出的int[]
)。然而,在目前,我無法編譯由於以下錯誤:
Could not find an implementation of the query pattern for source type 'Cubes.Cube[*,*,*]'. 'Where' not found.'
我敢肯定,LINQ應該能夠查詢多維數組,但我還沒有找到如何任何文件去做吧。
任何建議,或者我在這裏完全錯誤的軌道?
謝謝...我很害怕這一點。 然後我發現我只問了我需要答案的部分問題。哎呦。 – AllenG 2009-06-17 21:09:30