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 TypeMethodDescriptionbooleanOverridden equals methodgetDown()getLeft()static Point[]getRange(Point startPos, Point endPos, ShipPosition.Direction direction) Get range of points between start and end points.getRight()getUp()inthashCode()Returns a hash code value for this object.final StringtoString()Returns a string representation of this record class.intx()Returns the value of thexrecord component.inty()Returns the value of theyrecord component.
-
Constructor Details
-
Point
public Point(int x, int y) Creates an instance of aPointrecord class.- Parameters:
x- the value for thexrecord componenty- the value for theyrecord 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 thexrecord component.- Returns:
- the value of the
xrecord component
-
y
public int y()Returns the value of theyrecord component.- Returns:
- the value of the
yrecord component
-