Class GameController

Object
GameController

public class GameController extends Object
Central point of communication between GameData, GameView and CombatEngine. Constructed in the Main.java, but most all work happens here until the game ends.
  • Field Details

    • data

      private final GameData data
      Game data passed into the constructor.
    • view

      private final GameView view
      game view passed into the constructor
    • engine

      private final CombatEngine engine
      combat engine, passed into the constructor
  • Constructor Details

    • GameController

      public GameController(GameData data, GameView view, CombatEngine engine)
      The GameController needs all major components of the game to work - view, data, and combat
      Parameters:
      data - GameData - does not care the type (CSV, JSON, etc), just the abstract class
      view - GameView - calls the various methods based on feedback from data
      engine - runs combat between an active knight group and MOBs
  • Method Details

    • start

      public void start()
      Starts the game, causing it to run until a client exits. Starts with splashScreen, loops as long as processCommand returns true, prints endgame when loop is done.
      See Also:
    • processCommand

      protected boolean processCommand(String command)
      Setup as a helper method for start() }, processes commands the client passes in through GameView.displayMainMenu(). The following command combinations are allowed:
      • exit or bye (contains) - causes processCommand to return false
      • ls or list all - list all knights. For example, view.listKnights(data.getKnights())
      • list active - list active knights via GameData.getActiveKnights()
      • show (name or id) - if the command starts with show, take the remainder and show the knight card
      • set active (name or id) - if command starts with set active, grabs the remainder of the line, and try to add the knight to the active knight list.
      • remove (name or id) - if command starts with remove, grabs the remainder of the line, attempts to remove the knight from active status.
      • save (filename - optional) - saves the game. If a file name is provided saves the knights to the file. If a file name is left off, saves out to saveData.csv
      • explore, adventure or quest - if any three of these words are used, it starts a combat sequence. For example.
         
                 engine.initialize();
                 engine.runCombat();
                 engine.clear();
             }
      • any other input, print the help menu.
      Parameters:
      command - command to process.
      Returns:
      true unless exit or bye is used.
    • processRemoveActive

      private void processRemoveActive(String remove)
      Optional helper method that helped keep processCommand(String) cleaner. removes the night by calling .getActive(), and then removeActive() if the knight exists Prints knightNotFound() if an invalid knight is given.
      Parameters:
      remove - the id or name of knight to remove
    • processSetActive

      private void processSetActive(String active)
      Optional helper method that helped keep processCommand(String) cleaner. sets a knight to 'active' by calling .getKnight(String), and then setActive(Knight) if the knight exists Prints knightNotFound() if an invalid knight is given, and setActiveFailed() if it can't add the knight.
      Parameters:
      active -
    • processShowKnight

      private void processShowKnight(String nameOrId)
      Optional helper method that helped keep processCommand(String) cleaner. Uses data.getKnight(nameOrId) to ge ta knight, and then call the showKnight(knight) method in GameView. If the knight wasn't found, print knightNotFound()
      Parameters:
      nameOrId -