Esempio n. 1
0
    void CreateRoomsAndCorridors(int _numRooms, int _roomWidth, int _roomHeight, int _corridorLength)
    {
        Debug.Log("CreateRoomsAndCorridors 1");
        // Create the rooms array with a random size.
        m_Rooms = new List <CTRoom>();

        // There should be one less corridor than there is rooms.
        m_Corridors = new List <CTCorridor>();

        //0
        CTRoom startRoom = new CTRoom();

        m_Rooms.Add(startRoom);
        startRoom.SetupRoom(columns, rows, _roomWidth, _roomHeight, new CTRoomCoordinate(0, 0));
        CTCorridor start2mainCor = new CTCorridor();

        start2mainCor.SetupCorridor(startRoom, _corridorLength, Direction.NORTH);
        m_Corridors.Add(start2mainCor);
        startRoom.nextCorridors.Add(start2mainCor.direction, start2mainCor);

        //1
        CTRoom mainRoom = new CTRoom();

        m_Rooms.Add(mainRoom);
        mainRoom.SetupRoom(_roomWidth * 3, _roomHeight * 3, new CTRoomCoordinate(0, 1), start2mainCor);
        CTCorridor main2CPCor = new CTCorridor();

        main2CPCor.SetupCorridor(mainRoom, _corridorLength, Direction.NORTH);
        m_Corridors.Add(main2CPCor);
        mainRoom.nextCorridors.Add(main2CPCor.direction, main2CPCor);

        //2
        CTRoom checkPtRoom = new CTRoom();

        m_Rooms.Add(checkPtRoom);
        checkPtRoom.SetupRoom(_roomWidth, _roomHeight, new CTRoomCoordinate(0, 2), main2CPCor);
        CTCorridor CP2endCor = new CTCorridor();

        CP2endCor.SetupCorridor(checkPtRoom, _corridorLength, Direction.NORTH);
        m_Corridors.Add(CP2endCor);
        checkPtRoom.nextCorridors.Add(CP2endCor.direction, CP2endCor);

        //3
        CTRoom endRoom = new CTRoom();

        m_Rooms.Add(endRoom);
        endRoom.SetupRoom(_roomWidth, _roomHeight, new CTRoomCoordinate(0, 3), CP2endCor);
        Debug.Log("CreateRoomsAndCorridors 2");
    }
Esempio n. 2
0
    public void SetupRoom(int _width, int _height, CTRoomCoordinate _coordinate, CTCorridor _prevCorridor = null)
    {
        roomWidth  = _width;
        roomHeight = _height;
        coordinate = new CTRoomCoordinate(_coordinate);

        if (_prevCorridor == null)
        {
            firstRoom    = true;
            xPos         = (int)(_width * 0.5f);
            yPos         = (int)(_height * 0.5f);
            prevCorridor = Direction.Size;
        }
        else
        {
            firstRoom = false;

            switch (_prevCorridor.direction)
            {
            case Direction.NORTH:
                xPos = _prevCorridor.EndPositionX - (roomWidth / 2);
                yPos = _prevCorridor.EndPositionY + 1;
                break;

            case Direction.EAST:
                xPos = _prevCorridor.EndPositionX + 1;
                yPos = _prevCorridor.EndPositionY - (roomHeight / 2);
                break;

            case Direction.SOUTH:
                xPos = _prevCorridor.EndPositionX - (roomWidth / 2);
                yPos = _prevCorridor.EndPositionY - roomHeight;
                break;

            case Direction.WEST:
                xPos = _prevCorridor.EndPositionX - roomWidth;
                yPos = _prevCorridor.EndPositionY - (roomHeight / 2);
                break;
            }
            _prevCorridor.connectedTo = true;
        }

        // room created successfully!
        generated = true;
    }
