Class GameController
Object
GameController
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 Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionGameController
(GameData data, GameView view, CombatEngine engine) The GameController needs all major components of the game to work - view, data, and combat -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
processCommand
(String command) Setup as a helper method forstart()
}, processes commands the client passes in throughGameView.displayMainMenu()
.private void
processRemoveActive
(String remove) Optional helper method that helped keep processCommand(String) cleaner.private void
processSetActive
(String active) Optional helper method that helped keep processCommand(String) cleaner.private void
processShowKnight
(String nameOrId) Optional helper method that helped keep processCommand(String) cleaner.void
start()
Starts the game, causing it to run until a client exits.
-
Field Details
-
data
Game data passed into the constructor. -
view
game view passed into the constructor -
engine
combat engine, passed into the constructor
-
-
Constructor Details
-
GameController
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 classview
- GameView - calls the various methods based on feedback from dataengine
- 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
Setup as a helper method forstart()
}, processes commands the client passes in throughGameView.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
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
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
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
-
-