我目前停留在我的任务的一部分,我似乎无法弄清楚。它涉及到我建立一个游戏板,使用tablelayoutpanel作为游戏板。按照特定的顺序在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,其放在右排。我的问题是,有没有更好的方法来做到这一点?而不是为此写一连串的线,有几种方法可以做到这一点?
感谢您的回复,但是我放置它们的顺序真的很重要吗?我认为这将有更多的与MapSquareNumtoScreen(等..)的实际计算 – user3496101 2014-10-17 03:43:48
另外,请查看我在OP编辑,谢谢! – user3496101 2014-10-17 03:54:19
@ user3496101我在代码中看不到如何计算列和行值。但我的回答是处理你正在混合你的列和行的事实。我认为只有两个循环会更容易:'fox y = 0到rows,然后是x = 0到columns'。 – LarsTech 2014-10-17 13:12:47