Esempio n. 3
0
    void SetTilesValuesForCorridors()
    {
        // Go through every corridor...
        for (int i = 0; i < m_Corridors.Count; ++i)
        {
            CTCorridor currentCorridor = m_Corridors[i];

            // and go through it's length.
            for (int j = 0; j < currentCorridor.corridorLength; ++j)
            {
                // Start the coordinates at the start of the corridor.
                int xCoord = currentCorridor.startXPos;
                int yCoord = currentCorridor.startYPos;

                // Depending on the direction, add or subtract from the appropriate
                // coordinate based on how far through the length the loop is.

                //Starting Corners
                if (j == 0)
                {
                    switch (currentCorridor.direction)
                    {
                    case Direction.NORTH:
                        yCoord += j;
                        m_Tiles[xCoord - 2][yCoord] = TileType.WallOuterCorner_Q2;
                        m_Tiles[xCoord + 2][yCoord] = TileType.WallOuterCorner_Q1;
                        m_Tiles[xCoord - 1][yCoord] = TileType.Floor;
                        m_Tiles[xCoord + 1][yCoord] = TileType.Floor;
                        break;

                    case Direction.EAST:
                        xCoord += j;
                        m_Tiles[xCoord][yCoord + 2] = TileType.WallOuterCorner_Q1;
                        m_Tiles[xCoord][yCoord - 2] = TileType.WallOuterCorner_Q4;
                        m_Tiles[xCoord][yCoord + 1] = TileType.Floor;
                        m_Tiles[xCoord][yCoord - 1] = TileType.Floor;
                        break;

                    case Direction.SOUTH:
                        yCoord -= j;
                        m_Tiles[xCoord - 2][yCoord] = TileType.WallOuterCorner_Q3;
                        m_Tiles[xCoord + 2][yCoord] = TileType.WallOuterCorner_Q4;
                        m_Tiles[xCoord - 1][yCoord] = TileType.Floor;
                        m_Tiles[xCoord + 1][yCoord] = TileType.Floor;
                        break;

                    case Direction.WEST:
                        xCoord -= j;
                        m_Tiles[xCoord][yCoord + 2] = TileType.WallOuterCorner_Q2;
                        m_Tiles[xCoord][yCoord - 2] = TileType.WallOuterCorner_Q3;
                        m_Tiles[xCoord][yCoord + 1] = TileType.Floor;
                        m_Tiles[xCoord][yCoord - 1] = TileType.Floor;
                        break;
                    }
                }
                //Ending Corner
                else if (j == currentCorridor.corridorLength - 1)
                {
                    switch (currentCorridor.direction)
                    {
                    case Direction.NORTH:
                        yCoord += j;
                        m_Tiles[xCoord - 2][yCoord] = TileType.WallOuterCorner_Q3;
                        m_Tiles[xCoord + 2][yCoord] = TileType.WallOuterCorner_Q4;
                        m_Tiles[xCoord - 1][yCoord] = TileType.Floor;
                        m_Tiles[xCoord + 1][yCoord] = TileType.Floor;
                        break;

                    case Direction.EAST:
                        xCoord += j;
                        m_Tiles[xCoord][yCoord + 2] = TileType.WallOuterCorner_Q2;
                        m_Tiles[xCoord][yCoord - 2] = TileType.WallOuterCorner_Q3;
                        m_Tiles[xCoord][yCoord + 1] = TileType.Floor;
                        m_Tiles[xCoord][yCoord - 1] = TileType.Floor;
                        break;

                    case Direction.SOUTH:
                        yCoord -= j;
                        m_Tiles[xCoord - 2][yCoord] = TileType.WallOuterCorner_Q2;
                        m_Tiles[xCoord + 2][yCoord] = TileType.WallOuterCorner_Q1;
                        m_Tiles[xCoord - 1][yCoord] = TileType.Floor;
                        m_Tiles[xCoord + 1][yCoord] = TileType.Floor;
                        break;

                    case Direction.WEST:
                        xCoord -= j;
                        m_Tiles[xCoord][yCoord + 2] = TileType.WallOuterCorner_Q1;
                        m_Tiles[xCoord][yCoord - 2] = TileType.WallOuterCorner_Q4;
                        m_Tiles[xCoord][yCoord + 1] = TileType.Floor;
                        m_Tiles[xCoord][yCoord - 1] = TileType.Floor;
                        break;
                    }
                }
                //Side walls
                else
                {
                    switch (currentCorridor.direction)
                    {
                    case Direction.NORTH:
                        yCoord += j;
                        m_Tiles[xCoord - 2][yCoord] = TileType.Wall_Left;
                        m_Tiles[xCoord + 2][yCoord] = TileType.Wall_Right;
                        m_Tiles[xCoord - 1][yCoord] = TileType.Floor;
                        m_Tiles[xCoord + 1][yCoord] = TileType.Floor;
                        break;

                    case Direction.EAST:
                        xCoord += j;
                        m_Tiles[xCoord][yCoord + 2] = TileType.Wall_Up;
                        m_Tiles[xCoord][yCoord - 2] = TileType.Wall_Down;
                        m_Tiles[xCoord][yCoord + 1] = TileType.Floor;
                        m_Tiles[xCoord][yCoord - 1] = TileType.Floor;
                        break;

                    case Direction.SOUTH:
                        yCoord -= j;
                        m_Tiles[xCoord - 2][yCoord] = TileType.Wall_Left;
                        m_Tiles[xCoord + 2][yCoord] = TileType.Wall_Right;
                        m_Tiles[xCoord - 1][yCoord] = TileType.Floor;
                        m_Tiles[xCoord + 1][yCoord] = TileType.Floor;
                        break;

                    case Direction.WEST:
                        xCoord -= j;
                        m_Tiles[xCoord][yCoord + 2] = TileType.Wall_Up;
                        m_Tiles[xCoord][yCoord - 2] = TileType.Wall_Down;
                        m_Tiles[xCoord][yCoord + 1] = TileType.Floor;
                        m_Tiles[xCoord][yCoord - 1] = TileType.Floor;
                        break;
                    }
                }
                //Floor
                m_Tiles[xCoord][yCoord] = TileType.Floor;
            }
        }
    }
