[US-05] Save, load, and resume a match
Implementation Summary
This merge request implements the save/load functionality for the Battleship game as specified in issue #5 (closed).
Features Implemented:
-
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
-
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
-
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)
-
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:
- 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
- Boards, indicators, whose turn, timer, difficulty/mode
- Shot history and results preserved
- Visible cell states maintained
- Missing file detection
- Invalid/corrupted file detection
- Incompatible version detection
- Current game remains unchanged on error
- Save immediately followed by load preserves all observable state
- No changes to match state after round-trip
- File path validation
- Directory existence checks
- File permission validation
Acceptance Criteria Validation:
- Test fixture with complex game state
- Round-trip verification of all state elements
- Shot history, visible cell states, sunk indicators, turn, difficulty, timer
- Tests for corrupted file detection
- Tests for wrong file format detection
- Current game state preservation on error
- 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