|
| 1 | +In this exercise you're playing a role-playing game named "Wizard and Warriors," which allows you to play as either a Wizard or a Warrior. |
| 2 | + |
| 3 | +There are different rules for Warriors and Wizards to determine how much damage points they deal. |
| 4 | + |
| 5 | +For a Warrior, these are the rules: |
| 6 | + |
| 7 | +- Deal 6 points of damage if the fighter they are attacking is not vulnerable |
| 8 | +- Deal 10 points of damage if the fighter they are attacking is vulnerable |
| 9 | + |
| 10 | +For a Wizard, these are the rules: |
| 11 | + |
| 12 | +- Deal 12 points of damage if the Wizard prepared a spell in advanced |
| 13 | +- Deal 3 points of damage if the Wizard did not prepare a spell in advance |
| 14 | + |
| 15 | +In general, fighters are never vulnerable. However, Wizards _are_ vulnerable if they haven't prepared a spell. |
| 16 | + |
| 17 | +You have six tasks that work with Warriors and Wizard fighters. |
| 18 | + |
| 19 | +## 1. Describe a fighter |
| 20 | + |
| 21 | +Override the `toString()` method on the `Fighter` class to return a description of the fighter, formatted as `"Fighter is a <FIGHTER_TYPE>"`. |
| 22 | + |
| 23 | +```java |
| 24 | +Fighter warrior = new Warrior(); |
| 25 | +warrior.toString(); |
| 26 | +// => "Fighter is a Warrior" |
| 27 | +``` |
| 28 | + |
| 29 | +## 2. Make fighters not vulnerable by default |
| 30 | + |
| 31 | +Ensure that the `Fighter.isVulnerable()` method always returns `false`. |
| 32 | + |
| 33 | +```java |
| 34 | +Fighter warrior = new Warrior(); |
| 35 | +warrior.isVulnerable(); |
| 36 | +// => false |
| 37 | +``` |
| 38 | + |
| 39 | +## 3. Allow Wizards to prepare a spell |
| 40 | + |
| 41 | +Implement the `Wizard.prepareSpell()` method to allow a Wizard to prepare a spell in advance. |
| 42 | + |
| 43 | +```java |
| 44 | +Wizard wizard = new Wizard(); |
| 45 | +wizard.prepareSpell(); |
| 46 | +``` |
| 47 | + |
| 48 | +## 4. Make Wizards vulnerable when not having prepared a spell |
| 49 | + |
| 50 | +Ensure that the `isVulnerable()` method returns `true` if the wizard did not prepare a spell; otherwise, return `false`. |
| 51 | + |
| 52 | +```java |
| 53 | +Fighter wizard = new Wizard(); |
| 54 | +wizard.isVulnerable(); |
| 55 | +// => true |
| 56 | +``` |
| 57 | + |
| 58 | +## 5. Calculate the damage points for a Wizard |
| 59 | + |
| 60 | +Implement the `Wizard.damagePoints()` method to return the damage points dealt: 12 damage points when a spell has been prepared, 3 damage points when not. |
| 61 | + |
| 62 | +```java |
| 63 | +Wizard wizard = new Wizard(); |
| 64 | +Warrior warrior = new Warrior(); |
| 65 | + |
| 66 | +wizard.prepareSpell(); |
| 67 | +wizard.damagePoints(warrior); |
| 68 | +// => 12 |
| 69 | +``` |
| 70 | + |
| 71 | +## 6. Calculate the damage points for a Warrior |
| 72 | + |
| 73 | +Implement the `Warrior.damagePoints()` method to return the damage points dealt: 10 damage points when the target is vulnerable, 6 damage points when not. |
| 74 | + |
| 75 | +```java |
| 76 | +Warrior warrior = new Warrior(); |
| 77 | +Wizard wizard = new Wizard(); |
| 78 | + |
| 79 | +warrior.damagePoints(wizard); |
| 80 | +// => 10 |
| 81 | +``` |
0 commit comments