Skip to content

[US-03] Track ship damage, announce sunk, and end the game

Ivan Esau requested to merge feature/issue-3-us-03-track-ship-damage-announ into master

Description

This merge request implements the third user story for the Battleship game: tracking ship damage, announcing when ships are sunk, and ending the game when a fleet is destroyed.

Requirements Implemented

  1. Track hits per ship - Implemented damage tracking for each ship
  2. Announce ship as 'sunk' - Added logic to detect when all squares of a ship are hit
  3. End game when fleet destroyed - Added victory detection and game end logic
  4. Provide New Game functionality - Implemented game reset capability

Acceptance Criteria Verified

  • Given the last undamaged square of a ship is hit, when the result is processed, then that ship is announced 'sunk'.
  • 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.
  • Given a finished match, when New Game is chosen, then both boards reset to covered, unplaced state.

Technical Implementation

  • Added Ship entity with damage tracking and sunk status
  • Enhanced Game class with victory detection logic
  • Implemented game state management for end-game scenarios
  • Added comprehensive test coverage for all acceptance criteria

Testing

All acceptance criteria are covered by unit tests in Issue3AcceptanceCriteriaTest.java:

  • Test for ship sinking detection
  • Test for game end condition
  • Test for new game functionality

Closes #3

Merge request reports

Loading