Package battleship
Interface IGame
- All Known Implementing Classes:
Game
public interface IGame
The interface Game.
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidFires a set of shots in a given move.fireSingleShot(IPosition pos, boolean isRepeated) Fires a single shot at the specified position and indicates whether the shot is valid, repeated, and if it hit or sank a ship.Gets the alien fleetGets alien movesintgetHits()Gets hits.intGets invalid shots.Gets my fleet.Gets my movesintGets remaining ships.intGets repeated shots.intGets sunk ships.voidover()voidprintAlienBoard(boolean show_shots, boolean show_legend) Print the alien board (alien fleet + my shots).voidprintMyBoard(boolean show_shots, boolean show_legend) Print my board (my fleet + alien shots).Simulates a random enemy firing action on the game board.readEnemyFire(Scanner in) Reads the result of an enemy firing action from input and interprets it.
-
Method Details
-
randomEnemyFire
String randomEnemyFire()Simulates a random enemy firing action on the game board.- Returns:
- a
Stringindicating the result of the firing action, such as details about a hit, a miss, or other outcomes
-
readEnemyFire
Reads the result of an enemy firing action from input and interprets it.- Parameters:
in- theScannerto read the input from, which provides the details of the enemy fire- Returns:
- a
Stringdescribing the outcome of the enemy fire, such as a hit, a miss, or other results
-
fireShots
Fires a set of shots in a given move.- Parameters:
shots- the positions where the shots are fired
-
fireSingleShot
Fires a single shot at the specified position and indicates whether the shot is valid, repeated, and if it hit or sank a ship.- Parameters:
pos- the position to fire the shot at, represented as an instance ofIPositionisRepeated- a boolean indicating if the shot is a repeated attempt at the given position- Returns:
- a
ShotResultcontaining details such as the validity of the shot, whether it was repeated, the ship (if any) affected, and whether the ship was sunk
-
getMyFleet
IFleet getMyFleet()Gets my fleet.- Returns:
- my fleet
-
getAlienMoves
Gets alien moves- Returns:
- the alien moves
-
getAlienFleet
IFleet getAlienFleet()Gets the alien fleet- Returns:
- the alien fleet
-
getMyMoves
Gets my moves- Returns:
- my moves
-
getRepeatedShots
int getRepeatedShots()Gets repeated shots.- Returns:
- the repeated shots
-
getInvalidShots
int getInvalidShots()Gets invalid shots.- Returns:
- the invalid shots
-
getHits
int getHits()Gets hits.- Returns:
- the hits
-
getSunkShips
int getSunkShips()Gets sunk ships.- Returns:
- the sunk ships
-
getRemainingShips
int getRemainingShips()Gets remaining ships.- Returns:
- the remaining ships
-
printMyBoard
void printMyBoard(boolean show_shots, boolean show_legend) Print my board (my fleet + alien shots). -
printAlienBoard
void printAlienBoard(boolean show_shots, boolean show_legend) Print the alien board (alien fleet + my shots). -
over
void over()
-