Skip to content

[US-03] Ship damage, announcing sunk, and finishing

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

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

When the last healthy square of a ship gets hit, that ship should be indicated as sunk

  • Implemented in Ship.recordHit() method
  • Returns true when ship is sunk
  • Status method shows "SUNK" for sunk ships

When the final enemy ship is destroyed, the game should end, show who won, and not allow further shooting

  • Implemented in GameService.processShot()
  • Checks if all ships are sunk after each hit
  • Ends game and blocks further inputs

When a finished game is restarted, both boards become empty and hidden again

  • 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

Merge request reports

Loading