Esempio n. 1
0
    // Use this for initialization
    void Start()
    {
        instance = this;
        //Randomly place
        int RoomsLeft    = NoOfRooms;
        int NoOfAttempts = NoOfRooms * 8;//Try each room 8 times.
        int RoomIndex    = 1;
        int validRooms   = 0;

        rooms = new Room[NoOfRooms + 1];
        while ((RoomsLeft > 0) && (NoOfAttempts > 0))
        {
            //Generate a room
            Room newroom = RandomRoom();
            //check collision on room.
            if (!DoesRoomCollide(newroom))
            {
                // Debug.Log("Placing Room " + RoomIndex + " at " + newroom.x + "," + newroom.y + " (" +newroom.dimX + "," + newroom.dimY + ")");
                rooms[RoomIndex] = newroom;
                newroom.index    = RoomIndex++;
                PlaceRoom(newroom);
                RoomsLeft--;
                validRooms++;
            }
            else
            {
                NoOfAttempts++;
            }
        }

        //Set no of connected rooms
        for (int i = 0; i <= validRooms; i++)
        {
            rooms[i].ConnectedRooms = new int[validRooms + 1];
            for (int j = 0; j <= rooms[i].ConnectedRooms.GetUpperBound(0); j++)
            {
                rooms[i].ConnectedRooms[j] = -1;
            }
            rooms[i].ConnectedRooms[i] = i;//always connect to itself
        }

        FillConnectedRooms(validRooms);

        PlaceConnectors();


        PrintRoomConnections();
        PrintRooms();
    }
 void Start()
 {
     instance = this;
 }