java.lang.Object
it.polimi.ingsw.am13.model.card.Coordinates
- All Implemented Interfaces:
Serializable
Represents a 2-tuple of coordinates for a 2D point or vector that could be used in game.
For how game works, coordinates (x, y) are valid only if (x+y)%2=0 (their sum must be a multiple of 2).
The object, once instantiated, is immutable.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCoordinates
(int posX, int posY) Creates an immutable valid object Coordinates. -
Method Summary
Modifier and TypeMethodDescriptionadd
(int posX, int posY) Performs arithmetic sum of coordinatesadd
(Coordinates other) Performs arithmetic sum of coordinatesboolean
Creates the ordered list of 4 coordinates that are near this coordinate in game field.int
getPosX()
int
getPosY()
boolean
hasCoords
(int posX, int posY) Checks equality with indicated coordinatesint
hashCode()
static Coordinates
origin()
Create new coordinates for origin, without throwing exceptionstoString()
-
Field Details
-
posX
private final int posXCoordinate x of point/vector (horizontal axis) -
posY
private final int posYCoordinate y of point/vector (vertical axis)
-
-
Constructor Details
-
Coordinates
Creates an immutable valid object Coordinates. The sum of parameters must be a multiple of 2- Parameters:
posX
- Coordinate x of point/vector (horizontal ax)posY
- Coordinate y of point/vector (vertical axis)- Throws:
InvalidCoordinatesException
- If posX+posY is not a multiple of 2 (game coordinates are not valid)
-
-
Method Details
-
origin
Create new coordinates for origin, without throwing exceptions- Returns:
- Coordinates for (0,0)
-
getPosX
public int getPosX()- Returns:
- Coordinate x of point/vector (horizontal axis)
-
getPosY
public int getPosY()- Returns:
- Coordinate y of point/vector (vertical axis)
-
add
Performs arithmetic sum of coordinates- Parameters:
other
- Other coordinates to be summed- Returns:
- New object Coordinates with result of sum
-
add
Performs arithmetic sum of coordinates- Parameters:
posX
- Other x coordinate to be summedposY
- Other y coordinate to be summed- Returns:
- New object Coordinates with result of sum
- Throws:
InvalidCoordinatesException
- If, performing the sum, the new coordinates are not valid
-
fetchNearCoordinates
Creates the ordered list of 4 coordinates that are near this coordinate in game field. The 'near coordinates' are the ones where a new card could be placed with respect to a card in these coordinates.- Returns:
- List of the 4 near coordinates, in order 'upper left', 'upper right', 'lower right', 'lower left'
-
hasCoords
public boolean hasCoords(int posX, int posY) Checks equality with indicated coordinates- Parameters:
posX
- x coordinate to be checkedposY
- y coordinate to be checked- Returns:
true
if these coordinates are equal to the respective coordinates passed as parameter
-
equals
-
hashCode
public int hashCode() -
toString
-