Class GameDetailsDAOText


public class GameDetailsDAOText extends SpaceInvadersDAOText
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
  • Constructor Details

    • GameDetailsDAOText

      public GameDetailsDAOText()
  • Method Details

    • saveData

      public static boolean saveData(GameDetails gameDetails) throws Exception
      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

      public static boolean loadData(GameDetails gameDetails) throws Exception
      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

      public static boolean saveHighScore(GameDetails gameDetails) throws IOException
      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

      public static void loadHighScore(GameDetails gameDetails) throws Exception
      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