Package net.royalur.model
Class Tile
java.lang.Object
net.royalur.model.Tile
A tile represents location on a Royal Game of Ur board.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncreateList
(int... coordinates) Constructs a list of tiles from the tile coordinates.createPath
(int... coordinates) Constructs a path from waypoints on the board.void
encode
(StringBuilder builder) Encodes the location of this tile intobuilder
.void
encodeX
(StringBuilder builder) Encodes the x-coordinate as an upper-case letter, and appends it tobuilder
.void
encodeXLowerCase
(StringBuilder builder) Encodes the x-coordinate as a lower-case letter, and appends it tobuilder
.void
encodeY
(StringBuilder builder) Encodes the y-coordinate as a number, and appends it tobuilder
.boolean
static Tile
fromIndices
(int ix, int iy) Creates a new tile representing the tile at the indices (ix
,iy
), 0-based.static Tile
fromString
(String tile) Converts text representations of the tile of the format "[letter][number]".int
getX()
Gets the x-coordinate of the tile.int
Gets the x-index of the tile.int
getY()
Gets the y-coordinate of the tile.int
Gets the y-index of the tile.int
hashCode()
stepTowards
(Tile other) Takes a unit length step towards the other tile.toString()
Converts the location of this tile into a text representation of the format "[letter][number]".unionLists
(Collection<Tile>... tileLists) Calculates the union of all given tile lists.
-
Constructor Details
-
Tile
public Tile(int x, int y) Instantiates a tile location.- Parameters:
x
- The x-coordinate of the tile. This coordinate starts at 1.y
- The y-coordinate of the tile. This coordinate starts at 1.
-
-
Method Details
-
getX
public int getX()Gets the x-coordinate of the tile. This coordinate is 1-based.- Returns:
- The x-coordinate of the tile.
-
getXIndex
public int getXIndex()Gets the x-index of the tile. This coordinate is 0-based.- Returns:
- The x-index of the tile.
-
getY
public int getY()Gets the y-coordinate of the tile. This coordinate is 1-based.- Returns:
- The y-coordinate of the tile.
-
getYIndex
public int getYIndex()Gets the y-index of the tile. This coordinate is 0-based.- Returns:
- The y-index of the tile.
-
fromIndices
Creates a new tile representing the tile at the indices (ix
,iy
), 0-based.- Parameters:
ix
- The x-index of the tile. This coordinate is 0-based.iy
- The y-index of the tile. This coordinate is 0-based.- Returns:
- A tile representing the tile at indices (
ix
,iy
).
-
hashCode
public int hashCode() -
equals
-
stepTowards
Takes a unit length step towards the other tile.- Parameters:
other
- The other vector to step towards.- Returns:
- A new vector that is one step closer to other.
-
encode
Encodes the location of this tile intobuilder
.- Parameters:
builder
- The builder to place the encoded tile coordinates into.
-
encodeX
Encodes the x-coordinate as an upper-case letter, and appends it tobuilder
.- Parameters:
builder
- The builder to place the encoded x-coordinate into.
-
encodeXLowerCase
Encodes the x-coordinate as a lower-case letter, and appends it tobuilder
.- Parameters:
builder
- The builder to place the encoded x-coordinate into.
-
encodeY
Encodes the y-coordinate as a number, and appends it tobuilder
.- Parameters:
builder
- The builder to place the encoded y-coordinate into.
-
toString
Converts the location of this tile into a text representation of the format "[letter][number]". -
fromString
Converts text representations of the tile of the format "[letter][number]". For example: - A1 represents (1, 1) - C3 represents (3, 3) - B8 represents (2, 8) - B0 represents (2, 0)- Parameters:
tile
- The text representation of the tile's location.- Returns:
- The tile that the given text is representing.
-
createList
Constructs a list of tiles from the tile coordinates.- Parameters:
coordinates
- The tile coordinates. Must be an even list ordered following x0, y0, x1, y1, x2, y2, etc.- Returns:
- A list of tiles.
-
createPath
Constructs a path from waypoints on the board.- Parameters:
coordinates
- The waypoint coordinates. Must be an even list ordered following x0, y0, x1, y1, x2, y2, etc.- Returns:
- A list of tiles following the path between the given waypoints.
-
unionLists
Calculates the union of all given tile lists.- Parameters:
tileLists
- The lists of tiles.- Returns:
- A set of all tiles.
-