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 announcements, and game ending functionality for Battleship game.

Changes

  • Added ship damage tracking with hit recording
  • Implemented ship sunk detection and announcements
  • Added game ending logic when all ships are sunk
  • Implemented new game functionality
  • Added comprehensive test coverage

Requirements Implemented

Track hits per ship and determine when all squares of a ship are hit Upon completion, announce the ship as 'sunk' When all ships of a player are sunk, declare victory for the opponent and disable further input Provide New Game to start a fresh match

Acceptance Criteria Validated

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 Details

  • Added Ship.isSunk() method to detect when all positions are hit
  • Enhanced Game.processShot() to handle sunk ships and game ending
  • Added Player.hasLost() to check if all ships are sunk
  • Implemented Game.newGame() for reset functionality
  • Comprehensive test coverage in ShipTest.java and GameTest.java

Closes #3

Merge request reports

Loading