[US-02] Take turns firing with hit/miss feedback
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
- Verified by
testAcceptanceCriterion1_UntargetedCoordinate_ShowsResultAndMarksUsed
- Verified by
testAcceptanceCriterion2_AlreadyTargetedCoordinate_BlocksActionAndPreservesTurn
- 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)