Exemplo n.º 1
0
 public MazeCreator(int width, int height)
 {
     Width  = width;
     Height = height;
     _rnd   = new Random();
     Maze   = new ECell[Height][];
     for (int i = 0; i < Height; i++)
     {
         Maze[i] = new ECell[Width];
         for (int j = 0; j < Width; j++)
         {
             Maze[i][j] = new ECell();
         }
     }
 }
Exemplo n.º 2
0
        private ECell[] CreateOneRow(int i, int[] right, int[] bot)
        {
            var temp = new ECell[Width];

            for (int c = 0; c < Width; c++)
            {
                temp[c] = new ECell();
            }

            for (int j = 0; j < Width; j++)
            {
                if (j != Width - 1 && j + 1 != right[j] && _rnd.NextDouble() < 0.5)
                {
                    temp[j].Right = false;

                    right[bot[j + 1]] = right[j];

                    bot[right[j]] = bot[j + 1];

                    right[j] = j + 1;

                    bot[j + 1] = j;
                }

                if (j != right[j] && _rnd.NextDouble() < 0.5)
                {
                    right[bot[j]] = right[j];

                    bot[right[j]] = bot[j];

                    right[j] = j;

                    bot[j] = j;
                }
                else
                {
                    temp[j].Bottom = false;
                }
            }
            return(temp);
        }
Exemplo n.º 3
0
        public ECell[][] Generate()
        {
            Maze = new ECell[Height][];
            for (int i = 0; i < Height; i++)
            {
                Maze[i] = new ECell[Width];
                for (int j = 0; j < Width; j++)
                {
                    Maze[i][j] = new ECell();
                }
            }

            var temp = new int[Width];
            var bot  = new int[Width];

            for (int i = 0; i < Width; i++)
            {
                temp[i] = i;
                bot[i]  = i;
            }

            for (int i = 0; i < Height - 1; i++)
            {
                for (int j = 0; j < Width; j++)
                {
                    if (j != Width - 1 && j + 1 != temp[j] && _rnd.NextDouble() < 0.5)
                    {
                        Maze[i][j].Right = false;

                        temp[bot[j + 1]] = temp[j];

                        bot[temp[j]] = bot[j + 1];

                        temp[j] = j + 1;

                        bot[j + 1] = j;
                    }

                    if (j != temp[j] && _rnd.NextDouble() < 0.5)
                    {
                        temp[bot[j]] = temp[j];

                        bot[temp[j]] = bot[j];

                        temp[j] = j;

                        bot[j] = j;
                    }
                    else
                    {
                        Maze[i][j].Bottom = false;
                    }
                }

                for (int c = 0; c < temp.Length; c++)
                {
                    Console.Write(temp[c] + "  ");
                }
                Console.WriteLine();
            }

            for (int j = 0; j < Width; j++)
            {
                if (j != Width - 1 && j + 1 != temp[j] && (j == temp[j] || _rnd.NextDouble() < 0.5))
                {
                    Maze.Last()[j].Right = false;

                    temp[bot[j + 1]] = temp[j];

                    bot[temp[j]] = bot[j + 1];

                    temp[j] = j + 1;

                    bot[j + 1] = j;
                }
                temp[bot[j]] = temp[j];

                bot[temp[j]] = bot[j];

                temp[j] = j;

                bot[j] = j;
            }
            if (Console.ReadKey().Key == ConsoleKey.W)
            {
                PrintWithOutNumbers(0, Height, Maze);
            }
            return(Maze);
        }