Skip to content

[US-05] Saving and restoring the game

Ivan Esau requested to merge feature/issue-5-us-05-saving-and-restoring-the into master

Description

Implements comprehensive save/load functionality for the Battleship game. Players can save the current game state to a file and later load it to continue from the exact same point.

Changes

  • Created GameSaveState class for serialization with all required game data
  • Made all model classes (Coordinate, Ship, Board, Player) serializable
  • Added saveGame() and loadGame() methods to GameController
  • Implemented error handling for corrupted/missing files
  • Added running time tracking for game sessions

Requirements Met

Store everything belonging to the match in a file Hidden things must stay hidden after loading Previous game state must be shown exactly as before Report errors for missing/damaged/incompatible files Leave running game unchanged if file loading fails Player can choose file location and name Save right before loading should not change match state

Acceptance Criteria

If game is saved and loaded right away, every visible part and all internal values should be identical If a corrupted file is loaded, an error is displayed and the game remains the same If a completed game is saved and later loaded, it stays finished and waits for a new start

Technical Details

  • Uses Java Object Serialization for state persistence
  • Comprehensive error handling for file operations
  • Preserves all game elements: ship placements, shots, turn order, game state
  • Maintains hidden ship positions after loading

Closes #5 (closed)

Edited by Ivan Esau

Merge request reports

Loading