Package battleship
Class Ship
java.lang.Object
battleship.Ship
- All Implemented Interfaces:
IShip
The type Ship.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionRetrieves a list of positions adjacent to the ship's current positions.Gets bearing.intGets bottom most pos.Gets category.intGets left most pos.Gets position.Gets positions.intGets right most pos.getSize()Gets size.intGets top most pos.booleanOccupies boolean.voidShoot.voidsink()Sink.booleanStill floating boolean.booleantooCloseTo(IPosition pos) Too close to boolean.booleantooCloseTo(IShip other) Too close to boolean.toString()To string string.
-
Field Details
-
positions
The Positions occupied by the ship.
-
-
Constructor Details
-
Ship
Create ships- Parameters:
category- The category of ships of interestbearing- The bearing of ships of interestpos- The position of ships of interestsize- The number of positions occupied by the ship
-
-
Method Details
-
getCategory
Gets category.- Specified by:
getCategoryin interfaceIShip- Returns:
- the category
-
getPositions
Gets positions.- Specified by:
getPositionsin interfaceIShip- Returns:
- the positions
-
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:
getAdjacentPositionsin interfaceIShip- Returns:
- a list of IPosition objects representing adjacent positions
-
getPosition
Gets position.- Specified by:
getPositionin interfaceIShip- Returns:
- the position
-
getBearing
Gets bearing.- Specified by:
getBearingin interfaceIShip- Returns:
- the bearing
-
getSize
Gets size. -
stillFloating
public boolean stillFloating()Still floating boolean.- Specified by:
stillFloatingin interfaceIShip- Returns:
- the boolean
-
getTopMostPos
public int getTopMostPos()Gets top most pos.- Specified by:
getTopMostPosin interfaceIShip- Returns:
- the top most pos
-
getBottomMostPos
public int getBottomMostPos()Gets bottom most pos.- Specified by:
getBottomMostPosin interfaceIShip- Returns:
- the bottom most pos
-
getLeftMostPos
public int getLeftMostPos()Gets left most pos.- Specified by:
getLeftMostPosin interfaceIShip- Returns:
- the left most pos
-
getRightMostPos
public int getRightMostPos()Gets right most pos.- Specified by:
getRightMostPosin interfaceIShip- Returns:
- the right most pos
-
occupies
Occupies boolean. -
tooCloseTo
Too close to boolean.- Specified by:
tooCloseToin interfaceIShip- Parameters:
other- the other- Returns:
- the boolean
-
tooCloseTo
Too close to boolean.- Specified by:
tooCloseToin interfaceIShip- Parameters:
pos- the pos- Returns:
- the boolean
-
shoot
Shoot. -
sink
public void sink()Sink. -
toString
To string string.
-