Esempio n. 1
0
        static void CleanupTunnel(IMapGrid map, int x, int y)
        {
            if (map.GetID(x, y) != MapGridTypes.ID.Tunnel && map.GetID(x, y) != MapGridTypes.ID.TunnelEnd)
                return;

            int tuncells = map.GetBCross(x, y).Count(e => e.Type == MapGridTypes.ID.Tunnel);
            int empty = map.GetBCross(x, y).Count (e => e.Type == MapGridTypes.ID.Empty || e.Type == MapGridTypes.ID.Blocked);

            if (tuncells != 1 || empty != 3)
                return;

            var all_dirs = Enum.GetValues (typeof(Direction)).Cast<Direction> ().ToList ();
            foreach (var dir in all_dirs) {
                map.SetID (x, y, MapGridTypes.ID.Empty);
                if (dir == Direction.Up) CleanupTunnel (map, x, y - 1);
                if (dir == Direction.Right) CleanupTunnel (map, x + 1, y);
                if (dir == Direction.Down) CleanupTunnel (map, x, y + 1);
                if (dir == Direction.Left) CleanupTunnel (map, x - 1, y);
            }
        }