Class Ship

java.lang.Object
battleship.model.ships.Ship
Direct Known Subclasses:
Battleship, Carrier, Cruiser, Destroyer, Submarine

public abstract class Ship extends Object
  • Field Details

    • health

      protected int health
  • Constructor Details

    • Ship

      protected Ship(int health)
  • Method Details

    • hitTheShip

      public HealthReport hitTheShip(FiringMode firingMode)
      Hit the ship with firing mode.
      Parameters:
      firingMode - if TORPEDO_FIRING_MODE -> ship immediately get sunk. if GENERAL_FIRING_MODE -> health--.
      Returns:
      healthReport with health remaining and power(health) of attack.
    • getLength

      public abstract int getLength()
      Returns:
      length of the ship (MAX_HEALTH = length).
    • restoreHealthInRecoveryMode

      public abstract void restoreHealthInRecoveryMode()
      When the recovery mode is enabled this method restore. health of the ship to MAX_HEALTH (depends on the ship type).
    • convertInputIntegersToShips

      public static List<Ship> convertInputIntegersToShips(int[] counters)
      Converts input integers, where these numbers are listed in the order which corresponds to ship types size, to list of ships.
      Parameters:
      counters - Array of integers.
      Returns:
      List of the ships (sorted by length descending)