Class CombatEngine
Object
CombatEngine
The combat engine runs the combat for the game.
-
Constructor Summary
ConstructorsConstructorDescriptionCombatEngine(GameData data, GameView view) To run the combat, a GameData and GameView is essential for it to work. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Sets all fortunes to null across all knights.voidBefore every quest, active knights are assigned random fortunes (GameData.getRandomFortune().voidRuns the combat simulation (optional).
-
Constructor Details
-
CombatEngine
To run the combat, a GameData and GameView is essential for it to work. It is designed to use classes that implement the GameView and GameData interfaces- Parameters:
data- a game datasetview- a game view
-
-
Method Details
-
initialize
public void initialize()Before every quest, active knights are assigned random fortunes (GameData.getRandomFortune(). Once an a fortune is assigned to each active knight, callGameView.printFortunes(List) -
runCombat
public void runCombat()Runs the combat simulation (optional).This method is NOT graded - and is purely a "challenge" for you to implement.
Combat will continue to run as long as there are either knights or monsters/MOBs. If MOBs are reduced to zero, the player will be promoted to see if they wish to continue exploring
GameView.checkContinue(). If they respond yes, more random monsters will be generated, and combat begins again. At the start of each battle:- Generates a random list of MOBs, no larger than the total number of knights
GameData.getRandomMonsters() - Prints the battle text, on who the fight is between
GameView.printBattleText(List, List) - Runs through the combat
The combat order itself is undefined on order of actions, but the following must happen- When knights are defeated (
MOB.getHP()<= 0), they are removed from active knights - When MOBs are defeated, every active knight earns 1 XP point (
Knight.addXP(int)) - While combat order is undefined, a common implementation is cycle through the knights having them attack a random monster. We then cycle through the MOBs having them each attack a random knight.
- When a knight or mob is defeated, we print that they were defeated
GameView.printBattleText(MOB)
If all knights are defeated, we notify the player using
GameView.printDefeated().Calculating Hits
To calculate a successful hit, you roll a D20 (DiceSet.roll(DiceType)take that value, add the MOBs/Knights toHitModifier. If the value is greater than the armor value, they score a hit, and the damage die is rolled.D20 + hitModifier>armor (successful hit formula)
Upon a successful strike, the damage die is rolled to determine the amount of damage the opponent takes Hint to students: private helper methods are extremely helpful here. As is helps break up the above steps. Make sure to take it in small parts, printing out in each step.- See Also:
- Generates a random list of MOBs, no larger than the total number of knights
-
clear
public void clear()Sets all fortunes to null across all knights.
-