giovabattelli / terminal-battleship

Play a game of battleship (with modified game rules) against a basic AI in the terminal.
0 stars 0 forks source link

Add support for a battleship board of size 25 cells; instead of board size being between 6-15, it can be between 6-25 cells. #92

Open giovabattelli opened 4 days ago

trysherpa[bot] commented 4 days ago

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

Changes Required

1. AbstractPlayer.java

/**
 * 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

if (height < 6 || height > 25 || width < 6 || width > 25 || inputs.length > 2) {
    throw new Exception();
}

3. Board.java

4. ViewImpl.java

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

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.