diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b4ff339..3478de4 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -6,9 +6,15 @@ + + + + + + diff --git a/src/code/ca/bcit/comp2522/lab02/Creature.java b/src/code/ca/bcit/comp2522/lab02/Creature.java index c6d9210..0aa95ad 100644 --- a/src/code/ca/bcit/comp2522/lab02/Creature.java +++ b/src/code/ca/bcit/comp2522/lab02/Creature.java @@ -4,10 +4,13 @@ package ca.bcit.comp2522.lab02; * Creature contains simple information regarding * a creature such as its health, name and date of birth. * - * @author Braeden Sowinski, Nicolas Agostini, Trishaan Shetty + * @author Braeden Sowinski + * @author Nicolas Agostini + * @author Trishaan Shetty * @version 1.0.0 */ public class Creature { + private static final int MIN_HEALTH = 1; private static final int MAX_HEALTH = 100; private static final int NO_HEALTH = 0; @@ -68,10 +71,11 @@ public class Creature { * @param dateOfBirth of creature * @param health of creature to start */ - public Creature(final String name, - final Date dateOfBirth, - final int health) - { + public Creature( + final String name, + final Date dateOfBirth, + final int health + ) { validateName(name); validateDateOfBirth(dateOfBirth); @@ -163,11 +167,11 @@ public class Creature { builder = new StringBuilder(); - builder.append("Is alive: " + this.isAlive()); - builder.append("Name: " + this.name); + builder.append("Is alive: " + this.isAlive()); + builder.append("Name: " + this.name); builder.append("Date of birth: " + this.dateOfBirth); - builder.append("Age: " + this.getAgeYears()); - builder.append("Health: " + this.health); + builder.append("Age: " + this.getAgeYears()); + builder.append("Health: " + this.health); return builder.toString(); diff --git a/src/code/ca/bcit/comp2522/lab02/DamageException.java b/src/code/ca/bcit/comp2522/lab02/DamageException.java index a17342b..b7c6cf5 100644 --- a/src/code/ca/bcit/comp2522/lab02/DamageException.java +++ b/src/code/ca/bcit/comp2522/lab02/DamageException.java @@ -5,9 +5,16 @@ package ca.bcit.comp2522.lab02; * for when a given damage value is invalid. * * @author Braeden Sowinski + * @author Nicolas Agostini + * @author Trishaan Shetty * @version 1.0.0 */ public class DamageException extends RuntimeException { + + /** + * DamageException constructor + * @param message of DamageException error + */ public DamageException(final String message) { super(message); } diff --git a/src/code/ca/bcit/comp2522/lab02/Dragon.java b/src/code/ca/bcit/comp2522/lab02/Dragon.java index e7ec08b..2f72ec4 100644 --- a/src/code/ca/bcit/comp2522/lab02/Dragon.java +++ b/src/code/ca/bcit/comp2522/lab02/Dragon.java @@ -5,9 +5,12 @@ package ca.bcit.comp2522.lab02; * holds a firePower value. * * @author Braeden Sowinski + * @author Nicolas Agostini + * @author Trishaan Shetty * @version 1.0.0 */ public class Dragon extends Creature { + private static final int MAX_FIRE_POWER = 100; private static final int MIN_FIRE_POWER = 0; private static final int FIRE_POWER_USAGE = 10; @@ -25,7 +28,6 @@ public class Dragon extends Creature { private static void validateFirePower(final int firePower) throws IllegalArgumentException { - if (firePower < MIN_FIRE_POWER || firePower > MAX_FIRE_POWER) { throw new IllegalArgumentException("Fire power is outside of valid range."); } @@ -60,16 +62,17 @@ public class Dragon extends Creature { */ @Override public String getDetails() { - StringBuilder builder; + + final StringBuilder builder; builder = new StringBuilder(); - builder.append("Is alive: " + this.isAlive()); - builder.append(" Name: " + this.getName()); + builder.append("Is alive: " + this.isAlive()); + builder.append(" Name: " + this.getName()); builder.append(" Date of birth: " + (this.getDateOfBirth()).getYyyyMmDd()); - builder.append(" Age: " + this.getAgeYears()); - builder.append(" Health: " + this.getHealth()); - builder.append(" FirePower: " + this.firePower); + builder.append(" Age: " + this.getAgeYears()); + builder.append(" Health: " + this.getHealth()); + builder.append(" FirePower: " + this.firePower); return builder.toString(); @@ -84,7 +87,8 @@ public class Dragon extends Creature { * @throws RuntimeException if the dragon is not alive to accomplish the action */ public void breatheFire(final Creature target) - throws LowFirePowerException, RuntimeException { + throws LowFirePowerException, RuntimeException + { if (!this.isAlive()) { throw new RuntimeException("The dragon is not alive."); @@ -107,10 +111,12 @@ public class Dragon extends Creature { * @param amount to increase firePower */ protected void restoreFirePower(final int amount) { + this.firePower += amount; if (this.firePower > MAX_FIRE_POWER) { this.firePower = MAX_FIRE_POWER; } + } } diff --git a/src/code/ca/bcit/comp2522/lab02/Elf.java b/src/code/ca/bcit/comp2522/lab02/Elf.java index 10c0e24..2c04bfb 100644 --- a/src/code/ca/bcit/comp2522/lab02/Elf.java +++ b/src/code/ca/bcit/comp2522/lab02/Elf.java @@ -5,9 +5,12 @@ package ca.bcit.comp2522.lab02; * holds a mana value * * @author Braeden Sowinski + * @author Nicolas Agostini + * @author Trishaan Shetty * @version 1.0.0 */ public class Elf extends Creature { + private static final int MIN_MANA_VALUE = 0; private static final int MAX_MANA_VALUE = 50; private static final int MANA_DAMAGE = 10; @@ -58,14 +61,17 @@ public class Elf extends Creature { */ @Override public String getDetails() { - StringBuilder builder; + + final StringBuilder builder; + builder = new StringBuilder(); - builder.append("Is alive: " + this.isAlive()); - builder.append(" Name: " + this.getName()); + + builder.append("Is alive: " + this.isAlive()); + builder.append(" Name: " + this.getName()); builder.append(" Date of birth: " + (this.getDateOfBirth()).getYyyyMmDd()); - builder.append(" Age: " + this.getAgeYears()); - builder.append(" Health: " + this.getHealth()); - builder.append(" Mana: " + this.mana); + builder.append(" Age: " + this.getAgeYears()); + builder.append(" Health: " + this.getHealth()); + builder.append(" Mana: " + this.mana); return builder.toString(); } @@ -102,10 +108,12 @@ public class Elf extends Creature { * @param amount to increase mana */ protected void restoreMana(final int amount) { + this.mana += amount; if (this.mana > MAX_MANA_VALUE) { this.mana = MAX_MANA_VALUE; } + } } diff --git a/src/code/ca/bcit/comp2522/lab02/HealingException.java b/src/code/ca/bcit/comp2522/lab02/HealingException.java index 1195f77..f360318 100644 --- a/src/code/ca/bcit/comp2522/lab02/HealingException.java +++ b/src/code/ca/bcit/comp2522/lab02/HealingException.java @@ -5,9 +5,16 @@ package ca.bcit.comp2522.lab02; * for when a given healing value is invalid. * * @author Braeden Sowinski + * @author Nicolas Agostini + * @author Trishaan Shetty * @version 1.0.0 */ public class HealingException extends RuntimeException { + + /** + * HealingException constructor + * @param message HealingException error message + */ public HealingException(final String message) { super(message); } diff --git a/src/code/ca/bcit/comp2522/lab02/LowFirePowerException.java b/src/code/ca/bcit/comp2522/lab02/LowFirePowerException.java index dfe0ac9..4c30b6e 100644 --- a/src/code/ca/bcit/comp2522/lab02/LowFirePowerException.java +++ b/src/code/ca/bcit/comp2522/lab02/LowFirePowerException.java @@ -5,9 +5,16 @@ package ca.bcit.comp2522.lab02; * when firePower is too low to deal damage. * * @author Braeden Sowinski + * @author Nicolas Agostini + * @author Trishaan Shetty * @version 1.0.0 */ public class LowFirePowerException extends Exception { + + /** + * LowFirePowerException constructor + * @param message LowFirePowerException error message + */ public LowFirePowerException(final String message) { super(message); } diff --git a/src/code/ca/bcit/comp2522/lab02/LowManaException.java b/src/code/ca/bcit/comp2522/lab02/LowManaException.java index f4bcdb4..dd07777 100644 --- a/src/code/ca/bcit/comp2522/lab02/LowManaException.java +++ b/src/code/ca/bcit/comp2522/lab02/LowManaException.java @@ -5,9 +5,16 @@ package ca.bcit.comp2522.lab02; * when mana is too low to deal damage. * * @author Braeden Sowinski + * @author Nicolas Agostini + * @author Trishaan Shetty * @version 1.0.0 */ public class LowManaException extends Exception { + + /** + * LowManaException constructor + * @param message LowManaException error message + */ public LowManaException(final String message) { super(message); } diff --git a/src/code/ca/bcit/comp2522/lab02/LowRageException.java b/src/code/ca/bcit/comp2522/lab02/LowRageException.java index 85cb888..d704063 100644 --- a/src/code/ca/bcit/comp2522/lab02/LowRageException.java +++ b/src/code/ca/bcit/comp2522/lab02/LowRageException.java @@ -5,9 +5,16 @@ package ca.bcit.comp2522.lab02; * when rage is too low to deal damage. * * @author Braeden Sowinski + * @author Nicolas Agostini + * @author Trishaan Shetty * @version 1.0.0 */ public class LowRageException extends Exception { + + /** + * LowRageException constructor + * @param message LowRageException error message + */ public LowRageException(final String message) { super(message); } diff --git a/src/code/ca/bcit/comp2522/lab02/Orc.java b/src/code/ca/bcit/comp2522/lab02/Orc.java index ddd0223..648999c 100644 --- a/src/code/ca/bcit/comp2522/lab02/Orc.java +++ b/src/code/ca/bcit/comp2522/lab02/Orc.java @@ -5,9 +5,12 @@ package ca.bcit.comp2522.lab02; * holds a rage value. Orcs need anger management. * * @author Braeden Sowinski + * @author Nicolas Agostini + * @author Trishaan Shetty * @version 1.0.0 */ public class Orc extends Creature { + private static final int MIN_RAGE_VALUE = 0; private static final int MAX_RAGE_VALUE = 30; private static final int RAGE_INCREMENT = 5; @@ -60,14 +63,17 @@ public class Orc extends Creature { */ @Override public String getDetails() { - StringBuilder builder; + + final StringBuilder builder; + builder = new StringBuilder(); - builder.append("Is alive: " + this.isAlive()); - builder.append(" Name: " + this.getName()); + + builder.append("Is alive: " + this.isAlive()); + builder.append(" Name: " + this.getName()); builder.append(" Date of birth: " + (this.getDateOfBirth()).getYyyyMmDd()); - builder.append(" Age: " + this.getAgeYears()); - builder.append(" Health: " + this.getHealth()); - builder.append(" Rage: " + this.rage); + builder.append(" Age: " + this.getAgeYears()); + builder.append(" Health: " + this.getHealth()); + builder.append(" Rage: " + this.rage); return builder.toString(); } @@ -84,6 +90,7 @@ public class Orc extends Creature { public void berserk(final Creature target) throws LowRageException, RuntimeException { + if(!this.isAlive()){ throw new RuntimeException("The orc is not alive."); } @@ -102,5 +109,5 @@ public class Orc extends Creature { target.takeDamage(DAMAGE); } - } + } }