[US-03] Track ship damage, announce sunk, and end the game
Implementation Summary
This merge request implements the complete ship damage tracking and game completion functionality for US-03.
Requirements Implemented
-
Shipclass tracks hits per position with boolean array -
isSunk()method checks if all positions are hit -
getHitCount()method provides current damage status
- Ship sinking detection in
Board.allShipsSunk() - Game state management in
Game.executeShot() - Integration with game flow for announcements
-
Game.getWinner()method identifies winner -
Game.executeShot()throwsIllegalStateExceptionwhen game finished -
Player.hasLost()method checks if player has lost
-
GameService.createNewGame()resets all state - Complete board and ship reset functionality
Acceptance Criteria Validated
- Test:
acceptanceCriterion1_lastUndamagedSquareHit_shipAnnouncedSunk() - Validates ship sinking detection and announcement
- Test:
acceptanceCriterion2_finalEnemyShipSunk_matchEndsWithWinnerAndNoFurtherShots() - Validates game completion and input blocking
- Test:
acceptanceCriterion3_finishedMatch_newGameResetsBoards() - Validates complete game state reset
Technical Implementation
Core Classes:
-
Ship: Damage tracking withhits[]array andisSunk()method -
Board: Ship management withallShipsSunk()detection -
Game: Game state management withFINISHEDstate and winner determination -
Player: Loss detection withhasLost()method
Test Coverage:
- Comprehensive acceptance criteria tests in
AcceptanceCriteriaTest_Issue3.java - Additional validation tests for edge cases
- Integration tests for complete game flow
Files Modified/Created
Model Layer:
-
Ship.java- Enhanced with damage tracking -
Board.java- Added ship sinking detection -
Game.java- Added game completion logic -
Player.java- Added loss detection
Service Layer:
-
GameService.java- Game flow management
Test Layer:
-
AcceptanceCriteriaTest_Issue3.java- Complete acceptance criteria validation
Closes #3