Package battleship.model
Class Ship
java.lang.Object
battleship.model.Ship
public class Ship
extends java.lang.Object
player's ship class
-
Field Summary
Fields Modifier and Type Field Description private Pair<java.lang.Integer,java.lang.Integer>
coords
base coordinates of the shipprivate Direction
direction
(package private) Pair<java.lang.Integer,java.lang.Integer>[]
fullCoords
ship full coordinates calculate thank to base coordinates, direction and sizeprivate boolean
isDrown
if true the ship is destroyedprivate int
size
ship size -
Constructor Summary
-
Method Summary
Modifier and Type Method Description Pair<java.lang.Integer,java.lang.Integer>
getCoords()
Direction
getDirection()
Pair<java.lang.Integer,java.lang.Integer>[]
getFullCoords()
int
getSize()
boolean
isDrown()
void
recalculateFullCoords()
recalculate all coords based on this base coords, direction and sizevoid
setCoords(Pair<java.lang.Integer,java.lang.Integer> c)
void
setDirection(Direction d)
void
setDrown()
setisDrown
to truejava.lang.String
toString()
void
updateIsDrown(Player player)
update valueisDrown
to true ifplayer
hit all of ship boxesMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Field Details
-
coords
base coordinates of the ship -
size
private final int sizeship size -
fullCoords
ship full coordinates calculate thank to base coordinates, direction and size -
direction
-
isDrown
private boolean isDrownif true the ship is destroyed
-
-
Constructor Details
-
Ship
-
-
Method Details
-
setDirection
-
setCoords
-
setDrown
public void setDrown()setisDrown
to true -
isDrown
public boolean isDrown() -
getSize
public int getSize() -
getDirection
-
getCoords
-
recalculateFullCoords
public void recalculateFullCoords()recalculate all coords based on this base coords, direction and size -
getFullCoords
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
updateIsDrown
update valueisDrown
to true ifplayer
hit all of ship boxes- Parameters:
player
- the opponent of this ship owner
-