int getY() { return coords.getY(); }
/** * Constructs a new coordinate pair that is a duplicate of the parameter. */ public Coords(Coords c) { this(c.getX(), c.getY()); }
/** * this makes the coordinates 1 based instead of 0 based to match the tiles * diaplayed on the grid. */ public final String toFriendlyString() { return "(" + (getX() + 1) + ", " + (getY() + 1) + ")"; }
/** * The transformation encodes the y value in the top 5 decimal digits and * the x value in the bottom 5. Could more efficiently encode this by * partitioning the binary representation, but this is more human readable * and still allows for a 99999x99999 hex map. */ // encode 2 numbers into 1 public static int coordsToId(Coords c) { return c.getY() * 100000 + c.getX(); }
/** * The transformation encodes the y value in the top 5 decimal digits and * the x value in the bottom 5. Could more efficiently encode this by * partitioning the binary representation, but this is more human readable * and still allows for a 99999x99999 hex map. */ // encode 2 numbers into 1 public static int coordsToId(Coords c) { return c.getY() * 100000 + c.getX(); }
/** * Returns a string representing a coordinate in "board number" format. */ public final String getBoardNum() { StringBuilder num = new StringBuilder(); num.append(getX() > -1 && getX() < 9 ? "0" : "").append(getX() + 1); num.append(getY() > -1 && getY() < 9 ? "0" : "").append(getY() + 1); return num.toString(); }
/** * Creates an id for this building based on its location as well as a * building code. * The transformation encodes the y value in the top 5 decimal digits and * the x value in the bottom 5. Could more efficiently encode this by * partitioning the binary representation, but this is more human readable * and still allows for a 99999x99999 hex map. */ public static int coordsToId(Coords c) { return Targetable.TYPE_BUILDING * 1000000 + c.getY() * 1000 + c.getX(); }
/** * Coords are equal if their x and y components are equal */ @Override public boolean equals(Object object) { if (this == object) { return true; } else if (object == null || getClass() != object.getClass()) { return false; } Coords other = (Coords) object; return other.getX() == this.getX() && other.getY() == this.getY(); }
/** * Gets the hex in the specified direction from the specified starting * coordinates. */ public IHex getHexInDir(Coords c, int dir) { return getHexInDir(c.getX(), c.getY(), dir); }
/** * Returns the Hex at the specified Coords. * * @param c * the Coords. */ public IHex getHex(Coords c) { if (c == null) { return null; } return getHex(c.getX(), c.getY()); }
/** * Determines whether this Board "contains" the specified Coords. * * @param c * the Coords. */ public boolean contains(Coords c) { if (c == null) { return false; } return contains(c.getX(), c.getY()); }
/** * Notifies listeners about the specified mouse action. * * @param coords the Coords. */ public void mouseAction(Coords coords, int mtype, int modifiers) { mouseAction(coords.getX(), coords.getY(), mtype, modifiers); }
private double calcStrategicBuildingTargetUtility(final Targetable target) { if (!(target instanceof BuildingTarget)) { return 0; } final DecimalFormat coordsFormat = new DecimalFormat("00"); final Coords targetCoords = target.getPosition(); final String coords = coordsFormat.format(targetCoords.getX() + 1) + coordsFormat.format(targetCoords.getY() + 1); if (owner.getBehaviorSettings().getStrategicBuildingTargets().contains(coords)) { return STRATEGIC_TARGET_UTILITY; } return 0; }
@Override public String toString() { return "Coords (" + getX() + ", " + getY() + "); " + getBoardNum(); }
public Point getCentreHexLocation(Coords c) { return getCentreHexLocation(c.getX(), c.getY(), false); }
private void buildStraightRoad(Coords start, int direction, int roadStyle) { Coords coords = start; while (coords != null && coords.getX() <= board.getWidth() && coords.getX() >= -1 && coords.getY() <= board.getHeight() && coords.getY() >= -1) { cityPlan.add(coords); Coords next = extendRoad(coords, direction, roadStyle); if (next == null) { coords = resumeAfterObstacle(coords, direction); } else coords = next; } }
/** * Debugging method that renders a hex donut around the given coordinates, with the given radius. * @param g Graphics object on which to draw. */ private void renderDonut(Graphics2D g, Coords coords, int radius) { Set<Coords> donut = BotGeometry.getHexDonut(coords, radius); for(Coords donutCoords : donut) { Point p = getCentreHexLocation(donutCoords.getX(), donutCoords.getY(), true); p.translate(HEX_W / 2, HEX_H / 2); drawHexBorder(g, p, Color.PINK, 0, 6); } } /**