Record Class Snake.Segment
java.lang.Object
java.lang.Record
com.csse3200.game.minigames.snake.Snake.Segment
- Enclosing class:
Snake
Record that represents a segment of the snake's body
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of thedirection
record component.boolean
A function to check if segments are equalfinal 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
-
Segment
Creates an instance of aSegment
record class.- Parameters:
x
- the value for thex
record componenty
- the value for they
record componentdirection
- the value for thedirection
record component
-
-
Method Details
-
equals
A function to check if segments are equal -
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. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code 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
-
direction
Returns the value of thedirection
record component.- Returns:
- the value of the
direction
record component
-