Esempio n. 1
0
        public IEnumerator RandomTraversal(Action <Edge> onDrawEdge, Action onPause)
        {
            int count = 0;

            while (edges.Count > 0)
            {
                Edge passage = edges.PopRandom();

                if (maze[passage.exit] == Directions.None)
                {
                    maze.AddEdge(passage);
                    edges.AddRange(maze.GetEdges(passage.exit));

                    onDrawEdge(passage);

                    // Pause generation to show current results
                    count++;
                    if (count > pauseStep)
                    {
                        count = 0;
                        onPause();
                        yield return(null);
                    }
                }
            }
        }
Esempio n. 2
0
        private void RandomTraversal()
        {
            Edge passage = edges.PopRandom();

            if (maze[passage.exit] == Directions.None)
            {
                maze.AddEdge(passage);
                edges.AddRange(maze.GetEdges(passage.exit));

                config.drawEdge(passage);
            }
        }
Esempio n. 3
0
        private IEnumerator RandomTraversal()
        {
            int count = 0;

            while (edges.Count > 0)
            {
                var passage = edges.PopRandom();

                if (maze[passage.exit] == Directions.None)
                {
                    maze.AddEdge(passage);
                    edges.AddRange(maze.GetEdges(passage.exit));

                    DrawEdge(passage);
                    count++;
                    if (count > drawStep)
                    {
                        count = 0;
                        texture.Apply();
                        yield return(null);
                    }
                }
            }
        }
Esempio n. 4
0
        public MazeGenerator(int mazeWidth, int mazeHeight, int cellSize, int wallSize, int pauseStep = 200)
        {
            int cellWidth = (mazeWidth - wallSize)/(cellSize + wallSize);
            int cellHeight = (mazeHeight - wallSize)/(cellSize + wallSize);
            maze = new Maze(cellWidth, cellHeight);

            var origin = new Cell
            {
                x = Random.Range(0, cellWidth),
                y = Random.Range(0, cellHeight)
            };
            maze[origin] = Directions.None;
            edges = new List<Edge>(maze.GetEdges(origin));

            this.pauseStep = pauseStep;
        }
Esempio n. 5
0
        public MazeGenerator(Config config)
        {
            this.config = config;
            int widthInCells  = (config.mazeWidth - config.wallSize) / (config.cellSize + config.wallSize);
            int heightInCells = (config.mazeHeight - config.wallSize) / (config.cellSize + config.wallSize);

            maze = new Maze(widthInCells, heightInCells);

            var origin = new Cell
            {
                x = Random.Range(0, widthInCells),
                y = Random.Range(0, heightInCells)
            };

            maze[origin] = Directions.None;
            edges        = new List <Edge>(maze.GetEdges(origin));
        }
Esempio n. 6
0
        private IEnumerator GenerateCoroutine()
        {
            texture = new Texture2D(mazeWidth, mazeHeight, TextureFormat.ARGB32, false, true)
            {
                filterMode = FilterMode.Point
            };
            cellWidth  = (mazeWidth - cellWallSize) / (cellSize + cellWallSize);
            cellHeight = (mazeHeight - cellWallSize) / (cellSize + cellWallSize);
            maze       = new Maze(cellWidth, cellHeight);

            var origin = new Cell {
                x = Random.Range(0, cellWidth), y = Random.Range(0, cellHeight)
            };

            maze[origin] = Directions.None;
            edges        = new List <Edge>(maze.GetEdges(origin));

            texture.Clear(Color.black);
            yield return(null);

            switch (mazeAlgorithm)
            {
            case MazeAlgorithm.None:
                if (RandomE.Chance(0.5f))
                {
                    yield return(StartCoroutine(RandomTraversal()));
                }
                else
                {
                    yield return(StartCoroutine(RandomDepthFirstTraversal()));
                }
                break;

            case MazeAlgorithm.RandomTraversal:
                yield return(StartCoroutine(RandomTraversal()));

                break;

            case MazeAlgorithm.RandomDepthFirstTraversal:
                yield return(StartCoroutine(RandomDepthFirstTraversal()));

                break;
            }

            texture.Apply();
        }
Esempio n. 7
0
        public MazeGenerator(int mazeWidth, int mazeHeight, int cellSize, int wallSize, int pauseStep = 200)
        {
            int cellWidth  = (mazeWidth - wallSize) / (cellSize + wallSize);
            int cellHeight = (mazeHeight - wallSize) / (cellSize + wallSize);

            maze = new Maze(cellWidth, cellHeight);

            var origin = new Cell
            {
                x = Random.Range(0, cellWidth),
                y = Random.Range(0, cellHeight)
            };

            maze[origin] = Directions.None;
            edges        = new List <Edge>(maze.GetEdges(origin));

            this.pauseStep = pauseStep;
        }
Esempio n. 8
0
        private IEnumerator GenerateCoroutine()
        {
            texture = new Texture2D(mazeWidth, mazeHeight, TextureFormat.ARGB32, false, true)
            {
                filterMode = FilterMode.Point
            };
            cellWidth = (mazeWidth - cellWallSize)/(cellSize + cellWallSize);
            cellHeight = (mazeHeight - cellWallSize)/(cellSize + cellWallSize);
            maze = new Maze(cellWidth, cellHeight);

            var origin = new Cell {x = Random.Range(0, cellWidth), y = Random.Range(0, cellHeight)};
            maze[origin] = Directions.None;
            edges = new List<Edge>(maze.GetEdges(origin));

            texture.Clear(Color.black);
            yield return null;

            switch (mazeAlgorithm)
            {
                case MazeAlgorithm.None:
                    if (RandomE.Chance(0.5f))
                    {
                        yield return StartCoroutine(RandomTraversal());
                    }
                    else
                    {
                        yield return StartCoroutine(RandomDepthFirstTraversal());
                    }
                    break;
                case MazeAlgorithm.RandomTraversal:
                    yield return StartCoroutine(RandomTraversal());
                    break;
                case MazeAlgorithm.RandomDepthFirstTraversal:
                    yield return StartCoroutine(RandomDepthFirstTraversal());
                    break;
            }

            texture.Apply();
        }