本文整理汇总了Java中com.watabou.utils.Graph类的典型用法代码示例。如果您正苦于以下问题:Java Graph类的具体用法?Java Graph怎么用?Java Graph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Graph类属于com.watabou.utils包,在下文中一共展示了Graph类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: placeEntranceAndExit
import com.watabou.utils.Graph; //导入依赖的package包/类
protected boolean placeEntranceAndExit() {
int distance;
int retry = 0;
int minDistance = (int) Math.sqrt(rooms.size());
Room roomExit;
do {
do {
roomEntrance = Random.element(rooms);
} while (roomEntrance.width() < 4 || roomEntrance.height() < 4);
do {
roomExit = Random.element(rooms);
} while (roomExit == roomEntrance || roomExit.width() < 4 || roomExit.height() < 4);
Graph.buildDistanceMap(rooms, roomExit);
distance = roomEntrance.distance();
if (retry++ > 10) {
return false;
}
} while (distance < minDistance);
roomEntrance.type = Type.ENTRANCE;
roomExit.type = Type.EXIT;
setRoomExit(roomExit);
return true;
}
示例2: buildPath
import com.watabou.utils.Graph; //导入依赖的package包/类
private 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;
}
}
}
示例3: build
import com.watabou.utils.Graph; //导入依赖的package包/类
@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;
}
示例4: build
import com.watabou.utils.Graph; //导入依赖的package包/类
@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;
}
示例5: build
import com.watabou.utils.Graph; //导入依赖的package包/类
@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 = Room.Type.SHOP;
// roomShop.type = AmbitiousImp.Quest.isCompleted() ? Room.Type.SHOP : Room.Type.STANDARD;
}
paint();
paintWater();
paintGrass();
// if (AmbitiousImp.Quest.isCompleted()) {
// placeSign();
// }
return true;
}
示例6: build
import com.watabou.utils.Graph; //导入依赖的package包/类
@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;
}
示例7: paintDoors
import com.watabou.utils.Graph; //导入依赖的package包/类
protected void paintDoors( Level l, ArrayList<Room> rooms ) {
for (Room r : rooms) {
for (Room n : r.connected.keySet()) {
if (joinRooms(l, r, n)) {
continue;
}
Room.Door d = r.connected.get(n);
int door = d.x + d.y * l.width();
if (d.type == Room.Door.Type.REGULAR){
//chance for a hidden door scales from 3/21 on floor 2 to 3/3 on floor 20
if (Dungeon.depth > 1 &&
(Dungeon.depth >= 20 || Random.Int(23 - Dungeon.depth) < Dungeon.depth)) {
d.type = Room.Door.Type.HIDDEN;
Graph.buildDistanceMap(rooms, r);
//don't hide if it would make this room only accessible by hidden doors
if (n.distance == Integer.MAX_VALUE){
d.type = Room.Door.Type.UNLOCKED;
}
} else {
d.type = Room.Door.Type.UNLOCKED;
}
}
switch (d.type) {
case EMPTY:
l.map[door] = Terrain.EMPTY;
break;
case TUNNEL:
l.map[door] = l.tunnelTile();
break;
case UNLOCKED:
l.map[door] = Terrain.DOOR;
break;
case HIDDEN:
l.map[door] = Terrain.SECRET_DOOR;
break;
case BARRICADE:
l.map[door] = Terrain.BARRICADE;
break;
case LOCKED:
l.map[door] = Terrain.LOCKED_DOOR;
break;
}
}
}
}
示例8: build
import com.watabou.utils.Graph; //导入依赖的package包/类
@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;
}