Exemplo n.º 1
0
    private void DoNextGenerationStep(List <MazeCell> activeCells)
    {
        //get last cell in active list
        int      currentIndex = activeCells.Count - 1;
        MazeCell currentCell  = activeCells[currentIndex];

        //remove fullyInitialized cell
        if (currentCell.IsFullyInitialized)
        {
            activeCells.RemoveAt(currentIndex);
            return;
        }
        //go random direction
        MazeDirection direction = currentCell.RandomUninitializedDirection;
        IntVector3    coord     = currentCell.coord + direction.ToIntVector3();

        //is coord in grid?
        if (ContainsCoord(coord))
        {
            MazeCell neighbor = GetCell(coord);
            //is coord visited?
            if (neighbor == null)
            {
                neighbor = CreateCell(coord);
                CreatePassage(currentCell, neighbor, direction);
                activeCells.Add(neighbor);
            }
            else
            {
                //wall probability
                if (Random.value < wallProbability)
                {
                    CreateWall(currentCell, neighbor, direction);
                }
                else
                {
                    CreatePassage(currentCell, neighbor, direction);
                }
            }
        }
        else
        {
            CreateWall(currentCell, null, direction);
        }
    }