[US-05] Save, load, and resume a match
Implementation Summary
This merge request implements the complete save/load functionality for the Battleship game as specified in issue #5.
Requirements Implemented
-
SaveLoadServicehandles serialization of all game state - Saves board size, fleet layouts, shot history, sunk statuses, current turn, and game state
- Hidden information remains concealed from opponent after load
-
GameSaveServicerestores complete game state from files - Preserves shot history, visible cell states, sunk indicators, current turn
- Maintains game difficulty/mode and timer value
-
isValidSaveFile()method validates file integrity - Handles missing/invalid/corrupted/incompatible files
- Reports errors without modifying current game state
- Save immediately followed by load preserves all observable state
- Comprehensive tests validate round-trip consistency
- No state changes during save/load cycle
- Service methods accept file path parameters
- Controller layer handles user file selection
- Flexible file location and naming
Acceptance Criteria Validated
- Tested in
testAcceptanceCriterion1_SaveLoadPreservesCompleteState() - Validates shot history, visible states, sunk indicators, current turn
- Tested in
testAcceptanceCriterion2_CorruptedFileHandling() - Validates error handling and state preservation
- Tested in
testAcceptanceCriterion3_FinishedGamePreservation() - Validates finished state preservation
Technical Implementation
Core Classes:
-
SaveLoadService: Main service for save/load operations -
GameSaveService: Enhanced service with validation and testing -
GameSaveData: Serializable data structure for game state -
PlayerSaveData: Serializable data structure for player state -
ShipSaveData: Serializable data structure for ship state
Key Features:
- Java serialization for efficient state persistence
- Comprehensive error handling for file operations
- Complete state preservation including shot history
- Validation of save file integrity
- Round-trip consistency guarantees
Test Coverage:
- Unit tests for individual service methods
- Integration tests for complete save/load workflow
- Acceptance criteria validation tests
- Edge case handling (corrupted files, finished games)
Closes #5