Esempio n. 4
0
    public int SetupAllRoom(int _boardWidth, int _boardHeight, int _roomWidth, int _roomHeight, int _corridorLength, CTRoomCoordinate _startingCoord,
                            int _maxRooms, ref bool[][] _gameBoard, ref List <CTRoom> _rooms, ref List <CTCorridor> _corridors)
    {
        /*********************
        * GENERATE 1st ROOM
        *********************/
        firstRoom = true;

        // Set a random width and height.
        roomDepth  = 0;
        roomWidth  = _roomWidth;
        roomHeight = _roomHeight;

        xPos = (int)(_boardWidth * 0.5f - roomWidth * 0.5f);
        yPos = (int)(_boardHeight * 0.5f - roomHeight * 0.5f);

        coordinate = new CTRoomCoordinate(_startingCoord);
        _gameBoard[coordinate.x][coordinate.y] = true;

        //set up pathnodes
        //pathnodes.Add(new CPathNode(CenterPoint.x, yPos + roomHeight, Direction.NORTH, this));
        //pathnodes.Add(new CPathNode(xPos, CenterPoint.y, Direction.WEST, this));
        //pathnodes.Add(new CPathNode(CenterPoint.x, yPos, Direction.SOUTH, this));
        //pathnodes.Add(new CPathNode(xPos + roomWidth, CenterPoint.y + roomWidth, Direction.EAST, this));

        generated = true;
        int currNumRooms = 1;   // 1st room

        //Debug.Log("CR_Count " + _rooms.Count + "  _numRooms: " + currNumRooms);
        //Debug.Log("Coord: " + coordinate.x + ", " + coordinate.y );

        // Create Next Corridors and pathnodes
        for (int i = 0; i < (int)Direction.Size; ++i)
        {
            //Create Corridors
            // Safety Check  if not, create a corridor for the room
            switch ((Direction)i)
            {
            case Direction.NORTH:
                //if the next room will be out of board
                if (coordinate.y + 1 < _gameBoard[0].Length)
                {
                    if (!_gameBoard[coordinate.x][coordinate.y + 1])
                    {
                        break;
                    }
                }
                continue;

            case Direction.SOUTH:
                if (coordinate.y - 1 >= 0)
                {
                    if (!_gameBoard[coordinate.x][coordinate.y - 1])
                    {
                        break;
                    }
                }
                continue;

            case Direction.EAST:
                if (coordinate.x + 1 < _gameBoard.Length)
                {
                    if (!_gameBoard[coordinate.x + 1][coordinate.y])
                    {
                        break;
                    }
                }
                continue;

            case Direction.WEST:
                if (coordinate.x - 1 >= 0)
                {
                    if (!_gameBoard[coordinate.x - 1][coordinate.y])
                    {
                        break;
                    }
                }
                continue;
            }

            CTCorridor newCor = new CTCorridor();
            newCor.SetupCorridor(this, _corridorLength, (Direction)i);
            _corridors.Add(newCor);
            nextCorridors.Add((Direction)i, newCor);
        }

        int availableRooms = nextCorridors.Count;

        // Create Next Room
        CTRoomCoordinate nextRoomCoord = new CTRoomCoordinate(0, 0);

        foreach (Direction nextdir in nextCorridors.Keys)
        {
            //if direction have a room alrdy base on the _gameboard, skip
            //if direction is same as previous corridor / corridors in list, skip
            //random a corridor except for north side and check if they got slot on gameboard
            switch (nextdir)
            {
            case Direction.NORTH:
                if (!_gameBoard[coordinate.x][coordinate.y + 1])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x, coordinate.y + 1);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_roomWidth, _roomHeight, nextRoomCoord, nextCorridors[nextdir], ref currNumRooms, ref availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, 0);
                }
                break;

            case Direction.EAST:
                if (!_gameBoard[coordinate.x + 1][coordinate.y])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x + 1, coordinate.y);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_roomWidth, _roomHeight, nextRoomCoord, nextCorridors[nextdir], ref currNumRooms, ref availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, 0);
                }
                break;

            case Direction.WEST:
                if (!_gameBoard[coordinate.x - 1][coordinate.y])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x - 1, coordinate.y);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_roomWidth, _roomHeight, nextRoomCoord, nextCorridors[nextdir], ref currNumRooms, ref availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, 0);
                }
                break;

            case Direction.SOUTH:
                if (!_gameBoard[coordinate.x][coordinate.y - 1])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x, coordinate.y - 1);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_roomWidth, _roomHeight, nextRoomCoord, nextCorridors[nextdir], ref currNumRooms, ref availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, 0);
                }
                break;
            }
        }

        //Check if its enough rooms
        while (currNumRooms < _maxRooms)
        {
            CreateEndRooms(_roomWidth, _roomHeight, _corridorLength, GetEndRooms(_rooms, _maxRooms / 4), ref currNumRooms, ref availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors);
        }

        return(currNumRooms);
    }
