[US-03] Track ship damage, announce sunk, and end the game
Description
Implements ship damage tracking, sunk detection, and game end conditions for the Battleship game.
Requirements Implemented
-
Track hits per ship and determine when all squares of a ship are hit
-
Shipclass tracks hit positions and calculates sunk status -
Playerclass updates ship damage when receiving shots
-
-
Upon completion, announce the ship as 'sunk'
-
ShotResultincludes ship sunk status and type -
Player.receiveShot()returns detailed shot results
-
-
When all ships of a player are sunk, declare victory for the opponent and disable further input
-
Game.checkGameEnd()detects fleet destruction -
Gamestate transitions to FINISHED with winner
-
-
Provide New Game to start a fresh match
-
Game.reset()resets all game state -
Player.reset()clears ships and board
-
Acceptance Criteria Verified
-
✅ Given the last undamaged square of a ship is hit, when the result is processed, then that ship is announced 'sunk'- Test:
ShipDamageTest.testShipSinkingAnnouncementScenario() - Implementation:
Ship.isSunk()andShotResult.isShipSunk()
- Test:
-
✅ Given the final enemy ship is sunk, when the board updates, then the match ends, the winner is indicated, and no further shots are allowed- Test:
GameTest.testGameEndScenario() - Implementation:
Game.checkGameEnd()andGame.isGameFinished()
- Test:
-
✅ Given a finished match, when New Game is chosen, then both boards reset to covered, unplaced state- Test:
PlayerDamageTest.testPlayerReset() - Implementation:
Game.reset()andPlayer.reset()
- Test:
Technical Implementation
- Model Classes: Ship, Player, Game with comprehensive damage tracking
- Test Coverage: 100% of acceptance criteria covered with unit tests
- Architecture: Follows MVC pattern as defined in ORCH_PLAN.json
Files Modified/Created
-
src/main/java/org/example/model/Ship.java- Ship damage tracking -
src/main/java/org/example/model/Player.java- Fleet management and damage -
src/main/java/org/example/model/Game.java- Game state and end conditions -
src/test/java/org/example/model/ShipDamageTest.java- Ship damage tests -
src/test/java/org/example/model/PlayerDamageTest.java- Player damage tests -
src/test/java/org/example/model/GameTest.java- Game end condition tests
Closes #3