public void Redraw(MapTile tile) { var panel = Parent; Parent.Children.Remove(_path); tile.Processed = null; _tiles.Remove(tile); var allTiles = _tiles.OrderBy(x => x.Y).ThenBy(x => x.X).Select(x => { x.Processed = null; return(x); }).ToList(); _tiles.Clear(); var current = allTiles.FirstOrDefault(x => x.Processed == null); while (current != null) { if (Create(_map, current)) { var newWall = new WallRender(_map, _wallType); panel.Children.Insert(0, newWall.Render(current)); } current = allTiles.FirstOrDefault(x => x.Processed == null); } }
public static bool Create(AntRunner.Models.Map map, MapTile tile) { var checker = new WallRender(map, tile.Item); var sides = new[] { new KeyValuePair <TileSide, MapTile>(TileSide.Left, checker.Left(tile, true)), new KeyValuePair <TileSide, MapTile>(TileSide.Right, checker.Right(tile, true)), new KeyValuePair <TileSide, MapTile>(TileSide.Bottom, checker.Down(tile, true)), new KeyValuePair <TileSide, MapTile>(TileSide.Top, checker.Up(tile, true)) }.Where(x => x.Value != null).ToArray(); if (sides.All(x => x.Value.Item == tile.Item)) { var first = sides.Select(x => x.Value).FirstOrDefault(x => x.Processed != null); if (first != null) { first.Processed.AddTile(tile); return(false); } return(true); } var group = sides.FirstOrDefault(x => x.Value.Item == tile.Item && x.Value.Processed != null); if (group.Value == null) { return(true); } var startTile = sides.FirstOrDefault(x => x.Value.Item != tile.Item); group.Value.Processed.Combine(tile, startTile.Key); return(false); }