Class CSVGameData

Object
GameData
CSVGameData

public class CSVGameData extends GameData
Reads the game data from CSV files, and loads it into the protected methods in GameData.
  • Constructor Details

    • CSVGameData

      public CSVGameData(String gamedata, String saveData)
      Constructs the CSVGameData object, by loading CSV files passed into it. Use the protected methods (yes, this can be a two line constructor)
      Parameters:
      gamedata - A game data file containing fortunes and MOBS
      saveData - A data file containing knights
  • Method Details

    • loadSaveData

      void loadSaveData(String saveData)
      Loads in the data from a knights CSV file. Constructs a new Knight and adds it to the Knight List GameData.knights. Starts a counter for the IDs, with each new knight being assigned an ID in order of which they are read from the file While there are many ways to implement this method, this is implementation that we used.
      
       int counter = 0;
       CSVReader reader = new CSVReader(saveData, false);
       while (reader.hasNext()) {
           List<String> line = reader.getNext();
           Knight kt = new Knight(++counter, line.get(0).trim(), IntegerparseInt(line.get(1)),
                   Integer.parseInt(line.get(2)), Integer.parseInt(line.get(3)), DiceType.valueOf(line.get(4)),
                   Integer.parseInt(line.get(5)));
           knights.add(kt);
       }
       
      DiceType.valueOf was a method that was automatically generated for you as an enum. It takes in a string that looks *EXACTLY* like the enum, and converts it to the enum, so "D4" becomes DiceType.D4
      Parameters:
      saveData - a file containing knight information
    • loadGameData

      void loadGameData(String gamedata)
      Loads game data based on fortunes or MOBs. first line of the CSV file determines type, the rest loads directly into a MOB or Fortune object. Stores MOBs in GameData.monsters and fortunes into GameData.fortunes. Make sure to examine the code provided for loadSaveData()
      Parameters:
      gamedata - a game data CSV file with MOBs and Fortunes
    • save

      public void save(String filename)
      Saves out the knight data as a CSV to the given filename.
      Specified by:
      save in class GameData
      Parameters:
      filename - name of file to save knights out to
      See Also: