implement Dragon class

This commit is contained in:
2026-05-10 11:57:40 +03:30
parent 3ab38fddce
commit 7c60722ff2
15 changed files with 70 additions and 2 deletions
@@ -108,7 +108,8 @@ public class Main {
while (player.isAlive() && enemy.isAlive()) {
if (turn == 0) {
turn = 1;
System.out.println("choose your action:\n1.light attack 2.heavy attack 3.defend 4.heal 5.special ability");
System.out.println("choose your action:\n1.light attack 2.heavy attack " +
"3.defend 4.heal 5.special ability 6.flask");
choice = sc.nextInt();
switch (choice) {
case 1:
@@ -131,8 +132,15 @@ public class Main {
player.specialAbility(enemy);
if (player.isSuccessfulAction()) break;
else {turn = 0; continue;}
case 6:
player.getFlask().use(player);
break;
default:
System.out.println("invalid choice");
turn = 0;
continue;
}
System.out.println("[" + player.getClass().getSimpleName() + " - " + player.getHP() + "/" + player.getMaxHP()
+ " HP | " + player.getMP() + "/" + player.getMaxMP() + " Mana" + "]");
@@ -0,0 +1,60 @@
package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.item.weapons.Sword;
public class Dragon extends Enemy {
private static final int FIRE_BREATH_MP_COST = 30;
private int fireBreathCharge = 0;
public Dragon() {
super(200, 150, new Sword());
setDefendRate(.5);
}
@Override
public void attack(Entity target) {
System.out.println("Dragon breathes fire at " + target.getClass().getSimpleName() + "!");
fireBreathCharge++;
double damage = getAttackMultiplier() * getWeapon().getDamage();
if (fireBreathCharge >= 3) {
fireBreathCharge = 0;
System.out.println("FIRE BREATH! Dragon unleashes a devastating inferno!");
damage *= 2;
if (target.isDefending()) {
target.setDefending(false);
}
target.takeDamage((int) damage);
setMP(getMP() - FIRE_BREATH_MP_COST);
}
if (target.isDefending()) {
target.setDefending(false);
}
target.takeDamage((int) damage);
setMP(getMP() - getWeapon().getManaCost());
}
@Override
public void defend() {
System.out.println("Dragon roars and ignores the chance to defend!");
setSuccessfulAction(false);
}
@Override
public void heal(int health) {
if (getMP() >= 20) {
System.out.println("Dragon regenerates " + health + " HP!");
setHP(getHP() + health);
setMP(getMP() - 20);
} else {
System.out.println("Dragon has no mana to regenerate!");
setSuccessfulAction(false);
}
}
}
@@ -24,7 +24,7 @@ public abstract class Enemy implements Entity {
this.mp = mp;
this.maxMP = mp;
this.weapon = weapon;
if (!keyFound) { hasKey = Math.random() < .2;}
if (!keyFound) { hasKey = Math.random() < .9;}
}
@Override
Binary file not shown.