为了我个人的娱乐目的,我写了我希望成为稍后游戏的基础。目前,我正在制作游戏“棋盘”。请考虑以下几点:使用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