Record Class Snake.Segment

java.lang.Object
java.lang.Record
com.csse3200.game.minigames.snake.Snake.Segment
Enclosing class:
Snake

public static record Snake.Segment(int x, int y, Direction direction) extends Record
Record that represents a segment of the snake's body
  • Constructor Summary

    Constructors
    Constructor
    Description
    Segment(int x, int y, Direction direction)
    Creates an instance of a Segment record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the direction record component.
    boolean
    A function to check if segments are equal
    final int
    Returns a hash code value for this object.
    final String
    Returns a string representation of this record class.
    int
    x()
    Returns the value of the x record component.
    int
    y()
    Returns the value of the y record component.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Segment

      public Segment(int x, int y, Direction direction)
      Creates an instance of a Segment record class.
      Parameters:
      x - the value for the x record component
      y - the value for the y record component
      direction - the value for the direction record component
  • Method Details

    • equals

      public boolean equals(Object o)
      A function to check if segments are equal
      Specified by:
      equals in class Record
      Parameters:
      o - the reference object with which to compare.
      Returns:
      true if equal, otherwise false.
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • x

      public int x()
      Returns the value of the x record component.
      Returns:
      the value of the x record component
    • y

      public int y()
      Returns the value of the y record component.
      Returns:
      the value of the y record component
    • direction

      public Direction direction()
      Returns the value of the direction record component.
      Returns:
      the value of the direction record component