示例#1
0
 private void FullRefresh()
 {
     mainGrid.Children.Clear();
     mainGrid.ColumnDefinitions.Clear();
     mainGrid.RowDefinitions.Clear();
     for (Int32 x = 0; x < _maze.Width; x++)
     {
         mainGrid.ColumnDefinitions.Add(new ColumnDefinition());
     }
     for (Int32 y = 0; y < _maze.Height; y++)
     {
         mainGrid.RowDefinitions.Add(new RowDefinition());
     }
     for (Int32 x = 0; x < _maze.Width; x++)
     {
         for (Int32 y = 0; y < _maze.Height; y++)
         {
             var cell             = _maze[x, y];
             var imageElement     = new ElementFactory <Image>().Create().SetGridLocation(x, y);
             var backImageElement = new ElementFactory <Image>().Create().SetImageSource("images/empty.jpg").SetGridLocation(x, y);
             var empty            = cell as Empty;
             if (empty != null)
             {
                 imageElement.SetImageSource("images/empty.jpg");
             }
             var wall = cell as Wall;
             if (wall != null)
             {
                 imageElement.SetImageSource("images/wall.jpg");
             }
             var start = cell as Start;
             if (start != null)
             {
                 imageElement.SetImageSource("images/start.png");
                 backImageElement.AddToParent(mainGrid.Children);
             }
             var finish = cell as Finish;
             if (finish != null)
             {
                 imageElement.SetImageSource("images/finish.png");
                 backImageElement.AddToParent(mainGrid.Children);
             }
             var teleport = cell as Teleport;
             if (teleport != null)
             {
                 imageElement.SetImageSource(String.Format("images/teleport{0}.png", teleport.Address));
                 backImageElement.AddToParent(mainGrid.Children);
             }
             imageElement.AddToParent(mainGrid.Children);
             if (cell.Step.HasValue)
             {
                 var stepTextBlockElement = new ElementFactory <TextBlock>().Create()
                                            .SetGridLocation(x, y)
                                            .CenterInParent()
                                            .SetText(cell.Step.Value.ToString())
                                            //.BindCell(cell)
                                            .SetFont(40, 400, Brushes.White)
                                            .AddToParent(mainGrid.Children);
             }
         }
     }
 }