Added Enemy subclasses and completed Assasin and Wizard classes.

This commit is contained in:
2026-05-10 11:21:48 +03:30
parent a8ec615e1b
commit c0c32b2dce
12 changed files with 225 additions and 15 deletions
@@ -1,6 +1,7 @@
package org.project.entity.enemies; package org.project.entity.enemies;
import org.project.entity.Entity; import org.project.entity.Entity;
import org.project.item.weapons.Sword;
import org.project.item.weapons.Weapon; import org.project.item.weapons.Weapon;
public abstract class Enemy implements Entity { public abstract class Enemy implements Entity {
@@ -9,11 +10,15 @@ public abstract class Enemy implements Entity {
private int mp; private int mp;
private boolean isStunned = false; private boolean isStunned = false;
private int stunTurns = 0; private int stunTurns = 0;
private String name;
private final int defendCost = 6;
private boolean isDefending = false;
private final int healCost = 12;
public Enemy(int hp, int mp, Weapon weapon) { public Enemy(String name, int hp, int mp, Weapon weapon) {
this.name = name;
this.hp = hp; this.hp = hp;
this.mp = mp; this.mp = mp;
this.weapon = weapon; this.weapon = weapon;
} }
@@ -39,6 +44,28 @@ public abstract class Enemy implements Entity {
} }
} }
@Override
public void fillMana(int mana) {
int oldMana = mp;
mp += mana;
mp += mana;
if (mp > getMaxMP()) {
mp = getMaxMP();
}
}
@Override
public void defend() {
//checking mana
//reducing mana
mp -= defendCost;
//activating defense mode
isDefending = true;
}
public boolean isStunned() { public boolean isStunned() {
return isStunned; return isStunned;
} }
@@ -54,4 +81,17 @@ public abstract class Enemy implements Entity {
public Weapon getWeapon() { public Weapon getWeapon() {
return weapon; return weapon;
} }
public String getName(Entity target) {
if (target instanceof Skeleton) {
return "Skeleton";
}
else if (target instanceof Goblin) {
return "Goblin";
}
else if (target instanceof Vampire) {
return "Vampire";
}
return "Dragon";
}
} }
@@ -0,0 +1,4 @@
package org.project.entity.enemies;
public class Goblin {
}
@@ -1,6 +1,11 @@
package org.project.entity.enemies; package org.project.entity.enemies;
import org.project.item.weapons.BoneDagger;
// TODO: UPDATE IMPLEMENTATION // TODO: UPDATE IMPLEMENTATION
public class Skeleton { public class Skeleton extends Enemy {
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR // TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
public Skeleton() {
super("Skeleton", 40, 25, new BoneDagger());
}
} }
@@ -0,0 +1,4 @@
package org.project.entity.enemies;
public class Vampire {
}
@@ -4,8 +4,86 @@ import org.project.entity.Entity;
import org.project.item.armors.Armor; import org.project.item.armors.Armor;
import org.project.item.weapons.Weapon; import org.project.item.weapons.Weapon;
public class Assassin extends Player implements Entity { public class Assassin extends Player implements Entity, ICombatActions {
public Assassin(String name, Weapon weapon, Armor armor) { public Assassin(String name, Weapon weapon, Armor armor) {
super(name, 45, 60, weapon, armor); super(name, 45, 60, weapon, armor);
} }
}
@Override
public void specialAbility(Entity target) {
//Checking if the mana is enough of not
if (getMp() < 15) {
System.out.println("❌ Not enough mana for Devastating Spell!");
return;
}
//Consuming mana
setMp(getMp()-15);
setInvisible(true);
setNextAttackCritical(true);
System.out.println("💜 " + getName() + " turns INVISIBLE!");
System.out.println("⚡ Next attack will be CRITICAL (2x damage)!");
System.out.println("🛡️ Will dodge the next incoming attack completely!");
System.out.println("💙 Mana left: " + getMp());
}
public void lightAttack(Entity target) {
int damage = 10;
//Critical Action (if enabled)
if (isNextAttackCritical()) {
damage *= 2;
System.out.println("⚡ CRITICAL HIT! Damage doubled to " + damage + "!");
setNextAttackCritical(false);
}
target.takeDamage(damage);
System.out.println("⚔️ " + getName() + " used Light Attack! Dealt " + damage + " damage.");
}
@Override
public void heavyAttack(Entity target) {
if (getMp() < 8) {
System.out.println("❌ Not enough mana for Heavy Attack!");
return;
}
setMp(getMp() - 8);
int damage = 20;
//Critical Action (if enabled)
if (isNextAttackCritical()) {
damage *= 2;
System.out.println("⚡ CRITICAL HIT! Damage doubled to " + damage + "!");
setNextAttackCritical(false);
}
target.takeDamage(damage);
System.out.println("💥 " + getName() + " used Heavy Attack! Dealt " + damage + " damage.");
}
@Override
public void defend() {
if (getMp() < 6) {
System.out.println("❌ Not enough mana to defend!");
return;
}
setMp(getMp() - 6);
setDefending(true);
System.out.println("🛡️ " + getName() + " is defending! Next attack will be halved.");
}
@Override
public void heal() {
if (getMp() < 12) {
System.out.println("❌ Not enough mana to heal!");
return;
}
setMp(getMp() - 12);
int healAmount = 20;
setHp(getHp() + healAmount);
if (getHp() > getMaxHP()) setHp(getMaxHP());
System.out.println("💚 " + getName() + " healed " + healAmount + " HP!");
}
}
@@ -15,4 +15,4 @@ public interface ICombatActions {
void heal(); void heal();
void specialAbility(Entity target); void specialAbility(Entity target);
} }
@@ -19,7 +19,7 @@ public class Knight extends Player implements ICombatActions {
public void specialAbility(Entity target) { public void specialAbility(Entity target) {
//Checking if the mana is enough of not //Checking if the mana is enough of not
if (getMp() < 15) { if (getMp() < 15) {
System.out.println("Mana is not enough for Shield Bash!"); System.out.println("Mana is not enough for Shield Bash!");
return; return;
} }
@@ -18,6 +18,8 @@ public abstract class Player implements Entity {
private final int defendCost = 6; private final int defendCost = 6;
private boolean isDefending = false; private boolean isDefending = false;
private final int healCost = 12; private final int healCost = 12;
private boolean isInvisible = false;
private boolean nextAttackCritical = false;
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) { public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
this.name = name; this.name = name;
@@ -144,6 +146,14 @@ public abstract class Player implements Entity {
return isDefending; return isDefending;
} }
public boolean isInvisible() { return isInvisible; }
public boolean isNextAttackCritical() { return nextAttackCritical; }
public void setInvisible(boolean invisible) { this.isInvisible = invisible; }
public void setNextAttackCritical(boolean critical) { this.nextAttackCritical = critical; }
public void setHp(int hp) { public void setHp(int hp) {
this.hp = hp; this.hp = hp;
} }
@@ -2,10 +2,79 @@ package org.project.entity.players;
import org.project.entity.Entity; import org.project.entity.Entity;
import org.project.item.armors.Armor; import org.project.item.armors.Armor;
import org.project.item.weapons.Sword;
import org.project.item.weapons.Wand;
import org.project.item.weapons.Weapon; import org.project.item.weapons.Weapon;
public class Wizard extends Player implements Entity { public class Wizard extends Player implements Entity,ICombatActions {
public Wizard (String name, Weapon weapon, Armor armor) { public Wizard (String name, Weapon weapon, Armor armor) {
super(name, 60, 45, weapon, armor); super(name, 60, 45, new Wand(), armor);
}
@Override
public void specialAbility(Entity target) {
//Checking if the mana is enough of not
if (getMp() < 15) {
System.out.println("❌ Not enough mana for Devastating Spell!");
return;
}
//Consuming mana
setMp(getMp()-15);
target.takeDamage(30);
System.out.println("🔮 " + target.getName() + " took " +
30 + " damage from Devastating Spell!");
int newHp = getHp() + 10;
if (newHp > getMaxHP()) newHp = getMaxHP();
setHp(newHp);
System.out.println("💚 " + getName() + " healed " + 10 + " HP! (Now: " +
getHp() + "/" + getMaxHP() + ")");
System.out.println("🔮 " + getName() + " casts DEVASTATING SPELL!");
System.out.println("💙 Mana left: " + getMp());
}
public void lightAttack(Entity target) {
int damage = 10;
target.takeDamage(damage);
System.out.println("⚔️ " + getName() + " used Light Attack! Dealt " + damage + " damage.");
}
@Override
public void heavyAttack(Entity target) {
if (getMp() < 8) {
System.out.println("❌ Not enough mana for Heavy Attack!");
return;
}
setMp(getMp() - 8);
int damage = 20;
target.takeDamage(damage);
System.out.println("💥 " + getName() + " used Heavy Attack! Dealt " + damage + " damage.");
}
@Override
public void defend() {
if (getMp() < 6) {
System.out.println("❌ Not enough mana to defend!");
return;
}
setMp(getMp() - 6);
setDefending(true);
System.out.println("🛡️ " + getName() + " is defending! Next attack will be halved.");
}
@Override
public void heal() {
if (getMp() < 12) {
System.out.println("❌ Not enough mana to heal!");
return;
}
setMp(getMp() - 12);
int healAmount = 20;
setHp(getHp() + healAmount);
if (getHp() > getMaxHP()) setHp(getMaxHP());
System.out.println("💚 " + getName() + " healed " + healAmount + " HP!");
} }
} }
@@ -6,7 +6,7 @@ import org.project.item.Item;
public class BoneDagger extends Weapon implements Item { public class BoneDagger extends Weapon implements Item {
int abilityCharge; int abilityCharge;
public BoneDagger(int damage, int manaCost) { public BoneDagger() {
super(damage, manaCost); super(10, 5);
} }
} }
@@ -6,7 +6,7 @@ import org.project.item.Item;
public class Dagger extends Weapon implements Item { public class Dagger extends Weapon implements Item {
int abilityCharge; int abilityCharge;
public Dagger(int damage, int manaCost) { public Dagger() {
super(damage, manaCost); super(15, 10);
} }
} }
@@ -6,7 +6,7 @@ import org.project.item.Item;
public class Wand extends Weapon implements Item { public class Wand extends Weapon implements Item {
int abilityCharge; int abilityCharge;
public Wand(int damage, int manaCost) { public Wand() {
super(damage, manaCost); super(12, 6);
} }
} }