Class GameData

Object
GameData
Direct Known Subclasses:
CSVGameData

public abstract class GameData extends Object
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 Details

    • random

      protected static final Random random
      Random number generator, used for grabbing random items for the structures. For example, grabbing a random fortune would be fortunes.get(random.nextInt(fortunes.size()))
    • fortunes

      protected final List<Fortune> fortunes
      List of fortunes.
    • monsters

      protected final List<MOB> monsters
      List of MOBs/Monsters
    • knights

      protected final List<Knight> knights
      List of all the knights available
    • activeKnights

      protected final List<Knight> activeKnights
      List of the active knights, they are references, not copies.
  • Constructor Details

    • GameData

      public GameData()
  • Method Details

    • getKnights

      public List<Knight> getKnights()
      Returns all knights.
      Returns:
      all knights stored in knights
    • getActiveKnights

      public List<Knight> getActiveKnights()
      Returns list of knights currently set as active.
      Returns:
      Essentially returns activeKnights
    • getActive

      public Knight getActive(String nameOrId)
      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

      public Knight getKnight(String nameOrId)
      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

      protected Knight findKnight(String nameOrId, List<Knight> list)
      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 string
      list - the list of knights to search - often knights or activeKnights
      Returns:
      the single knight if found, or null if not found.
      See Also:
    • setActive

      public boolean setActive(Knight kt)
      Adds a knight to the activeKnights 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

      public void removeActive(Knight kt)
      Removes a knight from the activeKnights list and resets the damage on the knight!
      Parameters:
      kt - knight to remove
      See Also:
    • getRandomFortune

      public Fortune getRandomFortune()
      Gets a random fortune from fortunes
      Returns:
      a Fortune from the fortunes list
    • getRandomMonsters

      public List<MOB> getRandomMonsters()
      Gets a random monster from monsters 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

      public List<MOB> getRandomMonsters(int number)
      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

      public abstract void save(String filename)
      Required for the implementing class to be able to save the file
      Parameters:
      filename - name of file to save