Package battleship.model.game.ocean
Record Class Point
java.lang.Object
java.lang.Record
battleship.model.game.ocean.Point
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
Overridden equals methodgetDown()
getLeft()
static Point[]
getRange
(Point startPos, Point endPos, ShipPosition.Direction direction) Get range of points between start and end points.getRight()
getUp()
int
hashCode()
Returns a hash code value for this object.final String
toString()
Returns a string representation of this record class.int
x()
Returns the value of thex
record component.int
y()
Returns the value of they
record component.
-
Constructor Details
-
Point
public Point(int x, int y) Creates an instance of aPoint
record class.- Parameters:
x
- the value for thex
record componenty
- the value for they
record component
-
-
Method Details
-
getRange
Get range of points between start and end points.- Parameters:
startPos
- start pointendPos
- end pointdirection
- ship direction- Returns:
- array of points.
-
getLeft
- Returns:
- point which is on left
-
getRight
- Returns:
- point which is on right
-
getUp
- Returns:
- upper point
-
getDown
- Returns:
- down point
-
getUpAndRight
- Returns:
- up and right point
-
getDownAndRight
- Returns:
- down and right point
-
getUpAndLeft
- Returns:
- up and left point
-
getDownAndLeft
- Returns:
- down and left point
-
equals
Overridden equals method -
hashCode
public int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
x
public int x()Returns the value of thex
record component.- Returns:
- the value of the
x
record component
-
y
public int y()Returns the value of they
record component.- Returns:
- the value of the
y
record component
-