Skip to content

[US-02] Take turns firing with hit/miss feedback

Ivan Esau requested to merge feature/issue-2-us-02-take-turns-firing-with-h into master

Implementation Summary

This merge request implements the turn-based firing system for the Battleship game as specified in issue #2 (closed). The implementation provides:

Core Features

  • Alternating turns: Enforces strict turn order between players
  • Shot validation: Prevents firing at already targeted coordinates
  • Hit/miss feedback: Immediate feedback with detailed messages
  • Turn preservation: Maintains turn order even when shots are blocked

Key Implementation Details

Game Logic (Game.java):

  • fireShot() method handles all shot validation and execution
  • Turn switching logic: miss → switch turn, hit without sinking → keep turn, hit with sinking → switch turn
  • Comprehensive validation including game state, coordinate validity, and target availability

Board Management (Board.java, Cell.java):

  • Cell states track hit/miss status and prevent duplicate targeting
  • Opponent view conceals ship locations while showing hit/miss results
  • Player view shows own ship positions and hit/miss status

Testing Coverage:

  • All 3 acceptance criteria from issue #2 (closed) are fully tested
  • Comprehensive test suite covering edge cases and boundary conditions
  • Turn sequence validation with mixed hits and misses

Acceptance Criteria Validation

AC1: "Given A1 has not been targeted, when the player fires at A1, then the result is shown (hit/miss) and A1 becomes marked as used"

  • Verified by testAcceptanceCriterion1_UntargetedCoordinate_ShowsResultAndMarksUsed

AC2: "Given A1 is already targeted, when the player attempts A1 again, then the system blocks the action and preserves turn order rules"

  • Verified by testAcceptanceCriterion2_AlreadyTargetedCoordinate_BlocksActionAndPreservesTurn

AC3: "Given a turn completes, when control passes, then only the next player can act"

  • Verified by testAcceptanceCriterion3_TurnCompletion_PassesControlToNextPlayer

Pipeline Status

  • Pipeline #8657: SUCCESS
  • All tests passing: 100%
  • Compilation successful: 100%

Files Modified

  • src/main/java/org/example/battleship/model/Game.java - Core turn-based firing logic
  • src/main/java/org/example/battleship/model/Player.java - Player state management
  • src/main/java/org/example/battleship/model/Board.java - Board and cell management
  • src/main/java/org/example/battleship/model/Cell.java - Cell state tracking
  • src/test/java/org/example/battleship/TurnBasedFiringAcceptanceTest.java - Acceptance criteria tests

Closes #2 (closed)

Merge request reports

Loading