Package pp.battleship.model
Klasse Shot
java.lang.Object
pp.battleship.model.Shot
- Alle implementierten Schnittstellen:
IntPosition,Item
Represents a shot in the Battleship game.
A shot is defined by its coordinates and whether it was a hit or miss.
-
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungShot(int x, int y, boolean hit) Creates a new shot.Shot(IntPosition pos, boolean hit) Creates a new shot. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibung<T> TAccepts a visitor with a return value.voidaccept(VoidVisitor visitor) Accepts a visitor without a return value.booleanChecks if this shot is equal to another object.intgetX()Gets the x-coordinate of the shot.intgetY()Gets the y-coordinate of the shot.inthashCode()Computes the hash code of this shot.booleanisHit()Checks if the shot was a hit.toString()Returns a string representation of the shot.
-
Konstruktordetails
-
Shot
public Shot(int x, int y, boolean hit) Creates a new shot.- Parameter:
x- the x-coordinate of the shoty- the y-coordinate of the shothit- indicates whether the shot was a hit
-
Shot
Creates a new shot.- Parameter:
pos- the position of the shothit- indicates whether the shot was a hit
-
-
Methodendetails
-
getX
public int getX()Gets the x-coordinate of the shot.- Angegeben von:
getXin SchnittstelleIntPosition- Gibt zurück:
- the x-coordinate of the shot
-
getY
public int getY()Gets the y-coordinate of the shot.- Angegeben von:
getYin SchnittstelleIntPosition- 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
Checks if this shot is equal to another object. Two shots are considered equal if they have the same coordinates and hit status. -
hashCode
public int hashCode()Computes the hash code of this shot. -
toString
Returns a string representation of the shot. -
accept
Accepts a visitor with a return value. -
accept
Accepts a visitor without a return value.
-