Class GameDetailsDAOText
java.lang.Object
dao.SpaceInvadersDAOText
dao.GameDetailsDAOText
Database access object for Model element GameDetails. The only game detail we are storing is the highScore, but the
high score is for a particular, username+firingInterval+moveSpeed
-
Field Summary
Fields inherited from class dao.SpaceInvadersDAOText
SPACEINVADERS_SETTINGS_DB_NAME, SPACEINVADERS_USER_HIGH_SCORES_DB_NAME, SPACEINVADERS_USERS_DB_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanloadData(GameDetails gameDetails) static voidloadHighScore(GameDetails gameDetails) Loads high Score for a particular userName for the game settings currently in usestatic booleansaveData(GameDetails gameDetails) static booleansaveHighScore(GameDetails gameDetails) Saves high Score for a userName for the game settings currently userHighScoresFile use.Methods inherited from class dao.SpaceInvadersDAOText
connectToSpaceInvadersDatabase, getGameHighScores, getSettingsInputConnection, getUserHighScoresInputConnection, getUsersInputConnection, myDelete
-
Constructor Details
-
GameDetailsDAOText
public GameDetailsDAOText()
-
-
Method Details
-
saveData
- Parameters:
gameDetails- the gameDetails object containing all the data to be saved- Returns:
- true if all saving was successful otherwise false
- Throws:
Exception- - either file not found or another IO Exception
-
loadData
- Parameters:
gameDetails- the gameDetails object containing all the data to be saved- Returns:
- true if all loading was successful otherwise false
- Throws:
Exception- - either file not found or another IO Exception
-
saveHighScore
Saves high Score for a userName for the game settings currently userHighScoresFile use. The approach is to create a temp file and copy all entries from the existing highscore file into the temp file updating the entry matching the provided username+settings record if the provided highscore is higher than that already in the the file. If it doesn't find a record matching the provided username+settings info then it will write the provided data as a new entry in the temp file. After finishing all processing of records it will delete the old highscore file rename the temp file so it becomes the new highscore file. The userHighScoreFile is a csv file with the following format per line userName,moveSpeed,firingInterval,highscore with the datatype of each item being String,double,integer,integer- Parameters:
gameDetails- the gameDetails object containing all the data (username and gamesettings) for which a highscore needs to be saved- Returns:
- true if the saving was completed successfully
- Throws:
IOException- - occurs if something goes wrong with the reading of the file.
-
loadHighScore
Loads high Score for a particular userName for the game settings currently in use- Parameters:
gameDetails- - contains the user and settings details, will have its highscore value set if a matching entry is found in the file- Throws:
Exception
-