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

Implements ship damage tracking, sunk detection, and game end conditions for the Battleship game.

Requirements Implemented

  1. Track hits per ship and determine when all squares of a ship are hit

    • Ship class tracks hit positions and calculates sunk status
    • Player class updates ship damage when receiving shots
  2. Upon completion, announce the ship as 'sunk'

    • ShotResult includes ship sunk status and type
    • Player.receiveShot() returns detailed shot results
  3. When all ships of a player are sunk, declare victory for the opponent and disable further input

    • Game.checkGameEnd() detects fleet destruction
    • Game state transitions to FINISHED with winner
  4. 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() and ShotResult.isShipSunk()
  • 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() and Game.isGameFinished()
  • Given a finished match, when New Game is chosen, then both boards reset to covered, unplaced state

    • Test: PlayerDamageTest.testPlayerReset()
    • Implementation: Game.reset() and Player.reset()

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

Merge request reports

Loading