【问题标题】:Create elements in loop and position them, from bottom left to upper right在循环中创建元素并定位它们,从左下角到右上角
【发布时间】:2021-04-22 16:13:55
【问题描述】:

我目前正在做一个国际象棋游戏,在绘制棋盘时遇到了一个问题:第一个元素在左上角,最后一个在右下角。

如何更改我的代码,以便在左下角生成第一个元素,在右上角生成最后一个元素?

我的代码:

 int l = -1;
 for (int x = 0; x < gridSize; x++)
 {
     for (int y = 0; y < gridSize; y++)
     {
         l++;
         points[l] = new Point(tileSize * x, tileSize * y); 
     }
 }

任何帮助将不胜感激!

【问题讨论】:

    标签: c# winforms for-loop object position


    【解决方案1】:

    将 y 循环更改为从最大值开始并向下工作。

    int l = -1;
    for (int x = 0; x < gridSize; x++)
    {
        for (int y = gridSize - 1; y >= 0; y--)
        {
            l++;
            points[l] = new Point(tileSize * x, tileSize * y); 
        }
    }
    

    这将上升到第一列,然后上升到第二列,依此类推,直到到达右上角。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-12
      • 2012-12-21
      • 1970-01-01
      • 1970-01-01
      • 2019-03-06
      • 1970-01-01
      • 1970-01-01
      • 2017-05-03
      相关资源
      最近更新 更多