(Follows on from 7ec8.)
The true Fighting Fantasy rules are a bit more complex. A fighter has a further attribute, luck, an integer that is initially set to a value between 1 and 18. If a fighter gets hit during a battle, the fighter can test their luck: they roll two dice, and are lucky if and only if the sum of the numbers on the dice is less than or equal to their current luck. If the fighter is lucky, the damage inflicted is reduced by one, but if the fighter is unlucky, the damage inflicted is increased by one.
Similarly, when a fighter hits their opponent the fighter can test their luck. If lucky, the damage inflicted is doubled, but if unlucky, the damage inflicted is decreased by one point.
Each time a fighter tests their luck, the luck value is decreased by one (until it reaches zero). Note that testing luck is optional: it is a risky way to potentially inflict more damage on one's opponent, or to take less damage, but if unlucky it has the opposite effect.
Extend your battle simulator with the notion of luck. You should do this by replacing Fighter
with a similar, but extended,
LuckyFighter
class. The GameEngine
class should be virtually unchanged.
To model the use of luck in battles, each fighter should be equipped with a new strategy attribute. A fighter's strategy should be one of aggressive (the fighter is likely to try to use luck to inflict more damage), defensive (the fighter is likely to use luck to resist damage), or average (the fighter will use luck in either scenario only when the odds of being lucky are reasonably high).
You can decide how to represent a fighter's strategy, and how to implement the strategy: i.e., you must come up with a policy for what constitutes aggressive, defensive and average use of luck, and adjust the logic of your program to reflect this.
An example run of your program might look something like this:
At start of battle, stats are:
Joe - Aggressive Human Warrior - skill: 16; stamina: 12; luck: 12
Alex - Defensive Elf Lord - skill: 18; stamina: 6; luck: 11
------------------------------
Alex hits Joe, stats are:
Joe - Aggressive Human Warrior - skill: 16; stamina: 10; luck: 12
Alex - Defensive Elf Lord - skill: 18; stamina: 6; luck: 11
------------------------------
Alex hits Joe, stats are:
Joe - Aggressive Human Warrior - skill: 16; stamina: 8; luck: 12
Alex - Defensive Elf Lord - skill: 18; stamina: 6; luck: 11
------------------------------
Joe hits Alex, stats are:
Joe goes for an aggressive hit...
Joe tests luck...
Joe is lucky!
The hit is aggressive!
Alex tries to resist the damage...
Alex tests luck...
Alex is lucky!
The damage is partially resisted!
Joe - Aggressive Human Warrior - skill: 16; stamina: 8; luck: 11
Alex - Defensive Elf Lord - skill: 18; stamina: 3; luck: 10
------------------------------
Alex hits Joe, stats are:
Joe - Aggressive Human Warrior - skill: 16; stamina: 6; luck: 11
Alex - Defensive Elf Lord - skill: 18; stamina: 3; luck: 10
------------------------------
Joe hits Alex, stats are:
Joe goes for an aggressive hit...
Joe tests luck...
Joe is lucky!
The hit is aggressive!
Alex tries to resist the damage...
Alex tests luck...
Alex is lucky!
The damage is partially resisted!
Joe - Aggressive Human Warrior - skill: 16; stamina: 6; luck: 10
Alex - Defensive Elf Lord - skill: 18; stamina: 0; luck: 9
------------------------------
End of battle, Joe - Aggressive Human Warrior - skill: 16; stamina: 6; luck: 10 wins!
Suppose you wanted to mix up fighters with and without luck. How could this be achieved?
Quite easily, if the LuckyFighter
class is defined as extending the
Fighter
class. But this will have to wait until a later tutorial question!