Class CSVGameData
Reads the game data from CSV files, and loads it into the protected methods in
GameData
.-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCSVGameData
(String gamedata, String saveData) Constructs the CSVGameData object, by loading CSV files passed into it. -
Method Summary
Modifier and TypeMethodDescription(package private) void
loadGameData
(String gamedata) Loads game data based on fortunes or MOBs.(package private) void
loadSaveData
(String saveData) Loads in the data from a knights CSV file.void
Saves out the knight data as a CSV to the given filename.Methods inherited from class GameData
findKnight, getActive, getActiveKnights, getKnight, getKnights, getRandomFortune, getRandomMonsters, getRandomMonsters, removeActive, setActive
-
Constructor Details
-
CSVGameData
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 MOBSsaveData
- A data file containing knights
-
-
Method Details
-
loadSaveData
Loads in the data from a knights CSV file. Constructs a new Knight and adds it to the Knight ListGameData.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.
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" becomesint 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
.D4- Parameters:
saveData
- a file containing knight information
-
loadGameData
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 inGameData.monsters
and fortunes intoGameData.fortunes
. Make sure to examine the code provided for loadSaveData()- Parameters:
gamedata
- a game data CSV file with MOBs and Fortunes
-
save
Saves out the knight data as a CSV to the given filename.
-