Java Code Examples for com.watabou.utils.Graph#buildPath()

The following examples show how to use com.watabou.utils.Graph#buildPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegularLevel.java    From remixed-dungeon with GNU General Public License v3.0 5 votes vote down vote up
protected void buildPath(Room from, Room to) {
	Graph.buildDistanceMap(rooms, to);
	List<Room> path = Graph.buildPath(from, to);
	if(path!=null) {
		Room room = from;
		for (Room next : path) {
			if (!room.isRoomIsolatedFrom(to)) {
				break;
			}
			room.price(room.price()*2);
			room.connect(next);
			room = next;
		}
	}
}
 
Example 2
Source File: LastShopLevel.java    From unleashed-pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean build() {

	feeling = Feeling.CHASM;
	viewDistance = 4;
	
	initRooms();
	
	int distance;
	int retry = 0;
	int minDistance = (int)Math.sqrt( rooms.size() );
	do {
		int innerRetry = 0;
		do {
			if (innerRetry++ > 10) {
				return false;
			}
			roomEntrance = Random.element( rooms );
		} while (roomEntrance.width() < 4 || roomEntrance.height() < 4);
		
		innerRetry = 0;
		do {
			if (innerRetry++ > 10) {
				return false;
			}
			roomExit = Random.element( rooms );
		} while (roomExit == roomEntrance || roomExit.width() < 6 || roomExit.height() < 6 || roomExit.top == 0);

		Graph.buildDistanceMap( rooms, roomExit );
		distance = Graph.buildPath( rooms, roomEntrance, roomExit ).size();
		
		if (retry++ > 10) {
			return false;
		}
		
	} while (distance < minDistance);
	
	roomEntrance.type = Type.ENTRANCE;
	roomExit.type = Type.EXIT;
	
	Graph.buildDistanceMap( rooms, roomExit );
	List<Room> path = Graph.buildPath( rooms, roomEntrance, roomExit );
	
	Graph.setPrice( path, roomEntrance.distance );
	
	Graph.buildDistanceMap( rooms, roomExit );
	path = Graph.buildPath( rooms, roomEntrance, roomExit );
	
	Room room = roomEntrance;
	for (Room next : path) {
		room.connect( next );
		room = next;
	}
	
	Room roomShop = null;
	int shopSquare = 0;
	for (Room r : rooms) {
		if (r.type == Type.NULL && r.connected.size() > 0) {
			r.type = Type.PASSAGE;
			if (r.square() > shopSquare) {
				roomShop = r;
				shopSquare = r.square();
			}
		}
	}
	
	if (roomShop == null || shopSquare < 54) {
		return false;
	} else {
		roomShop.type = Imp.Quest.isCompleted() ? Room.Type.SHOP : Room.Type.STANDARD;
	}
	
	paint();
	
	paintWater();
	paintGrass();
	
	return true;
}
 
Example 3
Source File: LastShopLevel.java    From pixel-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean build() {
	
	initRooms();
	
	int distance;
	int retry = 0;
	int minDistance = (int)Math.sqrt( rooms.size() );
	do {
		int innerRetry = 0;
		do {
			if (innerRetry++ > 10) {
				return false;
			}
			roomEntrance = Random.element( rooms );
		} while (roomEntrance.width() < 4 || roomEntrance.height() < 4);
		
		innerRetry = 0;
		do {
			if (innerRetry++ > 10) {
				return false;
			}
			roomExit = Random.element( rooms );
		} while (roomExit == roomEntrance || roomExit.width() < 6 || roomExit.height() < 6 || roomExit.top == 0);

		Graph.buildDistanceMap( rooms, roomExit );
		distance = Graph.buildPath( rooms, roomEntrance, roomExit ).size();
		
		if (retry++ > 10) {
			return false;
		}
		
	} while (distance < minDistance);
	
	roomEntrance.type = Type.ENTRANCE;
	roomExit.type = Type.EXIT;
	
	Graph.buildDistanceMap( rooms, roomExit );
	List<Room> path = Graph.buildPath( rooms, roomEntrance, roomExit );
	
	Graph.setPrice( path, roomEntrance.distance );
	
	Graph.buildDistanceMap( rooms, roomExit );
	path = Graph.buildPath( rooms, roomEntrance, roomExit );
	
	Room room = roomEntrance;
	for (Room next : path) {
		room.connect( next );
		room = next;
	}
	
	Room roomShop = null;
	int shopSquare = 0;
	for (Room r : rooms) {
		if (r.type == Type.NULL && r.connected.size() > 0) {
			r.type = Type.PASSAGE; 
			if (r.square() > shopSquare) {
				roomShop = r;
				shopSquare = r.square();
			}
		}
	}
	
	if (roomShop == null || shopSquare < 30) {
		return false;
	} else {
		roomShop.type = Imp.Quest.isCompleted() ? Room.Type.SHOP : Room.Type.STANDARD;
	}
	
	paint();
	
	paintWater();
	paintGrass();
	
	return true;
}
 
Example 4
Source File: LastShopLevel.java    From remixed-dungeon with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected boolean build() {
	
	initRooms();
	
	int distance;
	int retry = 0;
	int minDistance = (int)Math.sqrt( rooms.size() );
	do {
		int innerRetry = 0;
		do {
			if (innerRetry++ > 10) {
				return false;
			}
			roomEntrance = Random.element( rooms );
		} while (roomEntrance.width() < 4 || roomEntrance.height() < 4);
		
		innerRetry = 0;
		do {
			if (innerRetry++ > 10) {
				return false;
			}
			setRoomExit(Random.element( rooms ));
		} while (getRoomExit() == roomEntrance || getRoomExit().width() < 6 || getRoomExit().height() < 6 || getRoomExit().top == 0);

		Graph.buildDistanceMap( rooms, getRoomExit());
		distance = Graph.buildPath(roomEntrance, getRoomExit()).size();
		
		if (retry++ > 10) {
			return false;
		}
		
	} while (distance < minDistance);
	
	roomEntrance.type = Type.ENTRANCE;
	getRoomExit().type = Type.EXIT;
	
	Graph.buildDistanceMap( rooms, getRoomExit());
	List<Room> path = Graph.buildPath(roomEntrance, getRoomExit());
	
	Graph.setPrice( path, roomEntrance.distance );
	
	Graph.buildDistanceMap( rooms, getRoomExit());
	path = Graph.buildPath(roomEntrance, getRoomExit());
	
	Room room = roomEntrance;
	for (Room next : path) {
		room.connect( next );
		room = next;
	}
	
	Room roomShop = null;
	int shopSquare = 0;
	for (Room r : rooms) {
		if (r.type == Type.NULL && r.connected.size() > 0) {
			r.type = Type.PASSAGE; 
			if (r.square() > shopSquare) {
				roomShop = r;
				shopSquare = r.square();
			}
		}
	}
	
	if (roomShop == null || shopSquare < 30) {
		return false;
	} else {
		roomShop.type = Imp.Quest.isCompleted() ? Room.Type.SHOP : Room.Type.STANDARD;
	}
	
	paint();
	
	paintWater();
	paintGrass();
	
	return true;
}