之后我们编写一个类,同时创建一个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 = ; x < ; x++)//25*14
{
var rect = new Rect() { X = x / , Y = x % };
switch (mazeMap[rect.X + , rect.Y + ]) {
case :
rect.Color = "Blue";
break;
case :
rect.Color = "Gray";
break;
case :
rect.Color = "Red";
break;
}
Rects.Add(rect);
}
GridView.ItemsSource = Rects;

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

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

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

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

05-14 01:23