示例#1
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;
        }
示例#2
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();
        }