【发布时间】:2015-12-09 19:27:14
【问题描述】:
在我正在构建的游戏引擎中(为了好玩),开发人员可以创建地牢,其中包含地牢楼层的 1 维数组,而地牢楼层又包含房间的 2 维数组。
每个楼层都可以从其他楼层偏移,(例如,让楼层居中),我想修改 get() 数组的 rooms 以便垂直对齐的楼层将具有相同的(每floor) 坐标,与两个楼层的大小和偏移量无关。
例如,想象一个 5 * 5 大小的地牢地板。它上面的楼层是 3 * 3。二楼偏移 (1, 1),这意味着如果我调用 dungeon.floors[0].rooms[2, 2] 和 dungeon.floors[1].rooms[2,2],我应该检索两个直接在彼此上方/下方的房间。
floor 1 floor 0 floor 1 with offset
■ ■ ■ ■ ■ ■ ■ ■ X X X X
■ O ■ ■ ■ ■ ■ ■ X ■ ■ ■
■ ■ ■ ■ ■ O ■ ■ X ■ O ■
■ ■ ■ ■ ■ X ■ ■ ■
■ ■ ■ ■ ■
Drawn diagram of the above example, the circle represents the room that should be selected.
The Xs in the last plan show how the offset should be 'visualised'.
Note the selected rooms overlap should floor 0 and floor 1 with offset be overlaid.
下面是工作代码,省略了方法和不相关的细节。 我可以通过所描述的属性访问器来完成它,还是必须使用类索引器?
struct Offset
{
int x, y;
}
class Dungeon
{
public DungeonFloor[] floors { get; private set; }
public int Height { get; private set; }
}
class DungeonFloor
{
public int Width { get; private set; }
public int Height { get; private set; }
public Offset offset {get; private set;}
public Room[,] rooms {
get
{
//What do I put here??
//Is it even possible to access the index values in this context?
}
private set;
}
}
class Room { }
(我知道我可能会用对数组实际尺寸大小的调用来替换 Width/Height)
【问题讨论】:
标签: c# arrays properties game-engine