Exemple #1
0
    void SetLargeRooms()
    {
        //Keeping track of how many large rooms our level has
        int largeRooms = 0;
        //Checking our level for any suitable positions to place a large room
        List <int> availableRooms = new List <int>();

        for (int i = 0; i < roomBool.Length; i++)
        {
            if (roomBool[i])
            {
                if (!roomBool[i - 1] && !roomBool[i + 1] && i != startRoom)
                {
                    availableRooms.Add(i);
                }
            }
        }

        if (availableRooms.Count > 0)
        {
            while (largeRooms < maxNoOfLargeRooms && availableRooms.Count > 0)
            {
                int randNo = Random.Range(0, availableRooms.Count);
                //Storing door positions of old room to place doorways in new room
                List <int>    doorPositions = new List <int>();
                RoomGenerator roomGen       = gridPoints[availableRooms[randNo]].GetComponent <RoomGenerator>();
                for (int i = 0; i < 12; i++)
                {
                    if (roomGen.CheckForDoor(i))
                    {
                        doorPositions.Add(i);
                    }
                }

                //Clearing old room
                roomGen.transform.GetChild(0).GetComponent <RoomScript>().PrepareForDeletion();
                Destroy(roomGen.transform.GetChild(0).gameObject);

                //Generating new room
                roomList.Add(roomGen.GenerateLargeRoom());
                largeRoomPositions.Add(availableRooms[randNo]);
                roomGen.SetAsLargeRoom();
                //Placing doorways
                foreach (int doorPosition in doorPositions)
                {
                    roomGen.PlaceDoorway(doorPosition);
                    roomGen.ReplaceCorridorForLargeRoom(doorPosition);
                }
                //Choosing large room layout
                roomGen.ChooseLargeRoomLayout();

                availableRooms.Remove(availableRooms[randNo]);
                largeRooms++;
            }
        }
    }