diff --git a/src/code/ca/bcit/comp2522/lab02/Creature.java b/src/code/ca/bcit/comp2522/lab02/Creature.java index d1bbc04..70e7518 100644 --- a/src/code/ca/bcit/comp2522/lab02/Creature.java +++ b/src/code/ca/bcit/comp2522/lab02/Creature.java @@ -107,16 +107,15 @@ public class Creature { if (!this.isAlive()){ throw new RuntimeException("The creature is not alive."); } - else{ - if (damage < NO_HEALTH) { - throw new DamageException("Damage cannot be negative"); - } - this.health -= damage; + if (damage < NO_HEALTH) { + throw new DamageException("Damage cannot be negative"); + } - if (this.health < NO_HEALTH) { - this.health = NO_HEALTH; - } + this.health -= damage; + + if (this.health < NO_HEALTH) { + this.health = NO_HEALTH; } } diff --git a/src/code/ca/bcit/comp2522/lab02/Dragon.java b/src/code/ca/bcit/comp2522/lab02/Dragon.java index e92bc00..cabba5c 100644 --- a/src/code/ca/bcit/comp2522/lab02/Dragon.java +++ b/src/code/ca/bcit/comp2522/lab02/Dragon.java @@ -83,10 +83,9 @@ public class Dragon extends Creature { if (!this.isAlive()) { throw new RuntimeException("The dragon is not alive."); } - else { - if(firePower < FIRE_POWER_USAGE) { - throw new LowFirePowerException("Fire power too low"); - } + + if(firePower < FIRE_POWER_USAGE) { + throw new LowFirePowerException("Fire power too low"); } this.firePower -= FIRE_POWER_USAGE; diff --git a/src/code/ca/bcit/comp2522/lab02/Elf.java b/src/code/ca/bcit/comp2522/lab02/Elf.java index 4e4d5e7..5d88329 100644 --- a/src/code/ca/bcit/comp2522/lab02/Elf.java +++ b/src/code/ca/bcit/comp2522/lab02/Elf.java @@ -83,15 +83,15 @@ public class Elf extends Creature { if(!this.isAlive()){ throw new RuntimeException("The elf is not alive."); } - else{ - if (this.mana < MANA_USAGE) { + + if (this.mana < MANA_USAGE) { throw new LowManaException("Not enough mana to cast spell"); } - this.mana -= MANA_USAGE; + this.mana -= MANA_USAGE; + + target.takeDamage(MANA_DAMAGE); - target.takeDamage(MANA_DAMAGE); - } } /** diff --git a/src/code/ca/bcit/comp2522/lab02/Orc.java b/src/code/ca/bcit/comp2522/lab02/Orc.java index 20df0d0..c4e7c39 100644 --- a/src/code/ca/bcit/comp2522/lab02/Orc.java +++ b/src/code/ca/bcit/comp2522/lab02/Orc.java @@ -86,24 +86,21 @@ public class Orc extends Creature { if(!this.isAlive()){ throw new RuntimeException("The orc is not alive."); } - else{ - this.rage += RAGE_INCREMENT; + this.rage += RAGE_INCREMENT; - if (this.rage > MAX_RAGE_VALUE) { - this.rage = MAX_RAGE_VALUE; - } + if (this.rage > MAX_RAGE_VALUE) { + this.rage = MAX_RAGE_VALUE; + } - if (rage < RAGE_INCREMENT) { - throw new LowRageException("Rage too low"); - } else if (this.rage > DAMAGE_THRESHOLD) { - target.takeDamage(DAMAGE * DOUBLE); - } else { - target.takeDamage(DOUBLE); - } + if (rage < RAGE_INCREMENT) { + throw new LowRageException("Rage too low"); + } else if (this.rage > DAMAGE_THRESHOLD) { + target.takeDamage(DAMAGE * DOUBLE); + } else { + target.takeDamage(DAMAGE); + } } - } - } diff --git a/src/tests/ca/bcit/comp2522/CreatureTest.java b/src/tests/ca/bcit/comp2522/CreatureTest.java index 4619a83..07d03e7 100644 --- a/src/tests/ca/bcit/comp2522/CreatureTest.java +++ b/src/tests/ca/bcit/comp2522/CreatureTest.java @@ -34,24 +34,24 @@ public class CreatureTest { elfBirthDate = new Date(1900, 11, 5); orcBirthDate = new Date(500, 5, 3); - creatureDragon = new Dragon("Sparky", dragonBirthDate, 5, 60); - creatureElf = new Elf("Ben", elfBirthDate, 10, 15); - creatureOrc = new Orc("Shobob", orcBirthDate, 12, 3); + creatureDragon = new Dragon("Sparky", dragonBirthDate, 5, 60); + creatureElf = new Elf("Ben", elfBirthDate, 10, 15); + creatureOrc = new Orc("Shobob", orcBirthDate, 12, 3); + + final Dragon dragon = (Dragon)creatureDragon; + final Elf elf = (Elf)creatureElf; + final Orc orc = (Orc)creatureOrc; + + + + dragon.printDetails(); + if (dragon instanceof Creature) System.out.println("This creature is a Dragon."); + elf.printDetails(); + if (elf instanceof Creature) System.out.println("This creature is an Elf."); + orc.printDetails(); + if (orc instanceof Creature) System.out.println("This creature is an Orc."); - final Dragon dragon = (Dragon)creatureDragon; - final Elf elf = (Elf)creatureElf; - final Orc orc = (Orc)creatureOrc; - - - - dragon.printDetails(); - if (dragon instanceof Creature) System.out.println("This creature is a Dragon."); - elf.printDetails(); - if (elf instanceof Creature) System.out.println("This creature is an Elf."); - orc.printDetails(); - if (orc instanceof Creature) System.out.println("This creature is an Orc."); - // Fight sequence — all guarded by friendly exception handling try { System.out.println("- Dragon breathed fire on the Elf");