[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.
Requirements Implemented
- Game state management with
GameState.PLAYER1_TURNandGameState.PLAYER2_TURN - Automatic turn switching on misses
- Turn preservation on hits (player gets another turn)
-
Game.executeShot()method handles shot execution - Coordinate validation and boundary checking
- Integration with player tracking boards
-
Player.ShotResultenum with HIT, MISS, SUNK, ALREADY_TARGETED, INVALID - Automatic tracking board updates for both players
- Immediate feedback through return values
-
Board.isCellTargeted()method checks if cell was already hit -
ShotResult.ALREADY_TARGETEDreturned for duplicate shots - Turn state preserved when duplicate shot attempted
Acceptance Criteria Validated
- Test:
testAcceptanceCriteria1_FirstShotAtUntargetedCoordinate_ShowsResultAndMarksUsed
- Test:
testAcceptanceCriteria2_AlreadyTargetedCoordinate_BlocksActionAndPreservesTurn
- Test:
testAcceptanceCriteria3_TurnCompletes_OnlyNextPlayerCanAct
Technical Implementation
Core Classes:
-
Game: Manages game state and turn logic -
Player: Handles player actions and tracking boards -
Board: Manages grid state and shot processing -
Cell: Represents individual grid cells
Key Features:
- Turn-based gameplay with proper state transitions
- Shot validation and result reporting
- Tracking board synchronization
- Comprehensive test coverage for all acceptance criteria
Testing
All acceptance criteria are covered by integration tests in AcceptanceCriteriaTest.java:
- Turn switching logic
- Shot result handling
- Duplicate shot prevention
- Game state preservation
Closes #2