Updated Knight Class.

This commit is contained in:
2026-05-10 01:28:59 +03:30
parent 4f2320f632
commit a8ec615e1b
5 changed files with 62 additions and 15 deletions
@@ -2,8 +2,6 @@ package org.project.entity;
public interface Entity { public interface Entity {
void attack(Entity target);
void defend(); void defend();
void heal(int health); void heal(int health);
@@ -0,0 +1,18 @@
package org.project.entity.players;
import org.project.entity.Entity;
import java.util.ArrayList;
public interface ICombatActions {
void lightAttack(Entity target);
void heavyAttack(Entity target);
void defend();
void heal();
void specialAbility(Entity target);
}
@@ -10,13 +10,13 @@ import org.project.item.weapons.Weapon;
import java.util.ArrayList; import java.util.ArrayList;
public class Knight extends Player { public class Knight extends Player implements ICombatActions {
public Knight(String name) { public Knight(String name) {
super(name, 45, 45, new Sword(), new KnightArmor()); super(name, 45, 45, new Sword(), new KnightArmor());
} }
@Override @Override
public void uniqueAbility(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!");
@@ -33,4 +33,46 @@ public class Knight extends Player {
System.out.println("💥 Shield Bash! Enemy is stunned!"); System.out.println("💥 Shield Bash! Enemy is stunned!");
} }
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!");
}
} }
@@ -28,11 +28,6 @@ public abstract class Player implements Entity {
this.armor = armor; this.armor = armor;
} }
@Override
public void attack(Entity target) {
target.takeDamage(weapon.getDamage());
}
@Override @Override
public void defend() { public void defend() {
//checking mana //checking mana
@@ -115,8 +110,6 @@ public abstract class Player implements Entity {
} }
} }
public abstract void uniqueAbility(Entity target);
public String getName() { public String getName() {
return name; return name;
} }
@@ -36,8 +36,4 @@ public abstract class Weapon implements Item {
public void setManaCost(int manaCost) { public void setManaCost(int manaCost) {
this.manaCost = manaCost; this.manaCost = manaCost;
} }
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
} }