[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).
Key Features Implemented:
Core Persistence:
-
GameStateclass with complete serializable game state -
GameService.saveGame()andGameService.loadGame()methods - File version validation and error handling
- Support for both single-player and two-player modes
State Preservation:
- Complete match state including board size, fleet layouts, shots, sunk status
- Current player turn, difficulty/mode, elapsed timer value
- Hidden information remains concealed from opponent after load
- Game finished state and winner preservation
Validation & Error Handling:
- File version compatibility checking
- Corrupted/invalid file detection
- Graceful error reporting without modifying current game
- File format validation with checksum-like validation
Acceptance Criteria Coverage:
-
✅ AC1: Save/load round-trip preserves complete state (shot history, visible cells, sunk indicators, turn, difficulty, timer) -
✅ AC2: Corrupted files show error and preserve current game -
✅ AC3: Finished games remain finished after load with same outcome
Technical Implementation:
- Java serialization for game state persistence
- Comprehensive test coverage with integration tests
- Idempotent round-trip verification
- File validation with version checking
Files Modified/Created:
-
src/main/java/org/example/model/GameState.java- Serializable game state -
src/main/java/org/example/service/GameService.java- Save/load operations -
src/test/java/org/example/integration/SaveLoadIntegrationTest.java- Acceptance criteria tests -
src/test/java/org/example/service/GameServiceTest.java- Unit tests -
src/test/java/org/example/model/GameStateTest.java- Model tests
Closes #5 (closed)