public void DestroyByFlood() { var area = GetArea(); var field = new CityField(area); while (true) { Boolean wasFlood = false; for (Int32 x = area.Left; x < area.Left + area.Width; x++) { for (Int32 y = area.Y - area.Height; y < area.Y; y++) { if (field[x, y]) { continue; } if (field.CanFill(x, y, Walls)) { field.FillCell(x, y); wasFlood = true; } } } if (!wasFlood) { var walls = FindAllFloodedWalls(field); if (walls == null || walls.Count == 0) { return; } var nodes = walls.GetAllNodes().ToList(); var nodeInfoList = new NodeInfoList(nodes.Select(n => new NodeInfo(n, walls))); var wallsOfEnclosedSpace = nodeInfoList.FindWallsOfEnclosedSpace().ToList(); if (wallsOfEnclosedSpace.Count == 0) { return; } wallsOfEnclosedSpace.ForEach(w => Walls.Remove(w)); } } }
private Walls FindAllFloodedWalls(CityField field) => new Walls(Walls.FindAll(wall => field.IsFlooded(wall)));