This commit is contained in:
nicoagostini committed 2025-09-21 00:42:25 -07:00
1 parent 9bb3af19a9
commit 18ec34592d
5 files changed
+42 -47

No files matched your search

@@ -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;
}
}
+3 -4
View File
@@ -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;
+5 -5
View File
@@ -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);
}
}
/**
+11 -14
View File
@@ -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);
}
}
}
}
+16 -16
View File
@@ -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");