Package battleship

Class Ship

java.lang.Object
battleship.Ship
All Implemented Interfaces:
IShip
Direct Known Subclasses:
Barge, Caravel, Carrack, Frigate, Galleon

public abstract class Ship extends Object implements IShip
The type Ship.
  • Field Details

    • positions

      protected List<IPosition> positions
      The Positions occupied by the ship.
  • Constructor Details

    • Ship

      public Ship(String category, Compass bearing, IPosition pos, int size)
      Create ships
      Parameters:
      category - The category of ships of interest
      bearing - The bearing of ships of interest
      pos - The position of ships of interest
      size - The number of positions occupied by the ship
  • Method Details

    • getCategory

      public String getCategory()
      Gets category.
      Specified by:
      getCategory in interface IShip
      Returns:
      the category
    • getPositions

      public List<IPosition> getPositions()
      Gets positions.
      Specified by:
      getPositions in interface IShip
      Returns:
      the positions
    • getAdjacentPositions

      public List<IPosition> getAdjacentPositions()
      Retrieves a list of positions adjacent to the ship's current positions. Adjacent positions are defined as neighboring positions that are not already occupied by the ship and are not duplicates in the final list.
      Specified by:
      getAdjacentPositions in interface IShip
      Returns:
      a list of IPosition objects representing adjacent positions
    • getPosition

      public IPosition getPosition()
      Gets position.
      Specified by:
      getPosition in interface IShip
      Returns:
      the position
    • getBearing

      public Compass getBearing()
      Gets bearing.
      Specified by:
      getBearing in interface IShip
      Returns:
      the bearing
    • getSize

      public Integer getSize()
      Gets size.
      Specified by:
      getSize in interface IShip
      Returns:
      the size
    • stillFloating

      public boolean stillFloating()
      Still floating boolean.
      Specified by:
      stillFloating in interface IShip
      Returns:
      the boolean
    • getTopMostPos

      public int getTopMostPos()
      Gets top most pos.
      Specified by:
      getTopMostPos in interface IShip
      Returns:
      the top most pos
    • getBottomMostPos

      public int getBottomMostPos()
      Gets bottom most pos.
      Specified by:
      getBottomMostPos in interface IShip
      Returns:
      the bottom most pos
    • getLeftMostPos

      public int getLeftMostPos()
      Gets left most pos.
      Specified by:
      getLeftMostPos in interface IShip
      Returns:
      the left most pos
    • getRightMostPos

      public int getRightMostPos()
      Gets right most pos.
      Specified by:
      getRightMostPos in interface IShip
      Returns:
      the right most pos
    • occupies

      public boolean occupies(IPosition pos)
      Occupies boolean.
      Specified by:
      occupies in interface IShip
      Parameters:
      pos - the pos
      Returns:
      the boolean
    • tooCloseTo

      public boolean tooCloseTo(IShip other)
      Too close to boolean.
      Specified by:
      tooCloseTo in interface IShip
      Parameters:
      other - the other
      Returns:
      the boolean
    • tooCloseTo

      public boolean tooCloseTo(IPosition pos)
      Too close to boolean.
      Specified by:
      tooCloseTo in interface IShip
      Parameters:
      pos - the pos
      Returns:
      the boolean
    • shoot

      public void shoot(IPosition pos)
      Shoot.
      Specified by:
      shoot in interface IShip
      Parameters:
      pos - the pos
    • sink

      public void sink()
      Sink.
      Specified by:
      sink in interface IShip
    • toString

      public String toString()
      To string string.
      Overrides:
      toString in class Object
      Returns:
      the string