Esempio n. 5
0
    private void SetupEndRoom(int _width, int _height, int _corridorLength,
                              ref int _numRooms, ref int _availableRooms, ref int _maxRooms, ref bool[][] _gameBoard, ref List <CTRoom> _rooms, ref List <CTCorridor> _corridors)
    {
        //Safety measures
        if (nextCorridors.Count > 0)
        {
            return;
        }

        //Create Corridors
        GameObject node;
        int        startDir = Random.Range(0, (int)Direction.Size);

        for (int i = 0; i < (int)Direction.Size; ++i, ++startDir)
        {
            Direction nextDir = (Direction)(startDir % (int)Direction.Size);
            //if ((startDir % (int)Direction.Size) != (int)prevCorridor)
            {
                //Create Corridors
                if (Random.Range(0.0f, 1.0f) <= 0.5f - i * 0.1f)
                {
                    // Safety Check  if not, create a corridor for the room
                    switch (nextDir)
                    {
                    case Direction.NORTH:
                        if (coordinate.y + 1 < _gameBoard[0].Length)
                        {
                            if (!_gameBoard[coordinate.x][coordinate.y + 1])
                            {
                                node = Object.Instantiate(Resources.Load("Pathnode"), Vector3.zero, Quaternion.identity) as GameObject;
                                node.GetComponent <CPathNode>().Init(CenterPoint.x - 1, yPos + roomHeight - 1, PathNodeDir.NorthL, this);
                                pathnodes.Add(PathNodeDir.NorthL, node.GetComponent <CPathNode>());
                                node = Object.Instantiate(Resources.Load("Pathnode"), Vector3.zero, Quaternion.identity) as GameObject;
                                node.GetComponent <CPathNode>().Init(CenterPoint.x + 1, yPos + roomHeight - 1, PathNodeDir.NorthR, this);
                                pathnodes.Add(PathNodeDir.NorthR, node.GetComponent <CPathNode>());
                                break;
                            }
                        }
                        continue;

                    case Direction.SOUTH:
                        if (coordinate.y - 1 >= 0)
                        {
                            if (!_gameBoard[coordinate.x][coordinate.y - 1])
                            {
                                node = Object.Instantiate(Resources.Load("Pathnode"), Vector3.zero, Quaternion.identity) as GameObject;
                                node.GetComponent <CPathNode>().Init(CenterPoint.x - 1, yPos, PathNodeDir.SouthL, this);
                                pathnodes.Add(PathNodeDir.SouthL, node.GetComponent <CPathNode>());
                                node = Object.Instantiate(Resources.Load("Pathnode"), Vector3.zero, Quaternion.identity) as GameObject;
                                node.GetComponent <CPathNode>().Init(CenterPoint.x + 1, yPos, PathNodeDir.SouthR, this);
                                pathnodes.Add(PathNodeDir.SouthR, node.GetComponent <CPathNode>());
                                break;
                            }
                        }
                        continue;

                    case Direction.EAST:
                        if (coordinate.x + 1 < _gameBoard.Length)
                        {
                            if (!_gameBoard[coordinate.x + 1][coordinate.y])
                            {
                                node = Object.Instantiate(Resources.Load("Pathnode"), Vector3.zero, Quaternion.identity) as GameObject;
                                node.GetComponent <CPathNode>().Init(xPos + roomWidth - 1, CenterPoint.y - 1, PathNodeDir.EastD, this);
                                pathnodes.Add(PathNodeDir.EastD, node.GetComponent <CPathNode>());
                                node = Object.Instantiate(Resources.Load("Pathnode"), Vector3.zero, Quaternion.identity) as GameObject;
                                node.GetComponent <CPathNode>().Init(xPos + roomWidth - 1, CenterPoint.y + 1, PathNodeDir.EastU, this);
                                pathnodes.Add(PathNodeDir.EastU, node.GetComponent <CPathNode>());
                                break;
                            }
                        }
                        continue;

                    case Direction.WEST:
                        if (coordinate.x - 1 >= 0)
                        {
                            if (!_gameBoard[coordinate.x - 1][coordinate.y])
                            {
                                node = Object.Instantiate(Resources.Load("Pathnode"), Vector3.zero, Quaternion.identity) as GameObject;
                                node.GetComponent <CPathNode>().Init(xPos, CenterPoint.y - 1, PathNodeDir.WestD, this);
                                pathnodes.Add(PathNodeDir.WestD, node.GetComponent <CPathNode>());
                                node = Object.Instantiate(Resources.Load("Pathnode"), Vector3.zero, Quaternion.identity) as GameObject;
                                node.GetComponent <CPathNode>().Init(xPos, CenterPoint.y + 1, PathNodeDir.WestU, this);
                                pathnodes.Add(PathNodeDir.WestU, node.GetComponent <CPathNode>());
                                break;
                            }
                        }
                        continue;
                    }

                    CTCorridor newCor = new CTCorridor();
                    newCor.SetupCorridor(this, _corridorLength, nextDir);
                    _corridors.Add(newCor);
                    nextCorridors.Add(nextDir, newCor);
                }
            }
        }

        // Create 1 End Room
        if (nextCorridors.Count <= 0)
        {
            return;
        }

        _availableRooms += nextCorridors.Count;

        // Create Next Room
        CTRoomCoordinate nextRoomCoord = new CTRoomCoordinate(0, 0);

        foreach (Direction nextdir in nextCorridors.Keys)
        {
            //if direction have a room alrdy base on the _gameboard, skip
            switch (nextdir)
            {
            case Direction.NORTH:
                if (!_gameBoard[coordinate.x][coordinate.y + 1])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x, coordinate.y + 1);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_width, _height, nextRoomCoord, nextCorridors[nextdir], ref _numRooms, ref _availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, roomDepth, true);
                }
                break;

            case Direction.EAST:
                if (!_gameBoard[coordinate.x + 1][coordinate.y])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x + 1, coordinate.y);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_width, _height, nextRoomCoord, nextCorridors[nextdir], ref _numRooms, ref _availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, roomDepth, true);
                }
                break;

            case Direction.WEST:
                if (!_gameBoard[coordinate.x - 1][coordinate.y])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x - 1, coordinate.y);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_width, _height, nextRoomCoord, nextCorridors[nextdir], ref _numRooms, ref _availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, roomDepth, true);
                }
                break;

            case Direction.SOUTH:
                if (!_gameBoard[coordinate.x][coordinate.y - 1])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x, coordinate.y - 1);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_width, _height, nextRoomCoord, nextCorridors[nextdir], ref _numRooms, ref _availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, roomDepth, true);
                }
                break;
            }
        }
    }
