Please note, Sherpa may occasionally provide incomplete or inaccurate information. Always verify critical details and double-check suggested changes before implementation.
The issue at hand is to extend the battleship board size from a range of 6-15 cells to a new range of 6-25 cells. This involves modifying the existing logic that constrains the board dimensions and potentially affecting how ships are placed and managed on the board.
Relevant Files
AbstractPlayer.java: Handles player actions, including board setup and ship placement logic.
BattleshipSalvo.java: Manages game flow, including board initialization and player interactions.
Board.java: Represents the game board and its functionalities.
ViewImpl.java: Manages user input and output, including board dimensions.
ShipType.java: Defines the types of ships and their sizes.
Changes Required
1. AbstractPlayer.java
Method to Modify: setup(int height, int width, Map<ShipType, Integer> specifications)
Guidance: Update the method's Javadoc to reflect the new height and width range of [6, 25]. Ensure that any logic that relies on the previous size constraints is updated accordingly.
/**
* Given the specifications for a BattleSalvo board, return a list of ships with their locations
* on the board.
*
* @param height the height of the board, range: [6, 25] inclusive
* @param width the width of the board, range: [6, 25] inclusive
*/
2. BattleshipSalvo.java
Method to Modify: initBoard()
Guidance: Change the validation checks for height and width to allow values up to 25. This will involve modifying the conditions in the try block.
Constructor to Modify: Board(int height, int width)
Guidance: Ensure that the board can handle the larger dimensions. If there are any assumptions about the maximum size of the board elsewhere in the code, those should be reviewed and updated.
4. ViewImpl.java
Method to Modify: initFleet()
Guidance: When displaying messages to the user regarding fleet specifications, ensure that the maximum board size is communicated correctly.
view.displayString(
"\nPlease enter your fleet in the order [Carrier, Battleship, Destroyer, Submarine].\n"
+ "Remember, your fleet may not exceed size " + minBoardSize + ".\n"
+ "-".repeat(66) + "\n");
5. ShipType.java
Consideration: If there are any ship types that have size constraints based on the board size, review those to ensure they are still valid within the new board size.
Summary
To implement the change, you will need to adjust the relevant methods and classes to accommodate the new board size of 6-25 cells. Focus on updating the validation logic in BattleshipSalvo, ensuring that AbstractPlayer reflects the new board dimensions, and confirming that the Board and ViewImpl classes can handle the larger board sizes. After making these changes, thoroughly test the game to ensure that all functionalities work as expected with the new board dimensions.
The issue at hand is to extend the battleship board size from a range of 6-15 cells to a new range of 6-25 cells. This involves modifying the existing logic that constrains the board dimensions and potentially affecting how ships are placed and managed on the board.
Relevant Files
AbstractPlayer.java
: Handles player actions, including board setup and ship placement logic.BattleshipSalvo.java
: Manages game flow, including board initialization and player interactions.Board.java
: Represents the game board and its functionalities.ViewImpl.java
: Manages user input and output, including board dimensions.ShipType.java
: Defines the types of ships and their sizes.Changes Required
1.
AbstractPlayer.java
setup(int height, int width, Map<ShipType, Integer> specifications)
[6, 25]
. Ensure that any logic that relies on the previous size constraints is updated accordingly.2.
BattleshipSalvo.java
initBoard()
height
andwidth
to allow values up to 25. This will involve modifying the conditions in thetry
block.3.
Board.java
Board(int height, int width)
4.
ViewImpl.java
initFleet()
5.
ShipType.java
Summary
To implement the change, you will need to adjust the relevant methods and classes to accommodate the new board size of 6-25 cells. Focus on updating the validation logic in
BattleshipSalvo
, ensuring thatAbstractPlayer
reflects the new board dimensions, and confirming that theBoard
andViewImpl
classes can handle the larger board sizes. After making these changes, thoroughly test the game to ensure that all functionalities work as expected with the new board dimensions.