Пример #1
0
        public void Dig(Point point)
        {
            MazeInformations.Map[point.X, point.Y] = SquareType.Free;

            if (point.X > 1)
            {
                if (MazeInformations.Map[point.X - 1, point.Y] == SquareType.Unknown)
                {
                    Point discoveredPoint = new Point(point.X - 1, point.Y);
                    Exposed.Add(discoveredPoint);
                }
            }

            if (point.X < MazeInformations.Height - 2)
            {
                if (MazeInformations.Map[point.X + 1, point.Y] == SquareType.Unknown)
                {
                    Point discoveredPoint = new Point(point.X + 1, point.Y);
                    Exposed.Add(discoveredPoint);
                }
            }

            if (point.Y > 1)
            {
                if (MazeInformations.Map[point.X, point.Y - 1] == SquareType.Unknown)
                {
                    Point discoveredPoint = new Point(point.X, point.Y - 1);
                    Exposed.Add(discoveredPoint);
                }
            }

            if (point.Y < MazeInformations.Width - 2)
            {
                if (MazeInformations.Map[point.X, point.Y + 1] == SquareType.Unknown)
                {
                    Point discoveredPoint = new Point(point.X, point.Y + 1);
                    Exposed.Add(discoveredPoint);
                }
            }

            if (point.X == MazeInformations.Height - 2)
            {
                CountToExit += 1;
                if (CountToExit == MazeInformations.Width / 2 - 1)
                {
                    MazeInformations.Map[point.X + 1, point.Y] = SquareType.Free;
                    this.MazeInformations.ExitPositionWidth    = point.Y;
                }
            }
        }
        internal ConfigurationElementCollection ForceLoad()
        {
            if (_initialized)
            {
                return(this);
            }

            _initialized = true;

            var duplicateElement    = GetParentElement();
            var duplicateCollection = duplicateElement?.GetCollection();

            if (duplicateCollection != null)
            {
                HasParent = true;

                // IMPORTANT: load duplicate element.
                foreach (ConfigurationElement element in duplicateCollection.Exposed)
                {
                    var newItem = CreateNewElement(element.ElementTagName);
                    Clone(element, newItem);
                    newItem.IsLocallyStored = false;
                    newItem.CloneSource     = element;
                    Exposed.Add(newItem);
                }

                return(this);
            }

            var parentElement    = FileContext.AppHost ? GetParentElement() : GetElementAtParentLocationInFileContext(FileContext.Parent);
            var parentCollection = parentElement?.GetCollection();

            if (parentCollection == null)
            {
                return(this);
            }

            HasParent = true;
            foreach (ConfigurationElement element in parentCollection.Exposed)
            {
                var newItem = CreateNewElement(element.ElementTagName);
                Clone(element, newItem);
                newItem.IsLocallyStored = false;
                newItem.CloneSource     = element;
                Exposed.Add(newItem);
            }

            return(this);
        }
        internal override void AddChild(ConfigurationElement child)
        {
            ForceLoad();
            if (Schema.CollectionSchema.ContainsAddElement(child.ElementTagName))
            {
                child.AppendToParentElement(child.Entity, false);
                Real.Add(child);
                if (HasParent && Schema.Path == "system.webServer/defaultDocument/files")
                {
                    var index = Real.Count == 0 ? 0 : Exposed.IndexOf(Real[Real.Count - 1]) + 1;
                    Exposed.Insert(index, child);
                }
                else
                {
                    Exposed.Add(child);
                }
            }
            else if (child.ElementTagName == Schema.CollectionSchema.ClearElementName)
            {
                child.AppendToParentElement(child.Entity, false);
                Real.Add(child);
                Exposed.Clear();
            }
            else if (child.ElementTagName == Schema.CollectionSchema.RemoveElementName)
            {
                child.AppendToParentElement(child.Entity, false);
                Real.Add(child);
                foreach (var item in Exposed.ToList())
                {
                    if (Match(item, child, Schema.CollectionSchema.RemoveSchema))
                    {
                        // IMPORTANT: can remove from location tag in the same file, but not from child web.config.
                        if (item.IsLocked == "true" && item.CloneSource?.FileContext != FileContext)
                        {
                            throw new FileLoadException($"Filename: \\\\?\\{FileContext.FileName}\r\nLine number: {(child.Entity as IXmlLineInfo).LineNumber}\r\nError: Lock violation\r\n\r\n");
                        }

                        Exposed.Remove(item);
                    }
                }
            }
            else
            {
                base.AddChild(child);
            }
        }