Esempio n. 6
0
    private void SetupRoom(int _width, int _height, CTRoomCoordinate _roomCoordinate, CTCorridor _prevCorridor,
                           ref int _numRooms, ref int _availableRooms, ref int _maxRooms, ref bool[][] _gameBoard, ref List <CTRoom> _rooms, ref List <CTCorridor> _corridors,
                           int _depth, bool _ignoreDepth = false)
    {
        //Return Mechanic / Safety
        if (_roomCoordinate.x >= _gameBoard.Length)
        {
            return;
        }

        if (_roomCoordinate.y >= _gameBoard[0].Length)
        {
            return;
        }

        if (_gameBoard[_roomCoordinate.x][_roomCoordinate.y])
        {
            return;
        }

        // Init Values
        // Set the entering corridor direction.
        nextCorridors = new Dictionary <Direction, CTCorridor>();
        prevCorridor  = _prevCorridor.direction;

        roomWidth  = _width;
        roomHeight = _height;
        roomDepth  = _depth + 1;

        coordinate = new CTRoomCoordinate(_roomCoordinate);

        //set up pathnodes
        pathnodes = new Dictionary <PathNodeDir, CPathNode>();

        //Create Room
        switch (_prevCorridor.direction)
        {
        // If the corridor entering this room is going north...
        case Direction.NORTH:
            // The y coordinate of the room must be at the end of the corridor (since the corridor leads to the bottom of the room).
            xPos = _prevCorridor.EndPositionX - (roomWidth / 2);
            yPos = _prevCorridor.EndPositionY + 1;
            break;

        case Direction.EAST:
            xPos = _prevCorridor.EndPositionX + 1;
            yPos = _prevCorridor.EndPositionY - (roomHeight / 2);
            break;

        case Direction.SOUTH:
            xPos = _prevCorridor.EndPositionX - (roomWidth / 2);
            yPos = _prevCorridor.EndPositionY - roomHeight;
            break;

        case Direction.WEST:
            xPos = _prevCorridor.EndPositionX - roomWidth;
            yPos = _prevCorridor.EndPositionY - (roomHeight / 2);
            break;
        }

        // room created successfully!
        _prevCorridor.connectedTo = true;
        generated = true;
        _gameBoard[_roomCoordinate.x][_roomCoordinate.y] = true;

        //pathnodes.Add(new CPathNode(CenterPoint.x, yPos + roomHeight, Direction.NORTH, this));
        //pathnodes.Add(new CPathNode(xPos, CenterPoint.y, Direction.WEST, this));
        //pathnodes.Add(new CPathNode(CenterPoint.x, yPos, Direction.SOUTH, this));
        //pathnodes.Add(new CPathNode(xPos + roomWidth, CenterPoint.y + roomWidth, Direction.EAST, this));

        _availableRooms--;
        _numRooms++;
        //Debug.Log("CR_Count " + _rooms.Count + "  _numRooms: " + _numRooms);
        //Debug.Log("Coord: " + coordinate.x + ", " + coordinate.y);

        if (_numRooms >= _maxRooms)
        {
            return;
        }

        int limit = _maxRooms / 4;

        if (limit < _depth && !_ignoreDepth)
        {
            return;
        }

        // Create Next Corridors and Pathnode
        int startDir = Random.Range(0, (int)Direction.Size);

        for (int i = 0; i < (int)Direction.Size; ++i, ++startDir)
        {
            Direction nextDir = (Direction)(startDir % (int)Direction.Size);
            //Create Corridors
            if (Random.Range(0.0f, 1.0f) <= 1.0f - (_numRooms + _availableRooms) / _maxRooms - i * 0.1f)
            {
                // Safety Check  if not, create a corridor for the room
                switch (nextDir)
                {
                case Direction.NORTH:
                    //if the next room will be out of board
                    if (coordinate.y + 1 < _gameBoard[0].Length)
                    {
                        if (!_gameBoard[coordinate.x][coordinate.y + 1])
                        {
                            break;
                        }
                    }
                    continue;

                case Direction.SOUTH:
                    if (coordinate.y - 1 >= 0)
                    {
                        if (!_gameBoard[coordinate.x][coordinate.y - 1])
                        {
                            break;
                        }
                    }
                    continue;

                case Direction.EAST:
                    if (coordinate.x + 1 < _gameBoard.Length)
                    {
                        if (!_gameBoard[coordinate.x + 1][coordinate.y])
                        {
                            break;
                        }
                    }
                    continue;

                case Direction.WEST:
                    if (coordinate.x - 1 >= 0)
                    {
                        if (!_gameBoard[coordinate.x - 1][coordinate.y])
                        {
                            break;
                        }
                    }
                    continue;
                }

                CTCorridor newCor = new CTCorridor();
                newCor.SetupCorridor(this, _prevCorridor.corridorLength, nextDir);
                _corridors.Add(newCor);
                nextCorridors.Add(nextDir, newCor);
            }
        }

        // Create 1 End Room
        if (nextCorridors.Count <= 0)
        {
            return;
        }

        _availableRooms += nextCorridors.Count;

        // Create Next Room
        CTRoomCoordinate nextRoomCoord = new CTRoomCoordinate(0, 0);

        foreach (Direction nextdir in nextCorridors.Keys)
        {
            //if direction have a room alrdy base on the _gameboard, skip
            switch (nextdir)
            {
            case Direction.NORTH:
                if (!_gameBoard[coordinate.x][coordinate.y + 1])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x, coordinate.y + 1);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_width, _height, nextRoomCoord, nextCorridors[nextdir], ref _numRooms, ref _availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, roomDepth);
                }
                break;

            case Direction.EAST:
                if (!_gameBoard[coordinate.x + 1][coordinate.y])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x + 1, coordinate.y);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_width, _height, nextRoomCoord, nextCorridors[nextdir], ref _numRooms, ref _availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, roomDepth);
                }
                break;

            case Direction.WEST:
                if (!_gameBoard[coordinate.x - 1][coordinate.y])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x - 1, coordinate.y);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_width, _height, nextRoomCoord, nextCorridors[nextdir], ref _numRooms, ref _availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, roomDepth);
                }
                break;

            case Direction.SOUTH:
                if (!_gameBoard[coordinate.x][coordinate.y - 1])
                {
                    //Create next room
                    CTRoom newRoom = new CTRoom();
                    nextRoomCoord.setCoordinate(coordinate.x, coordinate.y - 1);
                    _rooms.Add(newRoom);
                    newRoom.SetupRoom(_width, _height, nextRoomCoord, nextCorridors[nextdir], ref _numRooms, ref _availableRooms, ref _maxRooms, ref _gameBoard, ref _rooms, ref _corridors, roomDepth);
                }
                break;
            }
        }
    }