Skip to content

[US-02] Alternating shooting with feedback

Ivan Esau requested to merge feature/issue-2-us-02-alternating-shooting-wit into master

Implementation Summary

This merge request implements the alternating shooting system for the Battleship game as described in Issue #2.

Features Implemented:

Core Game Logic:

  • Turn-based shooting system with automatic alternation
  • Hit/miss detection with proper feedback messages
  • Duplicate shot prevention (cannot shoot same coordinate twice)
  • Game over detection when all ships are sunk

User Interface:

  • Console-based game interface with board display
  • Real-time feedback for shots (HIT/MISS messages)
  • Turn indication and game state display

Technical Implementation:

  • Complete MVC architecture with model, service, and view layers
  • Comprehensive test coverage for all acceptance criteria
  • Proper error handling for invalid coordinates
  • Game state management with player switching

Acceptance Criteria Verified:

Criterion 1: When firing at A1 for the first time, a message appears showing hit or miss, and that field becomes marked.

  • Implemented in Game.shoot() method with proper hit detection
  • Verified by Issue2AcceptanceCriteriaTest.testFirstShotAtA1_ShowsHitMissAndMarksField()

Criterion 2: When the same field is targeted again, the shot does not go through, and the next player acts.

  • Implemented duplicate shot prevention in Game.shoot()
  • Verified by Issue2AcceptanceCriteriaTest.testDuplicateShotAtSameField_ShouldNotGoThrough()

Criterion 3: After one shot cycle finishes, the control changes so that only the other player can continue.

  • Implemented automatic turn switching in Game.shoot()
  • Verified by Issue2AcceptanceCriteriaTest.testControlChangesToOtherPlayer_AfterShotCycle()

Test Coverage:

  • All acceptance criteria covered by dedicated test class
  • Unit tests for individual components (Board, Game, Player, Ship)
  • Integration tests for game flow
  • Pipeline verification: Success (Pipeline #7357)

Files Modified/Created:

Model Layer:

  • Game.java - Core game logic with turn management
  • Player.java - Player state and board management
  • Board.java - Board state and shot tracking
  • Ship.java - Ship placement and health tracking
  • Coordinate.java - Coordinate validation and conversion

Service Layer:

  • GameService.java - Game flow and user interaction

View Layer:

  • ConsoleView.java - CLI interface for game display

Test Coverage:

  • Issue2AcceptanceCriteriaTest.java - All acceptance criteria
  • GameTest.java - Game logic unit tests
  • BoardTest.java - Board functionality tests
  • CoordinateTest.java - Coordinate validation tests

Closes #2

Merge request reports

Loading