Fixes
This commit is contained in:
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()){
|
if (!this.isAlive()){
|
||||||
throw new RuntimeException("The creature is not alive.");
|
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 -= damage;
|
||||||
this.health = NO_HEALTH;
|
|
||||||
}
|
if (this.health < NO_HEALTH) {
|
||||||
|
this.health = NO_HEALTH;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -83,10 +83,9 @@ public class Dragon extends Creature {
|
|||||||
if (!this.isAlive()) {
|
if (!this.isAlive()) {
|
||||||
throw new RuntimeException("The dragon is not alive.");
|
throw new RuntimeException("The dragon is not alive.");
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
if(firePower < FIRE_POWER_USAGE) {
|
if(firePower < FIRE_POWER_USAGE) {
|
||||||
throw new LowFirePowerException("Fire power too low");
|
throw new LowFirePowerException("Fire power too low");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.firePower -= FIRE_POWER_USAGE;
|
this.firePower -= FIRE_POWER_USAGE;
|
||||||
|
|||||||
@@ -83,15 +83,15 @@ public class Elf extends Creature {
|
|||||||
if(!this.isAlive()){
|
if(!this.isAlive()){
|
||||||
throw new RuntimeException("The elf is not alive.");
|
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");
|
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -86,24 +86,21 @@ public class Orc extends Creature {
|
|||||||
if(!this.isAlive()){
|
if(!this.isAlive()){
|
||||||
throw new RuntimeException("The orc is not alive.");
|
throw new RuntimeException("The orc is not alive.");
|
||||||
}
|
}
|
||||||
else{
|
|
||||||
|
|
||||||
this.rage += RAGE_INCREMENT;
|
this.rage += RAGE_INCREMENT;
|
||||||
|
|
||||||
if (this.rage > MAX_RAGE_VALUE) {
|
if (this.rage > MAX_RAGE_VALUE) {
|
||||||
this.rage = MAX_RAGE_VALUE;
|
this.rage = MAX_RAGE_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rage < RAGE_INCREMENT) {
|
if (rage < RAGE_INCREMENT) {
|
||||||
throw new LowRageException("Rage too low");
|
throw new LowRageException("Rage too low");
|
||||||
} else if (this.rage > DAMAGE_THRESHOLD) {
|
} else if (this.rage > DAMAGE_THRESHOLD) {
|
||||||
target.takeDamage(DAMAGE * DOUBLE);
|
target.takeDamage(DAMAGE * DOUBLE);
|
||||||
} else {
|
} else {
|
||||||
target.takeDamage(DOUBLE);
|
target.takeDamage(DAMAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -34,24 +34,24 @@ public class CreatureTest {
|
|||||||
elfBirthDate = new Date(1900, 11, 5);
|
elfBirthDate = new Date(1900, 11, 5);
|
||||||
orcBirthDate = new Date(500, 5, 3);
|
orcBirthDate = new Date(500, 5, 3);
|
||||||
|
|
||||||
creatureDragon = new Dragon("Sparky", dragonBirthDate, 5, 60);
|
creatureDragon = new Dragon("Sparky", dragonBirthDate, 5, 60);
|
||||||
creatureElf = new Elf("Ben", elfBirthDate, 10, 15);
|
creatureElf = new Elf("Ben", elfBirthDate, 10, 15);
|
||||||
creatureOrc = new Orc("Shobob", orcBirthDate, 12, 3);
|
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 {
|
try {
|
||||||
|
|
||||||
System.out.println("- Dragon breathed fire on the Elf");
|
System.out.println("- Dragon breathed fire on the Elf");
|
||||||
|
|||||||
Reference in new issue
Block a user