sve*_*vit 6 c# data-structures
我想创建一个组件,它由一块板和它的周围角落组成.板的大小(因此也是边界的大小)在运行时定义.一些例子(板子很亮,边框很暗): 替代文字http://img340.imageshack.us/img340/3862/examplegw.png
该板由BoardCell类型的对象组成,边框由BorderCell类型的对象组成.电路板的数据结构是BoardCell [,] - 一个简单的二维数组.
我怎样才能代表边界?我从这样的事情开始:
public BorderCell TopLeft // top left corner cell
public BorderCell TopRight // top right corner cell
public BorderCell BottomRight // bottom right corner cell
public BorderCell BottomLeft // bottom left corner cell
public BorderCell[] Top // top border (without corners)
public BorderCell[] Bottom // bottom border (without corners)
public BorderCell[] Left // left border (without corners)
public BorderCell[] Right // right border (without corners)
Run Code Online (Sandbox Code Playgroud)
我不喜欢这种边界的表现,你能提出更好的建议吗?
附加:我想在边框对象上有一个方法SetSomethingForTheCell:
public void SetSomethingForTheCell(...)
Run Code Online (Sandbox Code Playgroud)
但是根据我目前的数据结构,我不知道该作为参数传递什么.
由于检测单元格是否属于边界的一部分确实很简单,因此只需将单元格存储一次并在需要时测试边界成员资格即可。
测试单元格是否在边框内的简单方法:
// assuming that the array is in row-major order...
public static bool IsInBorder(this BoardCell[,] board, int x, int y) {
return x == board.GetLowerBound(1) || x == board.GetUpperBound(1) ||
y == board.GetLowerBound(0) || y == board.GetUpperBound(0);
}
Run Code Online (Sandbox Code Playgroud)