Пример #4
0
 internal override void AddChild(ConfigurationElement child)
 {
     ForceLoad();
     if (Schema.CollectionSchema.ContainsAddElement(child.ElementTagName))
     {
         child.AppendToParentElement(child.Entity, false);
         Real.Add(child);
         if (HasParent && Schema.Path == "system.webServer/defaultDocument/files")
         {
             var index = Real.Count == 0 ? 0 : Exposed.IndexOf(Real[Real.Count - 1]) + 1;
             Exposed.Insert(index, child);
         }
         else
         {
             Exposed.Add(child);
         }
     }
     else if (child.ElementTagName == Schema.CollectionSchema.ClearElementName)
     {
         child.AppendToParentElement(child.Entity, false);
         Real.Add(child);
         Exposed.Clear();
     }
     else if (child.ElementTagName == Schema.CollectionSchema.RemoveElementName)
     {
         child.AppendToParentElement(child.Entity, false);
         Real.Add(child);
         foreach (var item in Exposed.ToList())
         {
             if (Match(item, child, Schema.CollectionSchema.RemoveSchema))
             {
                 Exposed.Remove(item);
             }
         }
     }
     else
     {
         base.AddChild(child);
     }
 }
Пример #5
0
        public void Generate()
        {
            Random rnd = new Random();

            MazeInformations.Map[0, MazeInformations.EntryPositionWidth] = SquareType.Free;
            Point entryPoint = new Point(1, MazeInformations.EntryPositionWidth);

            Exposed.Add(entryPoint);

            while (Exposed.Any())
            {
                int rand = rnd.Next(Exposed.Count());

                Point point = Exposed[rand];

                if (Decide(point))
                {
                    Dig(point);
                }
                else
                {
                    MazeInformations.Map[point.X, point.Y] = SquareType.Wall;
                }
                Exposed.RemoveAt(rand);
            }

            for (int i = 0; i < MazeInformations.Height; i++)
            {
                for (int j = 0; j < MazeInformations.Width; j++)
                {
                    if (MazeInformations.Map[i, j] == SquareType.Unknown)
                    {
                        MazeInformations.Map[i, j] = SquareType.Wall;
                    }
                    ResolveMap[i, j] = MazeInformations.Map[i, j];
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Génère aléatoirement un nouveau labyrinthe
        /// </summary>
        /// <param name="length">Longueur du labyrinthe</param>
        /// <param name="width">Largeur du labyrinthe</param>
        /// <returns>Le labyrinthe généré</returns>
        public Maze Generate(int length, int width)
        {
            Random rnd = new Random();

            this.MazeInformations = new Maze
            {
                Map    = new MapType[length, width],
                Length = length,
                Width  = width,
                Entree = rnd.Next(1, width - 1)
            };

            for (int i = 0; i < MazeInformations.Length; i++)
            {
                for (int j = 0; j < MazeInformations.Width; j++)
                {
                    if (i == 0 || i == MazeInformations.Length - 1 || j == 0 || j == MazeInformations.Width - 1)
                    {
                        MazeInformations.Map[i, j] = MapType.Wall;
                    }
                    else
                    {
                        MazeInformations.Map[i, j] = MapType.Unknown;
                    }
                }
            }

            MazeInformations.Map[0, MazeInformations.Entree] = MapType.Free;
            Point entreePoint = new Point(1, MazeInformations.Entree);

            Exposed.Add(entreePoint);

            while (Exposed.Any())
            {
                int rand = rnd.Next(Exposed.Count());

                Point point = Exposed[rand];

                if (Decide(point))
                {
                    Dig(point);
                }
                else
                {
                    MazeInformations.Map[point.X, point.Y] = MapType.Wall;
                }
                Exposed.RemoveAt(rand);
            }

            for (int i = 0; i < MazeInformations.Length; i++)
            {
                for (int j = 0; j < MazeInformations.Width; j++)
                {
                    if (MazeInformations.Map[i, j] == MapType.Unknown)
                    {
                        MazeInformations.Map[i, j] = MapType.Wall;
                    }
                }
            }
            return(MazeInformations);
        }