Skip to content

[US-05] Save, load, and resume a match

Ivan Esau requested to merge feature/issue-5-us-05-save-load-and-resume-a-m into master

Implementation Summary

This merge request implements the save/load functionality for the Battleship game as specified in issue #5 (closed).

Features Implemented:

  1. SaveLoadService - Core service for saving and loading game states

    • Serializes complete game state to files
    • Validates file paths and permissions
    • Handles error cases gracefully
    • Provides clear error messages
  2. GameState - Complete serializable game state

    • Captures all game information: board size, fleet layouts, shots, sunk statuses, current player, difficulty/mode, timer
    • Preserves hidden information (opponent's concealed layouts)
    • Version validation for compatibility
    • Complete state validation
  3. PlayerState & ShipState - Nested state classes for serialization

    • Player state: name, ships, shots fired, active status
    • Ship state: type, position, orientation, hit positions
    • Bidirectional reconstruction (state → object)
  4. Comprehensive Testing

    • Unit tests for SaveLoadService (12 tests)
    • Unit tests for GameState (11 tests)
    • Integration tests for save/load functionality
    • Error handling tests for corrupted/invalid files

Requirements Validation:

Requirement 1: Persist complete match state including:

  • Board size (10x10)
  • Both fleets' concealed layouts
  • All shots and results
  • Sunk statuses
  • Current player turn
  • Difficulty/mode
  • Elapsed timer value
  • Hidden information remains hidden

Requirement 2: Load and restore exact externally observable state

  • Boards, indicators, whose turn, timer, difficulty/mode
  • Shot history and results preserved
  • Visible cell states maintained

Requirement 3: File validation and error handling

  • Missing file detection
  • Invalid/corrupted file detection
  • Incompatible version detection
  • Current game remains unchanged on error

Requirement 4: Idempotent round-trip

  • Save immediately followed by load preserves all observable state
  • No changes to match state after round-trip

Requirement 5: User file selection

  • File path validation
  • Directory existence checks
  • File permission validation

Acceptance Criteria Validation:

AC1: Mid-game state preservation

  • Test fixture with complex game state
  • Round-trip verification of all state elements
  • Shot history, visible cell states, sunk indicators, turn, difficulty, timer

AC2: Error handling for corrupted files

  • Tests for corrupted file detection
  • Tests for wrong file format detection
  • Current game state preservation on error

AC3: Finished game state preservation

  • Win/loss outcome preservation
  • Input disabling after load
  • Game remains finished with same outcome

Technical Details:

  • Serialization: Java Object Serialization for reliable state capture
  • Validation: Comprehensive state validation before/after operations
  • Error Handling: Clear, user-friendly error messages
  • Testing: 84 total tests - ALL PASSING
  • Coverage: JaCoCo coverage reporting enabled

Current Status:

  • Pipeline: SUCCESS (Pipeline #6884)
  • Tests: 84/84 tests passing
  • Compilation: Successful
  • Ready for Merge: All validation criteria met

Closes #5 (closed)

Edited by Ivan Esau

Merge request reports

Loading