Package pp.battleship.model
Klasse Battleship
java.lang.Object
pp.battleship.model.Battleship
- Alle implementierten Schnittstellen:
Item
Represents a battleship in the game. A battleship is characterized by its length, position,
rotation, and status. It can be moved, rotated, and hit during the game. This class also
provides methods to check for collisions with other ships and to determine whether the
battleship has been destroyed.
-
Verschachtelte Klassen - Übersicht
Verschachtelte KlassenModifizierer und TypKlasseBeschreibungstatic enumEnumeration representing the different statuses a battleship can have during the game. -
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungBattleship(int length, int x, int y, Rotation rot) Constructs a new Battleship with the specified length, position, and rotation. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibung<T> TAccepts a visitor that returns a value of typeT.voidaccept(VoidVisitor visitor) Accepts a visitor that does not return a value.booleancollidesWith(Battleship other) Checks whether this battleship collides with another battleship.booleancontains(int x, int y) Checks whether the specified position is covered by the battleship.booleancontains(IntPosition pos) Checks whether the specified position is covered by the battleship.Returns the positions of this battleship that have been hit.intReturns the length of the battleship.intgetMaxX()Returns the maximum x-coordinate that the battleship occupies based on its current position and rotation.intgetMaxY()Returns the maximum y-coordinate that the battleship occupies based on its current position and rotation.intgetMinX()Returns the minimum x-coordinate that the battleship occupies based on its current position and rotation.intgetMinY()Returns the minimum y-coordinate that the battleship occupies based on its current position and rotation.getRot()Returns the current rotation of the battleship.Returns the current status of the battleship.intgetX()Returns the current x-coordinate of the battleship's position.intgetY()Returns the current y-coordinate of the battleship's position.booleanhit(int x, int y) Attempts to hit the battleship at the specified position.booleanhit(IntPosition position) Attempts to hit the battleship at the specified position.booleanDetermines if the battleship has been completely destroyed.voidmoveTo(int x, int y) Moves the battleship to the specified coordinates.voidmoveTo(IntPosition pos) Moves the battleship to the specified position.voidrotated()Rotates the battleship by 90 degrees clockwise.voidsetRotation(Rotation rot) Sets the rotation of the battleship.voidsetStatus(Battleship.Status status) Sets the status of the battleship.toString()Returns a string representation of the battleship, including its length, position, and rotation.
-
Konstruktordetails
-
Battleship
Constructs a new Battleship with the specified length, position, and rotation.- Parameter:
length- the length of the battleshipx- the x-coordinate of the battleship's initial positiony- the y-coordinate of the battleship's initial positionrot- the rotation of the battleship
-
-
Methodendetails
-
getX
public int getX()Returns the current x-coordinate of the battleship's position.- Gibt zurück:
- the x-coordinate of the battleship
-
getY
public int getY()Returns the current y-coordinate of the battleship's position.- Gibt zurück:
- the y-coordinate of the battleship
-
moveTo
public void moveTo(int x, int y) Moves the battleship to the specified coordinates.- Parameter:
x- the new x-coordinate of the battleship's positiony- the new y-coordinate of the battleship's position
-
moveTo
Moves the battleship to the specified position.- Parameter:
pos- the new position of the battleship
-
getStatus
Returns the current status of the battleship.- Gibt zurück:
- the status of the battleship
-
setStatus
Sets the status of the battleship.- Parameter:
status- the new status to be set for the battleship
-
getLength
public int getLength()Returns the length of the battleship.- Gibt zurück:
- the length of the battleship
-
getMinX
public int getMinX()Returns the minimum x-coordinate that the battleship occupies based on its current position and rotation.- Gibt zurück:
- the minimum x-coordinate of the battleship
-
getMaxX
public int getMaxX()Returns the maximum x-coordinate that the battleship occupies based on its current position and rotation.- Gibt zurück:
- the maximum x-coordinate of the battleship
-
getMinY
public int getMinY()Returns the minimum y-coordinate that the battleship occupies based on its current position and rotation.- Gibt zurück:
- the minimum y-coordinate of the battleship
-
getMaxY
public int getMaxY()Returns the maximum y-coordinate that the battleship occupies based on its current position and rotation.- Gibt zurück:
- the maximum y-coordinate of the battleship
-
getRot
Returns the current rotation of the battleship.- Gibt zurück:
- the rotation of the battleship
-
setRotation
Sets the rotation of the battleship.- Parameter:
rot- the new rotation to be set for the battleship
-
rotated
public void rotated()Rotates the battleship by 90 degrees clockwise. -
hit
public boolean hit(int x, int y) Attempts to hit the battleship at the specified position. If the position is part of the battleship, the hit is recorded.- Parameter:
x- the x-coordinate of the position to hity- the y-coordinate of the position to hit- Gibt zurück:
- true if the position is part of the battleship, false otherwise
- Siehe auch:
-
hit
Attempts to hit the battleship at the specified position. If the position is part of the battleship, the hit is recorded. This is a convenience method for hit(int, int).- Parameter:
position- the position to hit- Gibt zurück:
- true if the position is part of the battleship, false otherwise
-
getDamaged
Returns the positions of this battleship that have been hit.- Gibt zurück:
- a set of positions that have been hit
- Siehe auch:
-
contains
Checks whether the specified position is covered by the battleship. This method does not record a hit, only checks coverage. This is a convenience method for contains(int, int).- Parameter:
pos- the position to check- Gibt zurück:
- true if the position is covered by the battleship, false otherwise
-
contains
public boolean contains(int x, int y) Checks whether the specified position is covered by the battleship. This method does not record a hit, only checks coverage.- Parameter:
x- the x-coordinate of the position to checky- the y-coordinate of the position to check- Gibt zurück:
- true if the position is covered by the battleship, false otherwise
-
isDestroyed
public boolean isDestroyed()Determines if the battleship has been completely destroyed. A battleship is considered destroyed if all of its positions have been hit.- Gibt zurück:
- true if the battleship is destroyed, false otherwise
- Siehe auch:
-
collidesWith
Checks whether this battleship collides with another battleship. Two battleships collide if any of their occupied positions overlap.- Parameter:
other- the other battleship to check collision with- Gibt zurück:
- true if the battleships collide, false otherwise
-
toString
Returns a string representation of the battleship, including its length, position, and rotation. -
accept
Accepts a visitor that returns a value of typeT. This method is part of the Visitor design pattern. -
accept
Accepts a visitor that does not return a value. This method is part of the Visitor design pattern.
-