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. #46

Open giovabattelli opened 1 month ago

sherpabotjohnny[bot] commented 1 month ago

Please note, Sherpa may occasionally provide incomplete or inaccurate information. Always verify critical details and double-check suggested changes before implementation.

Summary of the Problem

The issue requires modifying the existing Battleship game to support a board size of 25 cells, expanding the current range from 6-15 to 6-25 cells. This will involve updating the relevant code to ensure that the new dimensions are accepted and properly handled throughout the game logic.

Relevant Files

Suggested Changes by File

AbstractPlayer.java

@Override
public List<Ship> setup(int height, int width, Map<ShipType, Integer> specifications) {
    if (height < 6 || height > 25 || width < 6 || width > 25) {
        throw new IllegalArgumentException("Height and width must be between 6 and 25.");
    }
    // existing code...
}

BattleshipSalvo.java

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

Board.java

Player.java

ViewImpl.java

view.displayString("Please enter a valid board height and width below (6 to 25):\n");

Conclusion

To implement the change to support a battleship board of size 25 cells, you should focus on updating the relevant methods across the listed files to ensure they accept and validate the new size constraints. This approach will maintain the integrity of the game while expanding its functionality. Make sure to test the changes thoroughly to confirm that all parts of the game handle the new dimensions correctly.