【发布时间】:2014-10-24 16:54:57
【问题描述】:
我目前被困在我似乎无法弄清楚的部分任务中。它涉及我设置一个游戏板,使用一个 tablelayoutpanel 作为游戏板。
到目前为止,我已经在板上显示了“正方形”图块,但是图块(单元格)的顺序不是这样:
我需要在左下角显示开始磁贴,在右上角显示结束,中间的单元格按如下顺序显示:
与这部分相关的方法如下:
/////此方法使用“正方形”数组设置游戏板,(仍在进行中,但大部分已完成)
private void SetupGameBoard() {
for (int i = 0; i <= 41; i++) {
SquareControl squareCreate = new SquareControl(Board.Squares[i], null);
int coloumn = 0;
int row = 0;
MapSquareNumToScreenRowAndColumn(i, out coloumn, out row);
boardTableLayoutPanel.Controls.Add(squareCreate, coloumn, row);
}
}// SetupGameBaord
还有这个,
private static void MapSquareNumToScreenRowAndColumn(int squareNumber, out int rowNumber, out int columnNumber) {
// ######################## Add more code to this method and replace the next two lines by something more sensible. ###############################
rowNumber = 0; // Use 0 to make the compiler happy for now.
columnNumber = 0; // Use 0 to make the compiler happy for now.
}//end MapSquareNumToScreenRowAndColumn
到目前为止,我所掌握的是,在 MapSquareToScreenRowandcColumn 中,我需要进行计算来确定正方形的位置。
真的很想得到这方面的一些提示/建议/帮助/任何东西。
如果你们需要更多信息,请告诉我。
谢谢!
编辑:
所以我想出了一种方法,只是想知道一种更好的方法。在 MapSqauretoScreenRowandColumn 我放了这个小 if 语句只是为了测试:
if (squareNumber >= 0 && squareNumber <= 5) {
rowNumber = 6;
}
因此,如果 sqaurenumber 大于 0 且小于 5,则将其放置在右侧。我的问题是,有没有更好的方法来做这件事?而不是为此写一堆行,有没有办法在几行中做到这一点?
【问题讨论】:
标签: c# tablelayoutpanel