[US-03] Ship damage, announcing sunk, and finishing
Description
Implements ship damage tracking, sunk detection, game end conditions, and restart functionality for the Battleship game.
Changes
Core Features
- Ship damage tracking: Each ship tracks hit positions and remaining health
- Sunk detection: Automatically detects when all ship positions are hit
- Game end conditions: Ends game when all ships of one player are sunk
- Restart functionality: Allows starting a new game with reset boards
Implementation Details
-
Ship.java: Added hit tracking, sunk detection, and health management -
GameService.java: Added shot processing with hit/miss logic and game state management -
GameState.java: Added game status tracking and player switching - Comprehensive test coverage for all new functionality
Acceptance Criteria Met
- Implemented in
Ship.recordHit()method - Returns true when ship is sunk
- Status method shows "SUNK" for sunk ships
- Implemented in
GameService.processShot() - Checks if all ships are sunk after each hit
- Ends game and blocks further inputs
- Implemented in
GameService.resetGame() - Resets all ships to unplaced state
- Clears game state for new match
Testing
- Comprehensive unit tests for ship damage tracking
- Integration tests for game flow and end conditions
- Boundary tests for edge cases
Closes #3