本文整理汇总了Java中net.sf.freecol.common.model.Tile.getY方法的典型用法代码示例。如果您正苦于以下问题:Java Tile.getY方法的具体用法?Java Tile.getY怎么用?Java Tile.getY使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.freecol.common.model.Tile
的用法示例。
在下文中一共展示了Tile.getY方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: calculateTilePosition
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Gets the position of the given {@code Tile}
* on the drawn map.
*
* @param t The {@code Tile} to check.
* @return The position of the given {@code Tile}, or
* {@code null} if the {@code Tile} is not drawn on
* the mapboard.
*/
Point calculateTilePosition(Tile t) {
repositionMapIfNeeded();
if (!isTileVisible(t)) return null;
int x = ((t.getX() - leftColumn) * tileWidth) + leftColumnX;
int y = ((t.getY() - topRow) * halfHeight) + topRowY;
if ((t.getY() & 1) != 0) x += halfWidth;
return new Point(x, y);
}
示例3: setOffsetFocus
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Sets the focus of the map but offset to the left or right so
* that the focus position can still be visible when a popup is
* raised. If successful, the supplied position will either be at
* the center of the left or right half of the map.
*
* @param tile The {@code Tile} to display.
* @return Positive if the focus is on the right hand side, negative
* if on the left, zero on failure.
* @see #getFocus
*/
int setOffsetFocus(Tile tile) {
if (tile == null) return 0;
int where;
final Map map = getGame().getMap();
final int tx = tile.getX(), ty = tile.getY(),
width = rightColumn - leftColumn;
int moveX = -1;
gui.setFocus(tile);
positionMap(tile);
if (leftColumn <= 0) { // At left edge already
if (tx <= width / 4) {
where = -1;
} else if (tx >= 3 * width / 4) {
where = 1;
} else {
moveX = tx + width / 4;
where = -1;
}
} else if (rightColumn >= width - 1) { // At right edge
if (tx >= rightColumn - width / 4) {
where = 1;
} else if (tx <= rightColumn - 3 * width / 4) {
where = -1;
} else {
moveX = tx - width / 4;
where = 1;
}
} else { // Move focus left 1/4 screen
moveX = tx - width / 4;
where = 1;
}
if (moveX >= 0) {
Tile other = map.getTile(moveX, ty);
gui.setFocus(other);
positionMap(other);
}
return where;
}
示例4: scrollMap
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Scroll the map in the given direction.
*
* @param direction The {@code Direction} to scroll in.
* @return True if scrolling occurred.
*/
boolean scrollMap(Direction direction) {
Tile t = focus;
if (t == null) return false;
int fx = t.getX(), fy = t.getY();
if ((t = t.getNeighbourOrNull(direction)) == null) return false;
int tx = t.getX(), ty = t.getY();
int x, y;
// When already close to an edge, resist moving the focus closer,
// but if moving away immediately jump out of the `nearTo' area.
if (isMapNearTop(ty) && isMapNearTop(fy)) {
y = (ty <= fy) ? fy : topRows;
} else if (isMapNearBottom(ty) && isMapNearBottom(fy)) {
y = (ty >= fy) ? fy : getGame().getMap().getWidth()
- bottomRows;
} else {
y = ty;
}
if (isMapNearLeft(tx, ty) && isMapNearLeft(fx, fy)) {
x = (tx <= fx) ? fx : getLeftColumns(ty);
} else if (isMapNearRight(tx, ty) && isMapNearRight(fx, fy)) {
x = (tx >= fx) ? fx : getGame().getMap().getWidth()
- getRightColumns(ty);
} else {
x = tx;
}
if (x == fx && y == fy) return false;
gui.setFocus(getGame().getMap().getTile(x,y));
return true;
}
示例5: calculateTileBounds
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Calculate the bounds of the rectangle containing a Tile on the
* screen, and return it. If the Tile is not on-screen a maximal
* rectangle is returned. The bounds includes a one-tile padding
* area above the Tile, to include the space needed by any units
* in the Tile.
*
* @param tile The {@code Tile} on the screen.
* @return The bounds {@code Rectangle}.
*/
Rectangle calculateTileBounds(Tile tile) {
Rectangle result = new Rectangle(0, 0, size.width, size.height);
if (isTileVisible(tile)) {
result.x = ((tile.getX() - leftColumn) * tileWidth) + leftColumnX;
result.y = ((tile.getY() - topRow) * halfHeight) + topRowY - tileHeight;
if ((tile.getY() & 1) != 0) {
result.x += halfWidth;
}
result.width = tileWidth;
result.height = tileHeight * 2;
}
return result;
}
示例6: isTileVisible
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
private boolean isTileVisible(Tile tile) {
if (tile == null) return false;
return tile.getY() >= topRow && tile.getY() <= bottomRow
&& tile.getX() >= leftColumn && tile.getX() <= rightColumn;
}
示例7: displayTileWithBeachAndBorder
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Displays the given Tile onto the given Graphics2D object at the
* location specified by the coordinates. Only base terrain will be drawn.
*
* @param g The Graphics2D object on which to draw the Tile.
* @param tile The Tile to draw.
*/
void displayTileWithBeachAndBorder(Graphics2D g, Tile tile) {
if (tile != null) {
TileType tileType = tile.getType();
int x = tile.getX();
int y = tile.getY();
// ATTENTION: we assume that all base tiles have the same size
g.drawImage(lib.getTerrainImage(tileType, x, y),
0, 0, null);
if (tile.isExplored()) {
if (!tile.isLand() && tile.getStyle() > 0) {
int edgeStyle = tile.getStyle() >> 4;
if (edgeStyle > 0) {
g.drawImage(lib.getBeachEdgeImage(edgeStyle, x, y),
0, 0, null);
}
int cornerStyle = tile.getStyle() & 15;
if (cornerStyle > 0) {
g.drawImage(lib.getBeachCornerImage(cornerStyle, x, y),
0, 0, null);
}
}
List<SortableImage> imageBorders = new ArrayList<>(8);
SortableImage si;
for (Direction direction : Direction.values()) {
Tile borderingTile = tile.getNeighbourOrNull(direction);
if (borderingTile != null && borderingTile.isExplored()) {
TileType borderingTileType = borderingTile.getType();
if (borderingTileType != tileType) {
if (!tile.isLand() && borderingTile.isLand()) {
// If there is a Coast image (eg. beach) defined, use it, otherwise skip
// Draw the grass from the neighboring tile, spilling over on the side of this tile
si = new SortableImage(
lib.getBorderImage(borderingTileType, direction, x, y),
borderingTileType.getIndex());
imageBorders.add(si);
TileImprovement river = borderingTile.getRiver();
if (river != null) {
int magnitude = river.getRiverConnection(
direction.getReverseDirection());
if (magnitude > 0) {
si = new SortableImage(
lib.getRiverMouthImage(direction,
magnitude, x, y),
-1);
imageBorders.add(si);
}
}
} else if (!tile.isLand() || borderingTile.isLand()) {
if (borderingTileType.getIndex() < tileType.getIndex() &&
!lib.getTerrainImage(tileType, 0, 0).equals(lib.getTerrainImage(borderingTileType, 0, 0))) {
// Draw land terrain with bordering land type, or ocean/high seas limit,
// if the tiles do not share same graphics (ocean & great river)
si = new SortableImage(
lib.getBorderImage(borderingTileType, direction, x, y),
borderingTileType.getIndex());
imageBorders.add(si);
}
}
}
}
}
for (SortableImage sorted : sort(imageBorders)) {
g.drawImage(sorted.image, 0, 0, null);
}
}
}
}
示例8: 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);
}
}
示例9: mouseReleased
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void mouseReleased(MouseEvent e) {
if (getMap() == null
|| e.getButton() == MouseEvent.BUTTON1
|| getGUI().getFocus() == null) return;
final JComponent component = (JComponent)e.getSource();
final MapEditorController controller
= getFreeColClient().getMapEditorController();
final boolean isTransformActive = controller.getMapTransform() != null;
endPoint = e.getPoint();
if (startPoint == null) startPoint = endPoint;
drawBox(component, startPoint, endPoint);
Tile start = canvas.convertToMapTile(startPoint.x, startPoint.y);
Tile end = (startPoint == endPoint) ? start
: canvas.convertToMapTile(endPoint.x, endPoint.y);
// edit 2 more conditions in if statement. we need to
// check for coordinator of X and Y if (x,y) outside of
// map then dont focus to that else setfocus to that
// position no option selected, just center map
if (!isTransformActive && end.getX() >= 0 && end.getY() >= 0) {
getGUI().setFocus(end);
return;
}
// find the area to transform
int min_x, max_x, min_y, max_y;
if (start.getX() < end.getX()) {
min_x = start.getX();
max_x = end.getX();
} else {
min_x = end.getX();
max_x = start.getX();
}
if (start.getY() < end.getY()) {
min_y = start.getY();
max_y = end.getY();
} else {
min_y = end.getY();
max_y = start.getY();
}
// apply transformation to all tiles in the area
Tile t = null;
for (int x = min_x; x <= max_x; x++) {
for (int y = min_y; y <= max_y; y++) {
t = getMap().getTile(x, y);
if (t != null) {
controller.transform(t);
}
}
}
if (controller.getMapTransform() instanceof TileTypeTransform) {
for (int x = min_x - 2; x <= max_x + 2; x++) {
for (int y = min_y - 2; y <= max_y + 2; y++) {
t = getMap().getTile(x, y);
if (t != null && t.getType().isWater()) {
TerrainGenerator.encodeStyle(t);
}
}
}
}
getGUI().refresh();
canvas.requestFocus();
}
示例10: refreshTile
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
public void refreshTile(Tile tile) {
if (tile.getX() >= 0 && tile.getY() >= 0) {
canvas.repaint(mapViewer.calculateTileBounds(tile));
}
}
示例11: onScreen
import net.sf.freecol.common.model.Tile; //导入方法依赖的package包/类
/**
* Checks if the Tile/Units at the given coordinates are displayed
* on the screen (or, if the map is already displayed and the focus
* has been changed, whether they will be displayed on the screen
* the next time it'll be redrawn).
*
* @param tileToCheck The position of the Tile in question.
* @return <i>true</i> if the Tile will be drawn on the screen,
* <i>false</i> otherwise.
*/
boolean onScreen(Tile tileToCheck) {
if (tileToCheck == null) return false;
repositionMapIfNeeded();
return (tileToCheck.getY() - 2 > topRow || alignedTop)
&& (tileToCheck.getY() + 4 < bottomRow || alignedBottom)
&& (tileToCheck.getX() - 1 > leftColumn || alignedLeft)
&& (tileToCheck.getX() + 2 < rightColumn || alignedRight);
}