Esempio n. 1
0
    // SELECT NEIGHBOR
    // ***************
    // function picks a random cell from
    // the neighborList. It then determines
    // which wall to destroy for the previous
    // cell to access the new cell. The function
    // then pushes the new cell on top of the stack.
    void SelectNeighbor(FormGrid.Cell[,] grid, FormGrid.Cell _cell)
    {
        int randNeighbor = Random.Range(0, neighborList.Count);

        FormGrid.Cell _nextCell = neighborList [randNeighbor];

        // if North neighbor
        if (_nextCell.row > _cell.row)
        {
            Destroy(grid [_cell.row, _cell.col].northWall);

            // if South neighbor
        }
        else if (_nextCell.row < _cell.row)
        {
            Destroy(grid [(_cell.row - 1), _cell.col].northWall);

            // if East Neighbor
        }
        else if (_nextCell.col > _cell.col)
        {
            Destroy(grid [_cell.row, _cell.col].eastWall);

            // if West Neighbor
        }
        else if (_nextCell.col < _cell.col)
        {
            Destroy(grid [_cell.row, (_cell.col - 1)].eastWall);
        }

        gridStack.Push(_nextCell);
    }
Esempio n. 2
0
    // CHECK NEIGHBOR
    // **************
    // function is passed the array and the cell
    // to be checked. It calls CheckVisited to see
    // if the neighbor of the cell has been visited.
    // The function then determines whether to add
    // it to the list.
    void CheckNeighbor(FormGrid.Cell[,] grid, FormGrid.Cell _cell)
    {
        bool checkW = CheckVisited(grid, (_cell.row - 1), _cell.col);
        bool checkE = CheckVisited(grid, (_cell.row + 1), _cell.col);
        bool checkS = CheckVisited(grid, _cell.row, (_cell.col - 1));
        bool checkN = CheckVisited(grid, _cell.row, (_cell.col + 1));

        // check W neighbor
        if (!checkW)
        {
            neighborList.Add(grid [(_cell.row - 1), _cell.col]);
        }

        // check E neighbor
        if (!checkE)
        {
            neighborList.Add(grid [(_cell.row + 1), _cell.col]);
        }

        // check S neighbor
        if (!checkS)
        {
            neighborList.Add(grid [_cell.row, (_cell.col - 1)]);
        }

        // check N neighbor
        if (!checkN)
        {
            neighborList.Add(grid [_cell.row, (_cell.col + 1)]);
        }

        //Debug.Log (neighborList.Count);
    }