Exemple #1
0
    private void DoNextGenerationStep(List <MazeCell> activeCells)
    {
        int      index = activeCells.Count - 1;
        MazeCell cell  = activeCells[index];

        if (cell.IsFullyInitialized)
        {
            activeCells.RemoveAt(index);
            return;
        }

        //MazeDirection direction = MazeDirections.RandomValue;
        MazeDirection direction   = cell.RandomUnitializedDirection;
        IntVector2    coordinates = cell.coordinates + direction.ConvertToIntVector2();

        if (this.ContainsCoordinates(coordinates) /*&& this.GetCell(coordinates) == null*/)
        {
            //activeCells.Add(this.CreateCell(coordinates));
            MazeCell neighbor = this.GetCell(coordinates);
            if (neighbor == null)
            {
                neighbor = this.CreateCell(coordinates);
                this.CreatePassage(cell, neighbor, direction);
                activeCells.Add(neighbor);
            }
            else
            {
                this.CreateWall(cell, neighbor, direction);
                //activeCells.RemoveAt(index);  //remove not needed
            }
        }
        else
        {
            this.CreateWall(cell, null, direction);
            //activeCells.RemoveAt(index);  //remote not needed
        }
    }