Class Fleet

java.lang.Object
battleship.Fleet
All Implemented Interfaces:
IFleet

public class Fleet extends Object implements IFleet
The type Fleet.
  • Constructor Details

    • Fleet

      public Fleet()
      Instantiates a new Fleet.
  • Method Details

    • createRandom

      public static IFleet createRandom()
      Creates a randomly generated fleet containing ships of various predefined types. Each ship is assigned a random bearing and position. If a ship cannot be added due to constraints (e.g., collision or boundary issues), it will be retried.
      Returns:
      a fully constructed and valid fleet as an instance of IFleet
    • getShips

      public List<IShip> getShips()
      Gets ships.
      Specified by:
      getShips in interface IFleet
      Returns:
      the ships
    • addShip

      public boolean addShip(IShip s)
      Add ship boolean.
      Specified by:
      addShip in interface IFleet
      Parameters:
      s - the s
      Returns:
      the boolean
    • getShipsLike

      public List<IShip> getShipsLike(String category)
      Gets ships like.
      Specified by:
      getShipsLike in interface IFleet
      Parameters:
      category - the category
      Returns:
      the ships like
    • getFloatingShips

      public List<IShip> getFloatingShips()
      Gets floating ships.
      Specified by:
      getFloatingShips in interface IFleet
      Returns:
      the floating ships
    • getSunkShips

      public List<IShip> getSunkShips()
      Gets sunk ships.
      Specified by:
      getSunkShips in interface IFleet
      Returns:
      the sunk ships
    • shipAt

      public IShip shipAt(IPosition pos)
      Ship at ship.
      Specified by:
      shipAt in interface IFleet
      Parameters:
      pos - the pos
      Returns:
      the ship
    • printShips

      public void printShips(List<IShip> ships)
      This operation prints all the given ships
      Parameters:
      ships - The list of ships
    • printStatus

      public void printStatus()
      This operation shows the state of a fleet
      Specified by:
      printStatus in interface IFleet
    • printShipsByCategory

      public void printShipsByCategory(String category)
      This operation prints all the ships of a fleet belonging to a particular category
      Parameters:
      category - The category of ships of interest
    • printFloatingShips

      public void printFloatingShips()
      This operation prints all the ships of a fleet but not yet shot