Class EmptySea


public class EmptySea extends Ship
Considered a type of Ship so that the Ocean's ship 2D array can consist of EmptySea references for empty tiles and proper ships for tiles with ships actually inside of them.
Author:
harry
  • Constructor Details

    • EmptySea

      public EmptySea()
      Sets the inherited length variable and initializes the hit array, based on the size of this Empty Sea (1 tiles).
  • Method Details

    • shootAt

      public boolean shootAt(int row, int column)
      Since an EmptySea is empty by definition, shooting at one will always be a miss.
      Overrides:
      shootAt in class Ship
      Parameters:
      row - the row of the shot
      column - the column of the shot
      Returns:
      false always, since nothing will be hit.
    • isSunk

      public boolean isSunk()
      Since an EmptySea is empty by definition, it is not possible that one can be sunk.
      Overrides:
      isSunk in class Ship
      Returns:
      false always, since nothing will be hit.
    • toString

      public String toString()
      Description copied from class: Ship
      Returns a single character String to use in the Ocean's print method. This method should return "x" if the ship has been sunk, and "S" if it has not yet been sunk. This method can only be used to print out locations in the ocean that have been shot at; it should not be used to print locations that have not been the target of a shot yet.
      Overrides:
      toString in class Ship
      Returns:
      "x" if this ship has been sunk, and "S" otherwise.
    • getShipType

      public String getShipType()
      Specified by:
      getShipType in class Ship
      Returns:
      "empty", indicating that this is an Empty sea tile.