Class GameData
Object
GameData
- Direct Known Subclasses:
CSVGameData
GameData handles the data for the game. It is abstract, as a child class needs to define how that
data is going to be loaded into the data objects, but most of the data objects
can run independently of the the child class. The rest of the game will
assume the GameData class only.
-
Field Summary
FieldsModifier and TypeFieldDescriptionList of the active knights, they are references, not copies.List of fortunes.List of all the knights availableList of MOBs/Monstersprotected static final Random
Random number generator, used for grabbing random items for the structures. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Knight
findKnight
(String nameOrId, List<Knight> list) Finds a knight based on nameOrId based on the a List of knights passed into it.Gets an active knight based on a string or id.Returns list of knights currently set as active.Gets an knight from the all knights list based on a string or id.Returns all knights.Gets a random fortune fromfortunes
Gets a random monster frommonsters
assuming the max number of monsters is less than or equal to activeKnights.size()getRandomMonsters
(int number) Builds a list of random monsters of size number.void
removeActive
(Knight kt) Removes a knight from theactiveKnights
list and resets the damage on the knight!abstract void
Required for the implementing class to be able to save the fileboolean
Adds a knight to theactiveKnights
list, as long as there are no more than 4 knights in the list.
-
Field Details
-
random
Random number generator, used for grabbing random items for the structures. For example, grabbing a random fortune would befortunes.get(random.nextInt(fortunes.size()))
-
fortunes
List of fortunes. -
monsters
List of MOBs/Monsters -
knights
List of all the knights available -
activeKnights
List of the active knights, they are references, not copies.
-
-
Constructor Details
-
GameData
public GameData()
-
-
Method Details
-
getKnights
Returns all knights.- Returns:
- all knights stored in
knights
-
getActiveKnights
Returns list of knights currently set as active.- Returns:
- Essentially returns
activeKnights
-
getActive
Gets an active knight based on a string or id. The string can be word in the knights name, and will return the first knight that it comes across that matches that string. The id is supposed to be unique, and will find the knight with that idea, immediately returning the knight. Uses findKnight to accomplish the task.- Parameters:
nameOrId
- string or ID as a string- Returns:
- the active knight if it exists, or null if it is not found
- See Also:
-
getKnight
Gets an knight from the all knights list based on a string or id. The string can be word in the knights name, and will return the first knight that it comes across that matches that string. The id is supposed to be unique, and will find the knight with that idea, immediately returning the knight. Uses findKnight to accomplish the task.- Parameters:
nameOrId
- string or ID as a string- Returns:
- the knight if it exists, or null if it is not found
- See Also:
-
findKnight
Finds a knight based on nameOrId based on the a List of knights passed into it. The name can be any part of the name (contains), but the ID must exactly match. Note for students: getId() returns an Integer (not int), so you can call toString, and just compare Strings. That is valid, no need to parse.- Parameters:
nameOrId
- a name or id stringlist
- the list of knights to search - oftenknights
oractiveKnights
- Returns:
- the single knight if found, or null if not found.
- See Also:
-
setActive
Adds a knight to theactiveKnights
list, as long as there are no more than 4 knights in the list.- Parameters:
kt
- knight to add- Returns:
- true if the added was successful, false if the knight was added, due to too many knights already being in the list
-
removeActive
Removes a knight from theactiveKnights
list and resets the damage on the knight!- Parameters:
kt
- knight to remove- See Also:
-
getRandomFortune
Gets a random fortune fromfortunes
- Returns:
- a Fortune from the fortunes list
-
getRandomMonsters
Gets a random monster frommonsters
assuming the max number of monsters is less than or equal to activeKnights.size()- Returns:
- a list of MOBs no greater than activeKnights.size()
-
getRandomMonsters
Builds a list of random monsters of size number. Note, that monsters should be copied into the return List, so they can be modified individually.- Parameters:
number
- the number of monsters to randomly grab and copy- Returns:
- a list of MOB/monsters (copies)
- See Also:
-
save
Required for the implementing class to be able to save the file- Parameters:
filename
- name of file to save
-