Klasse Shot

java.lang.Object
pp.battleship.model.Shot
Alle implementierten Schnittstellen:
IntPosition, Item

public final class Shot extends Object implements Item, IntPosition
Represents a shot in the Battleship game. A shot is defined by its coordinates and whether it was a hit or miss.
  • Konstruktorübersicht

    Konstruktoren
    Konstruktor
    Beschreibung
    Shot(int x, int y, boolean hit)
    Creates a new shot.
    Shot(IntPosition pos, boolean hit)
    Creates a new shot.
  • Methodenübersicht

    Modifizierer und Typ
    Methode
    Beschreibung
    <T> T
    accept(Visitor<T> visitor)
    Accepts a visitor with a return value.
    void
    Accepts a visitor without a return value.
    boolean
    Checks if this shot is equal to another object.
    int
    Gets the x-coordinate of the shot.
    int
    Gets the y-coordinate of the shot.
    int
    Computes the hash code of this shot.
    boolean
    Checks if the shot was a hit.
    Returns a string representation of the shot.

    Von Klasse geerbte Methoden java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Konstruktordetails

    • Shot

      public Shot(int x, int y, boolean hit)
      Creates a new shot.
      Parameter:
      x - the x-coordinate of the shot
      y - the y-coordinate of the shot
      hit - indicates whether the shot was a hit
    • Shot

      public Shot(IntPosition pos, boolean hit)
      Creates a new shot.
      Parameter:
      pos - the position of the shot
      hit - indicates whether the shot was a hit
  • Methodendetails

    • getX

      public int getX()
      Gets the x-coordinate of the shot.
      Angegeben von:
      getX in Schnittstelle IntPosition
      Gibt zurück:
      the x-coordinate of the shot
    • getY

      public int getY()
      Gets the y-coordinate of the shot.
      Angegeben von:
      getY in Schnittstelle IntPosition
      Gibt zurück:
      the y-coordinate of the shot
    • isHit

      public boolean isHit()
      Checks if the shot was a hit.
      Gibt zurück:
      true if the shot was a hit, false otherwise
    • equals

      public boolean equals(Object obj)
      Checks if this shot is equal to another object. Two shots are considered equal if they have the same coordinates and hit status.
      Setzt außer Kraft:
      equals in Klasse Object
      Parameter:
      obj - the object to compare with
      Gibt zurück:
      true if the objects are equal, false otherwise
    • hashCode

      public int hashCode()
      Computes the hash code of this shot.
      Setzt außer Kraft:
      hashCode in Klasse Object
      Gibt zurück:
      the hash code of this shot
    • toString

      public String toString()
      Returns a string representation of the shot.
      Setzt außer Kraft:
      toString in Klasse Object
      Gibt zurück:
      a string representation of the shot
    • accept

      public <T> T accept(Visitor<T> visitor)
      Accepts a visitor with a return value.
      Angegeben von:
      accept in Schnittstelle Item
      Typparameter:
      T - the type of the return value
      Parameter:
      visitor - the visitor to accept
      Gibt zurück:
      the result of the visitor's visit method
    • accept

      public void accept(VoidVisitor visitor)
      Accepts a visitor without a return value.
      Angegeben von:
      accept in Schnittstelle Item
      Parameter:
      visitor - the visitor to accept