Exemplo n.º 1
0
    IEnumerator GenerateSteps()
    {
        if (randomPosition)
        {
            startPosition = new Vector2Int(Random.Range(0, size.x), Random.Range(0, size.y));
        }

        var growingTree = new GrowingTree(size, startPosition, nextCandidate);

        growingTree.OnVisit += (pos) =>
        {
            blocks[pos.x, pos.y].sharedMaterial = (startPosition == pos ? startMaterial : candidateMaterial);
        };
        growingTree.OnDeadEnd      += (pos) => blocks[pos.x, pos.y].sharedMaterial = corridorMaterial;
        growingTree.OnCarvePassage += RemoveWall;

        growingTree.Start();
        while (!growingTree.Finished)
        {
            growingTree.Step();
            yield return(stepWait);
        }

        maze                  = growingTree.Maze;
        generator             = null;
        btnWalk.interactable  = true;
        btnStart.interactable = true;
    }
Exemplo n.º 2
0
        static G RandomAlgorithm <G, T>(Grid grid, Algorithm algorithm) where G : Grid where T : Cell
        {
            switch (algorithm)
            {
            case Algorithm.AldousBroder: return(AldousBroder.CreateMaze <G, T>(grid as G));

            case Algorithm.BinaryTree: return(BinaryTree.CreateMaze(grid) as G);

            case Algorithm.HuntAndKill: return(HuntAndKill.CreateMaze <G, T>(grid as G));

            case Algorithm.RecursiveBacktracker: return(RecursiveBacktracker.CreateMaze <G, T>(grid as G));

            case Algorithm.Sidewinder: return(Sidewinder.CreateMaze(grid) as G);

            case Algorithm.Wilsons: return(Wilsons.CreateMaze <G, T>(grid as G));

            case Algorithm.Kruskals: return(Kruskals.CreateMaze(grid) as G);

            case Algorithm.Prims: return(Prims.CreateMaze <G, T>(grid as G));

            case Algorithm.TruePrims: return(TruePrims.CreateMaze <G, T>(grid as G));

            case Algorithm.GrowingTree: return(GrowingTree.CreateMaze <G, T>(grid as G));

            case Algorithm.RecursiveDivision: return(RecursiveDivision.CreateMaze(grid) as G);

            case Algorithm.Ellers: return(Ellers.CreateMaze(grid) as G);

            case Algorithm.Houstons: return(Houstons.CreateMaze <G, T>(grid as G));
            }
            return(null);
        }
Exemplo n.º 3
0
    public static Dictionary <GridPosition, MazeNode> Create(EGTVariant Variant, GridPosition Origin, int Width, int Height)
    {
        GrowingTree Generator = new GrowingTree(Variant, Origin, Width, Height);

        Generator.BuildMaze();

        return(Generator.m_NodeList);
    }
Exemplo n.º 4
0
        public void TestGrowingTreeColored()
        {
            var coloredGrid = new ColoredGrid(25, 25);

            GrowingTree.On(coloredGrid);
            coloredGrid.Distances = coloredGrid.GetCenterCell().Distances;
            coloredGrid.ToBitmap().Save("growingtree-colored.png");
        }
Exemplo n.º 5
0
    public void StartGame(int inputRows, int inputCols)
    {
        size.r = inputRows;
        size.c = inputCols;

        mazeInstance = Instantiate(mazePrefab) as GrowingTree;
        StartCoroutine(mazeInstance.InstatiateMaze());
    }
Exemplo n.º 6
0
    private void Generate()
    {
        Debug.Log(m_Origin.ToString());

        switch (m_Algorithm)
        {
        case EMazeAlgorithm.CELLULAR_AUTOMATA:
            m_NodeMap = CellularAutomata.Create(m_Origin, m_Width, m_Height);
            break;

        case EMazeAlgorithm.GROWING_TREE:
            m_NodeMap = GrowingTree.Create(m_Origin, m_Width, m_Height);
            break;

        case EMazeAlgorithm.SIMPLE:
            m_NodeMap = CreateSimpleSector();
            break;
        }
    }
Exemplo n.º 7
0
        public void TestGrowingTree()
        {
            var grid = new Grid(5, 5);

            GrowingTree.On(grid).ToBitmap().Save("growingtree.png");
        }