public List <MapSection> GetMapSections() { foreach (Cell cell in _map.GetAllCells()) { if (!cell.IsWalkable) { continue; } bool foundSection = false; foreach (MapSection mapSection in _mapSections) { Path shortestPath = null; try { shortestPath = _pathFinder.ShortestPath(cell, mapSection.Cells.First()); } catch (PathNotFoundException) { } if (shortestPath != null) { mapSection.AddCell(cell); foundSection = true; break; } } if (!foundSection) { var mapSection = new MapSection(); mapSection.AddCell(cell); _mapSections.Add(mapSection); } } return(_mapSections); }
private static int DistanceBetween(MapSection startMapSection, MapSection destinationMapSection) { return(Math.Abs(startMapSection.Bounds.Center.X - destinationMapSection.Bounds.Center.X) + Math.Abs(startMapSection.Bounds.Center.Y - destinationMapSection.Bounds.Center.Y)); }