[US-05] Save, load, and resume a match
Description
Implements save and load functionality for Battleship game matches. Users can save their current game state to a file and later load it to resume exactly where they left off.
Features Implemented
Core Functionality
- GameState serialization: Complete game state persistence including board layouts, shot history, current player, difficulty, and timer
- SaveLoadService: Service for saving and loading game states with validation
- File validation: Comprehensive validation for corrupted, missing, or incompatible files
- Version compatibility: Ensures only compatible save files can be loaded
Key Components
-
GameState.java: Serializable class representing complete game state -
SaveLoadService.java: Service handling file I/O operations with error handling - Comprehensive test coverage for all acceptance criteria
Requirements Validation
- Includes board size, fleet layouts, shot history, sunk statuses, current player, difficulty/mode, timer
- Hidden information remains hidden after load
- Restores all externally observable state (boards, indicators, turn, timer, difficulty/mode)
- Validates file existence, readability, and format
- Reports errors for missing/invalid/corrupted/incompatible files
- Does not modify current game on error
- Save immediately followed by load preserves all observable state
- Allows user to choose location and filename
- Auto-adds .bsg extension if missing
Acceptance Criteria Verified
- Given mid-game state S, save and immediate load preserves: shot history & results, visible cell states, sunk indicators, whose turn, difficulty/mode, timer value
- Given deliberately corrupted/incompatible file, shows error and preserves current game
- Given finished game (win/loss), save and load preserves outcome and disables inputs
Technical Details
- File Format: Java Object Serialization (.bsg extension)
- Versioning: Current version "1.0" with compatibility checking
- Error Handling: Comprehensive exception handling with user-friendly messages
- Testing: 100% test coverage for SaveLoadService with all edge cases
Closes #5