Interface OceanInterface

All Known Implementing Classes:
Ocean

public interface OceanInterface
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    Ship[][]
    Provides access to the grid of ships in this Ocean.
    int
     
    int
     
    boolean
     
    boolean
    isOccupied(int row, int column)
    Checks if this coordinate is not empty; that is, if this coordinate does not contain an EmptySea reference.
    void
    Place all ten ships randomly on the (initially empty) ocean.
    void
    Prints the ocean.
    boolean
    shootAt(int row, int column)
    Fires a shot at this coordinate.
  • Method Details

    • placeAllShipsRandomly

      void placeAllShipsRandomly()
      Place all ten ships randomly on the (initially empty) ocean. Larger ships must be placed before smaller ones to avoid cases where it may be impossible to place the larger ships.
      See Also:
    • isOccupied

      boolean isOccupied(int row, int column)
      Checks if this coordinate is not empty; that is, if this coordinate does not contain an EmptySea reference.
      Parameters:
      row - the row (0 to 9) in which to check for a floating ship
      column - the column (0 to 9) in which to check for a floating ship
      Returns:
      true if the given location contains a ship, and false otherwise.
    • shootAt

      boolean shootAt(int row, int column)
      Fires a shot at this coordinate. This will update the number of shots that have been fired (and potentially the number of hits, as well). If a location contains a real, not sunk ship, this method should return true every time the user shoots at that location. If the ship has been sunk, additional shots at this location should return false.
      Parameters:
      row - the row (0 to 9) in which to shoot
      column - the column (0 to 9) in which to shoot
      Returns:
      true if the given location contains an afloat ship (not an EmptySea), false if it does not.
    • getShotsFired

      int getShotsFired()
      Returns:
      the number of shots fired in this game.
    • getHitCount

      int getHitCount()
      Returns:
      the number of hits recorded in this game.
    • getShipsSunk

      int getShipsSunk()
      Returns:
      the number of ships sunk in this game.
    • isGameOver

      boolean isGameOver()
      Returns:
      true if all ships have been sunk, otherwise false.
    • getShipArray

      Ship[][] getShipArray()
      Provides access to the grid of ships in this Ocean. The methods in the Ship class that take an Ocean parameter must be able to read and even modify the contents of this array. While it is generally undesirable to allow methods in one class to directly access instancce variables in another class, in this case there is no clear and elegant alternatives.
      Returns:
      the 10x10 array of ships.
    • print

      void print()
      Prints the ocean. To aid the user, row numbers should be displayed along the left edge of the array, and column numbers should be displayed along the top. Numbers should be 0 to 9, not 1 to 10. The top left corner square should be 0, 0.
      • Use 'S' to indicate a location that you have fired upon and hit a (real) ship
      • '-' to indicate a location that you have fired upon and found nothing there
      • 'x' to indicate a location containing a sunken ship
      • '.' (a period) to indicate a location that you have never fired upon.
      This is the only method in Ocean that has any printing capability, and it should never be called from within the Ocean class except for the purposes of debugging.