UWP开发:自动生成迷宫&自动寻路算法(2)

之后我们编写一个类,同时创建一个List,将List与前端的Rectangle绑定。

public static List<Rect> Rects { get; set; }
Rects = new List<Rect>();
 public class Rect
        {
            public int X { get; set; }
            public int Y { get; set; }//以左上角为1,1
            public string Color { get; set; }
        }
for (int x = 0; x < 325; x++)//25*14
            {
                var rect = new Rect() { X = x / 25, Y = x % 25 };
                switch (mazeMap[rect.X + 1, rect.Y + 1]) {
                    case 0:
                        rect.Color = "Blue";
                        break;
                    case 1:
                        rect.Color = "Gray";
                        break;
                    case 2:
                        rect.Color = "Red";
                        break;
                }
                Rects.Add(rect);
            }
            GridView.ItemsSource = Rects;

这里的代码,处理了方块的排布,根据mazeMap这个二维数组存储的数据,来进行Rect对象的颜色变换。

同时绑定了ItemSource,将325个方块装填到Rects类中。

======================================

之后我们就要开始编写mazeMap的生成了。

 

posted @ 2016-11-25 13:08  ldzhangyx  阅读(411)  评论(0编辑  收藏  举报