public abstract class AbstractShip extends java.lang.Object implements Ship
Modifier | Constructor and Description |
---|---|
protected |
AbstractShip() |
protected |
AbstractShip(Point2d startingPosition) |
protected |
AbstractShip(Point2d startingPosition,
ShipDirection direction) |
Modifier and Type | Method and Description |
---|---|
boolean |
containsPosition(Point2d point)
Returns
true if this ship contains a point specified by the
parameter. |
boolean |
equals(java.lang.Object o) |
java.util.List<Point2d> |
getAllPositions()
Gets all points used by this ship.
|
java.util.List<Point2d> |
getProjectionPoints(Point2d point)
Returns temporary projection points of the ship determined by the point
given in the input.
|
java.util.Optional<Point2d> |
getStartingPosition()
Gets the starting position of this ship.
|
int |
hashCode() |
boolean |
isPlaced()
Returns
true if this ship was placed. |
boolean |
isSunk()
Returns
true if the ship was sunk. |
void |
place(Point2d startingPosition)
Places a ship where specified with standard Direction
(EAST).
|
void |
place(Point2d startingPosition,
ShipDirection direction)
Places a ship where specified.
|
void |
resetPlacement()
Resets the placement of this ship.
|
boolean |
shoot(Shot shot)
Tries to shoot this ship.
|
void |
switchDirection(ShipDirection direction)
Not supported yet.
|
abstract java.lang.String |
toString() |
protected AbstractShip()
protected AbstractShip(Point2d startingPosition)
protected AbstractShip(Point2d startingPosition, ShipDirection direction)
public boolean containsPosition(Point2d point)
Ship
true
if this ship contains a point specified by the
parameter.containsPosition
in interface Ship
point
- Point2d
true
if this ship contains the specified pointpublic void place(Point2d startingPosition, ShipDirection direction)
Ship
place
in interface Ship
startingPosition
- Point2d
direction
- ShipDirection
public void place(Point2d startingPosition)
Ship
public void resetPlacement()
Ship
resetPlacement
in interface Ship
public boolean shoot(Shot shot)
Ship
true
if the ship was hit,
false
otherwise.public java.util.List<Point2d> getAllPositions()
Ship
getAllPositions
in interface Ship
public boolean isPlaced()
Ship
true
if this ship was placed.public java.util.Optional<Point2d> getStartingPosition()
Ship
getStartingPosition
in interface Ship
public java.util.List<Point2d> getProjectionPoints(Point2d point)
Ship
getProjectionPoints
in interface Ship
point
- point where the ship will startPoint2d
public boolean isSunk()
Ship
true
if the ship was sunk.public void switchDirection(ShipDirection direction)
switchDirection
in interface Ship
direction
- ShipDirection
java.lang.UnsupportedOperationException
- unsupportedpublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public abstract java.lang.String toString()
toString
in class java.lang.Object