Package battleship
Class Fleet
java.lang.Object
battleship.Fleet
- All Implemented Interfaces:
IFleet
The type Fleet.
-
Field Summary
Fields inherited from interface battleship.IFleet
FLEET_SIZE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd ship boolean.static IFleetCreates a randomly generated fleet containing ships of various predefined types.Gets floating ships.getShips()Gets ships.getShipsLike(String category) Gets ships like.Gets sunk ships.voidThis operation prints all the ships of a fleet but not yet shotvoidprintShips(List<IShip> ships) This operation prints all the given shipsvoidprintShipsByCategory(String category) This operation prints all the ships of a fleet belonging to a particular categoryvoidThis operation shows the state of a fleetShip at ship.
-
Constructor Details
-
Fleet
public Fleet()Instantiates a new Fleet.
-
-
Method Details
-
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
Gets ships. -
addShip
Add ship boolean. -
getShipsLike
Gets ships like.- Specified by:
getShipsLikein interfaceIFleet- Parameters:
category- the category- Returns:
- the ships like
-
getFloatingShips
Gets floating ships.- Specified by:
getFloatingShipsin interfaceIFleet- Returns:
- the floating ships
-
getSunkShips
Gets sunk ships.- Specified by:
getSunkShipsin interfaceIFleet- Returns:
- the sunk ships
-
shipAt
Ship at ship. -
printShips
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:
printStatusin interfaceIFleet
-
printShipsByCategory
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
-