Class CombatEngine
Object
CombatEngine
The combat engine runs the combat for the game. Initialize and clear() are the only required methods to implement for this class. *HOWEVER*
to have a fully functional game, runCombat() must be implemented. Furthermore, you will need at least the method signature
for runCombat(), even if you have it simply print out "not implemented".
-
Field Summary
Fields -
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 TypeMethodDescriptionvoid
clear()
Sets all fortunes to *null* across all knights.private int
Helper method.void
Before every quest, active knights are assigned random fortunes (GameData.getRandomFortune()
.void
Runs the combat simulation (optional).
-
Field Details
-
data
The data for the game, passed in as part of the constructor. -
view
The View used for the game, passed in as part of the constructor. It is mainly only used on reporting the battle text. -
rnd
Used in runCombat() to select who is fighting who. It may not be needed depending on how runCombat() is implemented.
-
-
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 a fortune is assigned to each active knight, callGameView.printFortunes(List)
Hints: Loops through getActiveKnights() and setActiveFortune using a getRandomFortune() from data. -
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 (DiceType.Roll
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
-
doBattle
Helper method. May not be needed depending on how you implement runCombat().- Parameters:
attackers
- - can be either the knights or the monsters (depending on who is attacking who)defenders
- - can be either the knights or the monsters- Returns:
- number of victories the 'attackers' have over the defenders
-
clear
public void clear()Sets all fortunes to *null* across all knights. It is easier to just loop through all Knights setting the fortune to null, simply because activeKnights can be harder to track after combat is done.
-