为了我个人的娱乐,我正在写我希望将成为以后游戏的基础的东西。目前,我正在开发游戏“棋盘”。请考虑以下几点:
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
返回 所在位置的特定Cube
索引Person
。这样,如果该人在,Board.GameBoard[1, 2, 10]
我将能够检索该位置(可能int[]
如上所述)。但是,目前,由于以下错误,我无法编译:
Could not find an implementation of the query pattern for source type 'Cubes.Cube[*,*,*]'. 'Where' not found.'
我很确定 LINQ 应该能够查询多维数组,但我还没有找到任何关于如何做到这一点的文档。
有什么建议,还是我在这里完全错误?