本文整理汇总了Java中net.sf.freecol.common.model.Tile.getRegion方法的典型用法代码示例。如果您正苦于以下问题:Java Tile.getRegion方法的具体用法?Java Tile.getRegion怎么用?Java Tile.getRegion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.freecol.common.model.Tile
的用法示例。
在下文中一共展示了Tile.getRegion方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeLakes
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Make lake regions from unassigned lake tiles.
*
* @param map The {@code Map} to add to.
* @param lakes A list of lake {@code Tile}s.
* @return A list of new {@code ServerRegion}s.
*/
private List<ServerRegion> makeLakes(Map map, List<Tile> lakes) {
Game game = map.getGame();
final TileType lakeType = map.getSpecification()
.getTileType("model.tile.lake");
List<Tile> todo = new ArrayList<>();
List<ServerRegion> result = new ArrayList<>();
int lakeCount = 0;
while (!lakes.isEmpty()) {
Tile tile = first(lakes);
if (tile.getRegion() != null) continue;
ServerRegion lakeRegion = new ServerRegion(game, RegionType.LAKE);
// Pretend lakes are discovered with the surrounding terrain?
todo.clear();
todo.add(tile);
while (!todo.isEmpty()) {
Tile t = todo.remove(0);
if (lakes.contains(t)) {
t.setRegion(lakeRegion);
t.setType(lakeType);
lakes.remove(t);
// It would be better to do:
// todo.addAll(t.getSurroundingTiles(1, 1));
// but this routine can be called from Map.readChildren
// before game.getMap() works. When that use goes away,
// use the above code.
for (Direction d : Direction.allDirections) {
Tile t0 = map.getAdjacentTile(t, d);
if (t0 != null) todo.add(t0);
}
}
}
result.add(lakeRegion);
}
return result;
}
示例2: fillOcean
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Flood fill ocean regions.
*
* @param map The {@code Map} to fill in.
* @param tile A valid starting {@code Tile}.
* @param region A {@code ServerRegion} to fill with.
* @param bounds A {@code Rectangle} that bounds the filling.
* @return The number of tiles filled.
*/
private static int fillOcean(Map map, Tile tile, ServerRegion region,
Rectangle bounds) {
Queue<Tile> q = new LinkedList<>();
int n = 0;
boolean[][] visited = new boolean[map.getWidth()][map.getHeight()];
visited[tile.getX()][tile.getY()] = true;
q.add(tile);
while ((tile = q.poll()) != null) {
region.addTile(tile);
n++;
for (Direction direction : Direction.values()) {
Tile t = map.getAdjacentTile(tile, direction);
if (t != null
&& !visited[t.getX()][t.getY()]
&& bounds.contains(t.getX(), t.getY())) {
visited[t.getX()][t.getY()] = true;
if ((t.getRegion() == null || t.getRegion() == region)
&& !t.isLand()) {
q.add(t);
}
}
}
}
return n;
}
示例3: displayOptionalTileText
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Displays the Tile text for a Tile.
* Shows tile names, coordinates and colony values.
*
* @param g The Graphics2D object on which the text gets drawn.
* @param tile The Tile to draw the text on.
*/
void displayOptionalTileText(Graphics2D g, Tile tile) {
String text = null;
int op = getClientOptions().getInteger(ClientOptions.DISPLAY_TILE_TEXT);
switch (op) {
case ClientOptions.DISPLAY_TILE_TEXT_NAMES:
text = Messages.getName(tile);
break;
case ClientOptions.DISPLAY_TILE_TEXT_OWNERS:
if (tile.getOwner() != null) {
text = Messages.message(tile.getOwner().getNationLabel());
}
break;
case ClientOptions.DISPLAY_TILE_TEXT_REGIONS:
if (tile.getRegion() != null) {
if (FreeColDebugger.isInDebugMode(FreeColDebugger.DebugMode.MENUS)
&& tile.getRegion().getName() == null) {
text = tile.getRegion().getSuffix();
} else {
text = Messages.message(tile.getRegion().getLabel());
}
}
break;
case ClientOptions.DISPLAY_TILE_TEXT_EMPTY:
break;
default:
logger.warning("displayTileText option " + op + " out of range");
break;
}
g.setColor(Color.BLACK);
g.setFont(FontLibrary.createFont(FontLibrary.FontType.NORMAL,
FontLibrary.FontSize.TINY, lib.getScaleFactor()));
if (text != null) {
int b = getBreakingPoint(text);
if (b == -1) {
g.drawString(text,
(tileWidth - g.getFontMetrics().stringWidth(text)) / 2,
(tileHeight - g.getFontMetrics().getAscent()) / 2);
} else {
g.drawString(text.substring(0, b),
(tileWidth - g.getFontMetrics().stringWidth(text.substring(0, b)))/2,
halfHeight - (g.getFontMetrics().getAscent()*2)/3);
g.drawString(text.substring(b+1),
(tileWidth - g.getFontMetrics().stringWidth(text.substring(b+1)))/2,
halfHeight + (g.getFontMetrics().getAscent()*2)/3);
}
}
if (FreeColDebugger.debugDisplayCoordinates()) {
String posString = tile.getX() + ", " + tile.getY();
if (tile.getHighSeasCount() >= 0) {
posString += "/" + Integer.toString(tile.getHighSeasCount());
}
g.drawString(posString,
(tileWidth - g.getFontMetrics().stringWidth(posString)) / 2,
(tileHeight - g.getFontMetrics().getAscent()) / 2);
}
String value = DebugUtils.getColonyValue(tile);
if (value != null) {
g.drawString(value,
(tileWidth - g.getFontMetrics().stringWidth(value)) / 2,
(tileHeight - g.getFontMetrics().getAscent()) / 2);
}
}