using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using UnityEngine; namespace GUI_Scripts.ProceduralGeneration { public class FloodFill : GraphNode { private Map map; private List queue = new List(); public FloodFill(Map map, int id, Vector2Int startPosition) { this.map = map; this.id = id; queue.Add(startPosition); } public bool Fill() { while (queue.Count > 0) { Vector2Int posiiton = queue[0]; queue.RemoveAt(0); if (map.tiles.ContainsKey(posiiton) && map.tiles[posiiton] == 0) { map.tiles[posiiton] = id; positions.Add(posiiton); foreach (var dir in Directions2D) { if (map.tiles.ContainsKey(posiiton + dir) && !positions.Contains(posiiton+dir)) { queue.Add(posiiton+dir); } } break; } } return queue.Count == 0; } public static readonly Vector2Int[] Directions2D = new Vector2Int[] { Vector2Int.left, Vector2Int.right, Vector2Int.up, Vector2Int.down, }; } }