コード例 #1
0
    private void DoNextGenerationStep(List <Cs_MazeCell> activeCells)
    {
        int         currentIndex = activeCells.Count - 1;
        Cs_MazeCell currentCell  = activeCells[currentIndex];

        if (currentCell.IsFullyInitialized)
        {
            activeCells.RemoveAt(currentIndex);
            return;
        }
        MazeDirection direction   = currentCell.RandomUninitializedDirection;
        intVector2    coordinates = currentCell.iCoordinates + direction.toIntVector2();

        if (ContainsCoordinates(coordinates))
        {
            Cs_MazeCell neighbor = GetCell(coordinates);
            if (neighbor == null)
            {
                neighbor = CreateCell(coordinates);
                CreatePassage(currentCell, neighbor, direction);
                activeCells.Add(neighbor);
            }
            else
            {
                CreateWall(currentCell, neighbor, direction);
            }
        }
        else
        {
            CreateWall(currentCell, null, direction);
        }
    }
コード例 #2
0
ファイル: Maze.cs プロジェクト: Energyslam/Maze-Generator
    private void DoNextGenerationStep(List <MazeCell> activeCells)
    {
        int currentIndex = returnIndex(activeCells); //returns the indextype for the algorithm

        MazeCell currentCell = activeCells[currentIndex];

        if (currentCell.isFullyInitizalized)
        {
            activeCells.RemoveAt(currentIndex); //removes cell from the list once fully initialized
            return;
        }

        MazeDirection direction   = currentCell.RandomUnitializedDirection;
        IntVector2    coordinates = currentCell.coordinates + direction.toIntVector2();

        if (ContainsCoordinates(coordinates) && GetCell(coordinates) == null) //if it's inside the limits of the field and target cell is empty
        {
            MazeCell neighbor = GetCell(coordinates);
            if (neighbor == null)
            {
                neighbor = CreateCell(coordinates);
                CreatePassage(currentCell, neighbor, direction);
                activeCells.Add(neighbor);
            }
        }
        else
        {
            CreateWall(currentCell, null, direction);
        }
    }