public void connectRooms(Room room1, Room room2, int width) { w = width; int r1Cx = room1.getLeft() + (room1.getWidth() / 2); int r1Cy = room1.getTop() + (room1.getHeight() / 2); int r2Cx = room2.getLeft() + (room2.getWidth() / 2); int r2Cy = room2.getTop() + (room2.getHeight() / 2); if (r1Cy > r2Cy) { h = room1.getTop() - room2.getTop() - room2.getHeight(); } else { h = room2.getTop() - room1.getTop() - room1.getHeight(); } if (room1.getWidth() >= room2.getWidth()) { if (room1.getWidth() >= 2 * room2.getWidth()) { left = r2Cx; } else { left = (r1Cx + r2Cx) / 2; } } else if (room2.getWidth() > room1.getWidth()) { if (room2.getWidth() >= 2 * room1.getWidth()) { left = r1Cx; } else { left = (r1Cx + r2Cx) / 2; } } top = room1.getTop() + room1.getHeight() - 1; if (h < 0) { h *= -1; } h += 2; setLayout(left, top, w, h); }
public void connectRooms(Room room1, Room room2, int width) { h = width; int r1Cx = room1.getLeft() + (room1.getWidth() / 2); int r1Cy = room1.getTop() + (room1.getHeight() / 2); int r2Cx = room2.getLeft() + (room2.getWidth() / 2); int r2Cy = room2.getTop() + (room2.getHeight() / 2); if (r1Cx > r2Cx) { w = room1.getLeft() - room2.getLeft() - room2.getWidth(); } else { w = room2.getLeft() - room1.getLeft() - room1.getWidth(); } if (room1.getHeight() >= room2.getHeight()) { if (room1.getHeight() >= 2 * room2.getHeight()) { top = r2Cy; } else { top = (r1Cy + r2Cy) / 2; } } else if (room2.getHeight() > room1.getHeight()) { if (room2.getHeight() >= 2 * room1.getHeight()) { top = r1Cy; } else { top = (r1Cy + r2Cy) / 2; } } left = room1.getLeft() + room1.getWidth() - 1; if (w < 0) { w *= -1; } w += 2; setLayout(left, top, w, h); }