private static void PopulateMaze(Maze maze, Random rand, int numCells)
        {
            Stack <MazeCell> cellStack = new Stack <MazeCell>();
            int      x    = rand.Next(0, numCells);
            int      y    = rand.Next(0, numCells);
            MazeCell cell = maze.GetCell(x, y);

            MazeBuilder.VisitCell(cell, cellStack, maze, rand);
        }
Esempio n. 2
0
        public MazeCell GetNextNeighbour(MazeCell cell, Random rand)
        {
            List <MazeCell> list = new List <MazeCell>();

            if (cell.X > 0 && !this.CellGrid[cell.X - 1][cell.Y].Visited)
            {
                list.Add(this.CellGrid[cell.X - 1][cell.Y]);
            }
            if (cell.X < this.CellGrid.Count - 1 && !this.CellGrid[cell.X + 1][cell.Y].Visited)
            {
                list.Add(this.CellGrid[cell.X + 1][cell.Y]);
            }
            if (cell.Y > 0 && !this.CellGrid[cell.X][cell.Y - 1].Visited)
            {
                list.Add(this.CellGrid[cell.X][cell.Y - 1]);
            }
            if (cell.Y < this.CellGrid[cell.X].Count - 1 && !this.CellGrid[cell.X][cell.Y + 1].Visited)
            {
                list.Add(this.CellGrid[cell.X][cell.Y + 1]);
            }
            if (list.Count > 0)
            {
                return(list[rand.Next(0, list.Count)]);
            }
            return(null);
        }