diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index cfaae74..40849de 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,23 +5,26 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
@@ -36,26 +39,31 @@
- {
+ "keyToString": {
+ "ModuleVcsDetector.initialDetectionPerformed": "true",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "RunOnceActivity.git.unshallow": "true",
+ "git-widget-placeholder": "main",
+ "kotlin-language-version-configured": "true",
+ "last_opened_file_path": "/home/flami/Projects/comp2522",
+ "node.js.detected.package.eslint": "true",
+ "node.js.detected.package.tslint": "true",
+ "node.js.selected.package.eslint": "(autodetect)",
+ "node.js.selected.package.tslint": "(autodetect)",
+ "nodejs_package_manager_path": "npm",
+ "project.structure.last.edited": "Project",
+ "project.structure.proportion": "0.15",
+ "project.structure.side.proportion": "0.2",
+ "settings.editor.selected.configurable": "preferences.lookFeel",
+ "vue.rearranger.settings.migration": "true"
}
-}]]>
+}
+
+
+
+
+
@@ -75,6 +83,9 @@
+
+
+
diff --git a/src/code/ca/bcit/comp2522/lab02/Creature.java b/src/code/ca/bcit/comp2522/lab02/Creature.java
index f456a9e..4a83b60 100644
--- a/src/code/ca/bcit/comp2522/lab02/Creature.java
+++ b/src/code/ca/bcit/comp2522/lab02/Creature.java
@@ -138,11 +138,31 @@ public class Creature {
}
}
+ /**
+ * getAgeYears calculates the age years
+ * from Date.MAX_YEAR which is current year
+ *
+ * @return age in years
+ */
protected int getAgeYears() {
- return 0;
+ return Date.MAX_YEAR - this.dateOfBirth.getYear();
}
+ /**
+ * getDetails of the creature
+ *
+ * @return details of the creature.
+ */
protected String getDetails() {
- return "";
+ return "Name: " + this.name;
+ }
+
+ /**
+ * getName of creature
+ *
+ * @return name of the creature
+ */
+ protected String getName() {
+ return this.name;
}
}
diff --git a/src/code/ca/bcit/comp2522/lab02/DamageException.java b/src/code/ca/bcit/comp2522/lab02/DamageException.java
index c43244c..b48c106 100644
--- a/src/code/ca/bcit/comp2522/lab02/DamageException.java
+++ b/src/code/ca/bcit/comp2522/lab02/DamageException.java
@@ -1,5 +1,12 @@
package ca.bcit.comp2522.lab02;
+/**
+ * DamageException is an unchecked exception
+ * for when a given damage value is invalid.
+ *
+ * @author Braeden Sowinski
+ * @version 1.0.0
+ */
public class DamageException extends RuntimeException {
public DamageException(String message) {
super(message);
diff --git a/src/code/ca/bcit/comp2522/lab02/Date.java b/src/code/ca/bcit/comp2522/lab02/Date.java
index 1ad2c24..00cf2b6 100644
--- a/src/code/ca/bcit/comp2522/lab02/Date.java
+++ b/src/code/ca/bcit/comp2522/lab02/Date.java
@@ -10,9 +10,10 @@ package ca.bcit.comp2522.lab02;
* @version 1.0.0
*/
public final class Date {
+ public static final int MAX_YEAR = 2025;
+
// Domain of dates
private static final int MIN_YEAR = 1800;
- private static final int MAX_YEAR = 2025;
private static final int MIN_DAY = 1;
private static final int CURRENT_DAY = 15;
private static final int CURRENT_MONTH = 9;
diff --git a/src/code/ca/bcit/comp2522/lab02/Dragon.java b/src/code/ca/bcit/comp2522/lab02/Dragon.java
index fd81e66..b0ad86e 100644
--- a/src/code/ca/bcit/comp2522/lab02/Dragon.java
+++ b/src/code/ca/bcit/comp2522/lab02/Dragon.java
@@ -10,12 +10,17 @@ package ca.bcit.comp2522.lab02;
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;
+ private static final int FIRE_POWER_DAMAGE = 20;
- private final int firePower;
+ private int firePower;
- /*
- validateFirePower ensures input firepower is in valid
- range of MAX_FIRE_POWER and MIN_FIRE_POWER.
+ /**
+ * validateFirePower ensures a given value is within
+ * the correct firePower range
+ *
+ * @param firePower to verify
+ * @throws IllegalArgumentException if firePower is outside valid range
*/
private static void validateFirePower(int firePower)
throws IllegalArgumentException {
@@ -34,18 +39,56 @@ public class Dragon extends Creature {
* @param firePower int
*/
Dragon(
- final String name,
- final Date dateOfBirth,
- final int health,
- final int firePower
+ final String name,
+ final Date dateOfBirth,
+ final int health,
+ final int firePower
) {
super(name, dateOfBirth, health);
this.firePower = firePower;
}
+ /**
+ * getDetails of Dragon with firepower
+ *
+ * @return details of dragon
+ */
@Override
protected String getDetails() {
- return "a";
+ return "Name: " + this.getName() + " FirePower: " + this.firePower;
+ }
+
+ /**
+ * breathFire onto Creatures to deal damage
+ * and reduces current firePower value
+ *
+ * @param target Creature to deal damage to
+ * @throws LowFirePowerException if not enough firePower
+ */
+ protected void breatheFire(final Creature target)
+ throws LowFirePowerException
+ {
+ if (firePower > FIRE_POWER_USAGE) {
+ throw new LowFirePowerException("Fire power too low");
+ }
+
+ this.firePower -= FIRE_POWER_USAGE;
+
+ target.takeDamage(FIRE_POWER_DAMAGE);
+ }
+
+ /**
+ * restoreFirePower by a given value and is
+ * maxed by MAX_FIRE_POWER
+ *
+ * @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
new file mode 100644
index 0000000..ccd90c1
--- /dev/null
+++ b/src/code/ca/bcit/comp2522/lab02/Elf.java
@@ -0,0 +1,96 @@
+package ca.bcit.comp2522.lab02;
+
+/**
+ * Elf extends Creature and
+ * holds a mana value? Never heard of that
+ *
+ * @author Braeden Sowinski
+ * @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;
+ private static final int MANA_USAGE = 5;
+
+ private int mana;
+
+ /*
+ * validateManaValue ensures a given value is within
+ * the correct mana range
+ *
+ * @param value to verify
+ * @throws IllegalArgumentException if mana is outside valid range
+ */
+ private static void validateManaValue(final int value)
+ throws IllegalArgumentException
+ {
+ if (value < MIN_MANA_VALUE || value > MAX_MANA_VALUE) {
+ throw new IllegalArgumentException("Invalid mana value: " + value);
+ }
+ }
+
+ /**
+ * Elf constructor
+ *
+ * @param name String
+ * @param dateOfBirth Date
+ * @param health int
+ * @param mana int
+ */
+ Elf(
+ final String name,
+ final Date dateOfBirth,
+ final int health,
+ final int mana
+ ) {
+ super(name, dateOfBirth, health);
+
+ validateManaValue(mana);
+
+ this.mana = mana;
+ }
+
+ /**
+ * getDetails of elf with Mana
+ *
+ * @return details of elf
+ */
+ @Override
+ protected String getDetails() {
+ return "Name: " + this.getName() + " Mana: " + this.mana;
+ }
+
+ /**
+ * castSpell onto target Creatures to deal damage
+ * and reduces current mana value
+ *
+ * @param target Creature to deal damage to
+ * @throws LowManaException if mana value is too low
+ */
+ protected void castSpell(final Creature target)
+ throws LowManaException
+ {
+ if (this.mana < MANA_USAGE) {
+ throw new LowManaException("Not enough mana to cast spell");
+ }
+
+ this.mana -= MANA_USAGE;
+
+ target.takeDamage(MANA_DAMAGE);
+ }
+
+ /**
+ * restoreMana by a given value and is maxed
+ * to MAX_MANA_VALUE
+ *
+ * @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 fab05c6..5cb559a 100644
--- a/src/code/ca/bcit/comp2522/lab02/HealingException.java
+++ b/src/code/ca/bcit/comp2522/lab02/HealingException.java
@@ -1,5 +1,12 @@
package ca.bcit.comp2522.lab02;
+/**
+ * HealingException is an unchecked exception
+ * for when a given healing value is invalid.
+ *
+ * @author Braeden Sowinski
+ * @version 1.0.0
+ */
public class HealingException extends RuntimeException {
public HealingException(String message) {
super(message);
diff --git a/src/code/ca/bcit/comp2522/lab02/LowFirePowerException.java b/src/code/ca/bcit/comp2522/lab02/LowFirePowerException.java
new file mode 100644
index 0000000..dfe0ac9
--- /dev/null
+++ b/src/code/ca/bcit/comp2522/lab02/LowFirePowerException.java
@@ -0,0 +1,14 @@
+package ca.bcit.comp2522.lab02;
+
+/**
+ * LowFirePowerException is a checked exception
+ * when firePower is too low to deal damage.
+ *
+ * @author Braeden Sowinski
+ * @version 1.0.0
+ */
+public class LowFirePowerException extends Exception {
+ 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
new file mode 100644
index 0000000..f4bcdb4
--- /dev/null
+++ b/src/code/ca/bcit/comp2522/lab02/LowManaException.java
@@ -0,0 +1,14 @@
+package ca.bcit.comp2522.lab02;
+
+/**
+ * LowManaException is a checked exception
+ * when mana is too low to deal damage.
+ *
+ * @author Braeden Sowinski
+ * @version 1.0.0
+ */
+public class LowManaException extends Exception {
+ 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
new file mode 100644
index 0000000..85cb888
--- /dev/null
+++ b/src/code/ca/bcit/comp2522/lab02/LowRageException.java
@@ -0,0 +1,14 @@
+package ca.bcit.comp2522.lab02;
+
+/**
+ * LowRageException is a checked exception
+ * when rage is too low to deal damage.
+ *
+ * @author Braeden Sowinski
+ * @version 1.0.0
+ */
+public class LowRageException extends Exception {
+ 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
new file mode 100644
index 0000000..2331f35
--- /dev/null
+++ b/src/code/ca/bcit/comp2522/lab02/Orc.java
@@ -0,0 +1,91 @@
+package ca.bcit.comp2522.lab02;
+
+/**
+ * Orc extends Creature and
+ * holds a rage value. Orcs need anger management.
+ *
+ * @author Braeden Sowinski
+ * @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;
+ private static final int DAMAGE_THRESHOLD = 20;
+ private static final int DAMAGE = 15;
+ private static final int DOUBLE = 2;
+
+ private int rage;
+
+ /*
+ * validateRageValue ensures a given value is within
+ * the correct rage range
+ *
+ * @param value to verify
+ * @throws IllegalArgumentException if rage is outside valid range
+ */
+ private static void validateRageValue(final int value)
+ throws IllegalArgumentException
+ {
+ if (value < MIN_RAGE_VALUE || value > MAX_RAGE_VALUE) {
+ throw new IllegalArgumentException("Invalid rage value: " + value);
+ }
+ }
+
+ /**
+ * Orc constructor
+ *
+ * @param name String
+ * @param dateOfBirth Date
+ * @param health int
+ * @param rage int
+ */
+ Orc(
+ final String name,
+ final Date dateOfBirth,
+ final int health,
+ final int rage
+ ) {
+ super(name, dateOfBirth, health);
+
+ validateRageValue(rage);
+
+ this.rage = rage;
+ }
+
+ /**
+ * getDetails of orc with rage
+ *
+ * @return details of orc
+ */
+ @Override
+ protected String getDetails() {
+ return "Name: " + this.getName() + " Rage: " + this.rage;
+ }
+
+ /**
+ * bezerk goes the orc when he is really mad.
+ * dealing damage to target Creatures with the
+ * potential for double damage.
+ *
+ * @param target Creature to deal damage to
+ * @throws LowRageException if rage value is too low
+ */
+ protected void bezerk(final Creature target)
+ throws LowRageException
+ {
+ this.rage += RAGE_INCREMENT;
+
+ 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);
+ }
+ }
+}