예제 #1
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];
                }
            }
        }
예제 #2
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);
        }