[US-05] Saving and restoring the game
Implementation Summary
This merge request implements comprehensive game save/load functionality for the Battleship game, addressing all acceptance criteria from Issue #5.
Key Features Implemented:
-
Game State Serialization (
GameState.java)- Complete game state capture including players, boards, ships, shots, current turn, difficulty, and timing
- Serializable implementation for file persistence
- Running time calculation for game duration tracking
-
Save/Load Service (
SaveLoadService.java)- Robust file operations with comprehensive error handling
- Validation for corrupted, missing, and incompatible files
- Directory creation support for custom file paths
- File integrity checks and user-friendly error reporting
-
Game Service Integration (
GameService.java)- Seamless integration with existing game logic
- State preservation during save/load operations
- Error recovery that preserves current game on failed loads
-
User Interface (
Main.java)- Main menu with save/load options
- File path selection for user flexibility
- Clear error messages and status feedback
Acceptance Criteria Coverage:
- Complete state preservation including player turns, board states, ship damage, and game timing
- Hidden information remains properly hidden after loading
- Comprehensive error handling for corrupted, missing, and incompatible files
- Current game state preserved on failed load attempts
- Clear error messages to the user
- Finished game state properly serialized and restored
- Game completion status preserved across save/load cycles
Technical Implementation:
- Architecture: Follows layered MVC pattern as specified in ORCH_PLAN.json
- Serialization: Java Object Serialization for efficient state persistence
- Error Handling: Comprehensive exception handling with user-friendly messages
- File Operations: Support for user-selectable file locations and names
- State Management: Complete game state capture and restoration
Testing:
Comprehensive test suite created with:
- 25 test cases for SaveLoadService covering file operations and error scenarios
- 15 test cases for GameService integration testing
- Full coverage of all acceptance criteria
- Edge case testing for corrupted files and error conditions
Dependencies Verified:
- All prerequisite issues (#1-4) completed as per ORCH_PLAN.json dependency graph
- Implementation builds upon existing game infrastructure
- No breaking changes to existing functionality
Closes #5
Edited by Ivan Esau