Package com.misc
Class SaveControls
- java.lang.Object
-
- com.misc.SaveControls
-
public class SaveControls extends java.lang.ObjectA class to store the functions required to save objects in the main game.- Since:
- 6/03/2020
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classSaveControls.SavedFiretruckA 'barebones' Firetruck class to only store the properties needed to re-create the classclassSaveControls.SavedFortressA 'barebones' ETFortress class to only store the properties needed to re-create the classclassSaveControls.SaveFileThe format of a save file
-
Constructor Summary
Constructors Constructor Description SaveControls()Creates a new Gson instance and creates a fresh save file setting the current save to 0
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancheckIfSaveEmpty(int saveNumber)Checks if a save file contains any datavoiddeleteSave(int saveNumber)Attempts to delete a save file.intgetCurrentSaveNumber()Gets the index of the save file currently used.intgetSavedDifficulty()Gets the saved game difficultySaveControls.SavedFiretruckgetSavedFiretruck(Constants.TruckType type)Gets a saved firetruck given its typeSaveControls.SavedFortressgetSavedFortress(Constants.FortressType type)Gets a saved fortress given its typeSaveControls.SaveFilegetSaveFile()Gets the current loaded save filejava.lang.StringgetSaveName(int saveNumber)Gets the name of a save filevoidloadFromSave(int saveNumber)Attempts to load a save file.voidsaveGame(int saveNumber, int score, int time, int difficulty, Firestation firestation, java.util.ArrayList<ETFortress> ETFortresses)The one function to save the entire game in a selected file.voidsetCurrentSaveNumber(int saveNumber)Sets the index of the save file currently used.voidsetSaveName(int saveNumber, java.lang.String name)Sets the name of a save file
-
-
-
Method Detail
-
saveGame
public void saveGame(int saveNumber, int score, int time, int difficulty, Firestation firestation, java.util.ArrayList<ETFortress> ETFortresses)The one function to save the entire game in a selected file.- Parameters:
saveNumber- The number of the save file to store the JSON inscore- The game score to be convertedtime- The game time to be converteddifficulty- The game difficulty to be convertedfirestation- The firestation to be convertedETFortresses- The ETFortresses to be converted
-
loadFromSave
public void loadFromSave(int saveNumber)
Attempts to load a save file. If it fails to open/find a save file it defaults to a new save file- Parameters:
saveNumber- The index of the save file to load
-
deleteSave
public void deleteSave(int saveNumber)
Attempts to delete a save file. If deleting the save file in use, set the currentSaveNumber to 0 to start a new game on reload- Parameters:
saveNumber- The index of the save file to delete
-
getCurrentSaveNumber
public int getCurrentSaveNumber()
Gets the index of the save file currently used. Will be 0 if no save is loaded.- Returns:
- The index of the save file currently loaded
-
setCurrentSaveNumber
public void setCurrentSaveNumber(int saveNumber)
Sets the index of the save file currently used.- Parameters:
saveNumber- The index of the save file currently loaded
-
checkIfSaveEmpty
public boolean checkIfSaveEmpty(int saveNumber)
Checks if a save file contains any data- Parameters:
saveNumber- The save number to check- Returns:
- Whether the save file is empty (true) or not (false)
-
getSaveName
public java.lang.String getSaveName(int saveNumber)
Gets the name of a save file- Parameters:
saveNumber- The save number to check- Returns:
- The name of the savefile
-
setSaveName
public void setSaveName(int saveNumber, java.lang.String name)Sets the name of a save file- Parameters:
saveNumber- The save number to changename- The name of the savefile
-
getSaveFile
public SaveControls.SaveFile getSaveFile()
Gets the current loaded save file- Returns:
- The current savefile
-
getSavedDifficulty
public int getSavedDifficulty()
Gets the saved game difficulty- Returns:
- The saved difficulty
-
getSavedFiretruck
public SaveControls.SavedFiretruck getSavedFiretruck(Constants.TruckType type)
Gets a saved firetruck given its type- Parameters:
type- The type of firetruck to retrieve- Returns:
- The saved firetruck
-
getSavedFortress
public SaveControls.SavedFortress getSavedFortress(Constants.FortressType type)
Gets a saved fortress given its type- Parameters:
type- The type of fortress to retrieve- Returns:
- The saved fortress
-
-