コード例 #1
0
 public void Initialize(MazeCell source, MazeCell sink, MazeDirection direction)
 {
     this.source    = source;
     this.sink      = sink;
     this.direction = direction.toCordinate();
     source.SetEdge(direction, this);
     transform.parent        = source.transform;
     transform.localPosition = Vector3.zero;
     transform.rotation      = direction.ToRotation();
 }
コード例 #2
0
    private void DoNextGenerationStep(List <MazeCell> activeCells)
    {
        /**
         * Add the new cell into the stack
         * if the cell cannot expand, remove it from the stack.
         * In this way to simulate a DFS process.
         */
        int      curIndex = activeCells.Count - 1;
        MazeCell curr     = activeCells[curIndex];

        if (curr.IsFullyInitialized) //This cell is fully initialized, remove it from stack.
        {
            activeCells.RemoveAt(curIndex);
            return;
        }
        MazeDirection direction = curr.RandomUninitializedDirection;
        Cordinate     cordinate = curr.cordinate + direction.toCordinate();

        if (WithinMazeScope(cordinate))
        {
            MazeCell neighbor = GetCell(cordinate);
            if (neighbor == null)
            {
                neighbor = CreateCell(cordinate);
                CreatePassage(curr, neighbor, direction);
                activeCells.Add(neighbor);
            }
            else
            {
                CreateWall(curr, neighbor, direction);
            }
        }
        else
        {
            CreateWall(curr, null, direction);
        }
    }