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 ship
    private Direction direction  
    (package private) Pair<java.lang.Integer,​java.lang.Integer>[] fullCoords
    ship full coordinates calculate thank to base coordinates, direction and size
    private boolean isDrown
    if true the ship is destroyed
    private int size
    ship size
  • Constructor Summary

    Constructors
    Constructor Description
    Ship​(Pair<java.lang.Integer,​java.lang.Integer> coords, int size, Direction direction)  
  • 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 size
    void setCoords​(Pair<java.lang.Integer,​java.lang.Integer> c)  
    void setDirection​(Direction d)  
    void setDrown()
    set isDrown to true
    java.lang.String toString()  
    void updateIsDrown​(Player player)
    update value isDrown to true if player hit all of ship boxes

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • coords

      private Pair<java.lang.Integer,​java.lang.Integer> coords
      base coordinates of the ship
    • size

      private final int size
      ship size
    • fullCoords

      final Pair<java.lang.Integer,​java.lang.Integer>[] fullCoords
      ship full coordinates calculate thank to base coordinates, direction and size
    • direction

      private Direction direction
    • isDrown

      private boolean isDrown
      if true the ship is destroyed
  • Constructor Details

    • Ship

      public Ship​(Pair<java.lang.Integer,​java.lang.Integer> coords, int size, Direction direction)
  • Method Details

    • setDirection

      public void setDirection​(Direction d)
    • setCoords

      public void setCoords​(Pair<java.lang.Integer,​java.lang.Integer> c)
    • setDrown

      public void setDrown()
      set isDrown to true
    • isDrown

      public boolean isDrown()
    • getSize

      public int getSize()
    • getDirection

      public Direction getDirection()
    • getCoords

      public Pair<java.lang.Integer,​java.lang.Integer> getCoords()
    • recalculateFullCoords

      public void recalculateFullCoords()
      recalculate all coords based on this base coords, direction and size
    • getFullCoords

      public Pair<java.lang.Integer,​java.lang.Integer>[] getFullCoords()
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • updateIsDrown

      public void updateIsDrown​(Player player)
      update value isDrown to true if player hit all of ship boxes
      Parameters:
      player - the opponent of this ship owner