public static List<Room> generateRooms(Global.RoomSize size, MapLayout map) { ArrayList<Room> placedRooms = new ArrayList<>(); int success = 0; int tPadding = Global.RoomUsePadding ? Global.RoomPadding : 0; int pSize = 0; int tAttempts = Global.RoomAttempts; while (tAttempts > 0) { Room room = createRandomRoom(map.getWidth(), map.getHeight(), size); Room paddedRoom = new Room( room.x - tPadding, room.y - tPadding, room.w + (2 * tPadding), room.h + (2 * tPadding)); if (checkForEmptySpace(map, paddedRoom)) { placeRoom(map, room); success++; placedRooms.add(room); pSize++; } tAttempts--; if (size != Global.RoomSize.getValues().get(0) && pSize % Global.RoomMaxNumPlace == 0) { size = size.getSmaller(); } } System.out.println("Successful Rooms: " + success); return placedRooms; }
/** * Check if the this Room can be placed on the map with the x,y coordinates * * @param map * @return */ public boolean checkRectangleInBounds(MapLayout map) { return (y < map.getHeight() && (y + h) < map.getHeight()) && (x < map.getWidth() && (x + w < map.getWidth())); }