Knight Class and KnightArmor Class completed, Player Class updated.

This commit is contained in:
2026-05-10 01:06:15 +03:30
parent 3804297a29
commit 4f2320f632
7 changed files with 44 additions and 29 deletions
@@ -15,8 +15,4 @@ public interface Entity {
int getMaxHP();
int getMaxMP();
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
}
@@ -5,9 +5,7 @@ import org.project.item.armors.Armor;
import org.project.item.weapons.Weapon;
public class Assassin extends Player implements Entity {
public Assassin(String name, int hp, int mp, Weapon weapon, Armor armor) {
super(name, hp, mp, weapon, armor);
setMaxMP(60);
setMaxHP(45);
public Assassin(String name, Weapon weapon, Armor armor) {
super(name, 45, 60, weapon, armor);
}
}
@@ -3,6 +3,7 @@ package org.project.entity.players;
import org.project.entity.Entity;
import org.project.entity.enemies.Enemy;
import org.project.item.armors.Armor;
import org.project.item.armors.KnightArmor;
import org.project.item.weapons.Sword;
import org.project.item.weapons.Weapon;
@@ -10,22 +11,20 @@ import java.util.ArrayList;
public class Knight extends Player {
Sword sword = new Sword()
public Knight(String name, Weapon weapon, Armor armor) {
super(name, 45, 45, weapon, armor);
public Knight(String name) {
super(name, 45, 45, new Sword(), new KnightArmor());
}
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
@Override
public void uniqueAbility(Entity target) {
//Checking if the mana is enough of not
if (super.getMp() < 15) {
if (getMp() < 15) {
System.out.println("Mana is not enough for Shield Bash!");
return;
}
//Consuming mana
super.setMp(getMp()-15);
setMp(getMp()-15);
//Stunning the enemies
if (getWeapon() instanceof Sword) {
@@ -55,14 +55,29 @@ public abstract class Player implements Entity {
int actualDamage = damage;
//reducing damage if the player is in defend mode
if (isDefending) {
if (isDefending()) {
actualDamage = damage / 2;
System.out.println("🛡️ Defense reduced damage from " + damage + " to " + actualDamage);
isDefending = false;
setDefending(false);
}
hp -= actualDamage;
if (hp < 0) {hp = 0;}
if (armor != null && !armor.isBroke()) {
int defense = armor.getDefense();
actualDamage -= defense;
if (actualDamage < 0) actualDamage = 0;
armor.reduceDurability(1);
System.out.println("🛡️ Armor blocked " + defense +
" damage! Remaining durability: " + armor.getDurability());
}
setHp(getHp() - actualDamage);
System.out.println("💥 " + getName() + " took " + actualDamage + " damage! HP: " + getHp());
if (getHp() < 0) {
setHp(0);
System.out.println("💀 " + getName() + " has been defeated!");
}
}
@Override
@@ -132,6 +147,10 @@ public abstract class Player implements Entity {
return armor;
}
public boolean isDefending() {
return isDefending;
}
public void setHp(int hp) {
this.hp = hp;
}
@@ -139,4 +158,8 @@ public abstract class Player implements Entity {
public void setMp(int mp) {
this.mp = mp;
}
public void setDefending(boolean defending) {
isDefending = defending;
}
}
@@ -5,9 +5,7 @@ import org.project.item.armors.Armor;
import org.project.item.weapons.Weapon;
public class Wizard extends Player implements Entity {
public Wizard (String name, int hp, int mp, Weapon weapon, Armor armor) {
super(name, hp, mp, weapon, armor);
setMaxMP(45);
setMaxHP(60);
public Wizard (String name, Weapon weapon, Armor armor) {
super(name, 60, 45, weapon, armor);
}
}
@@ -4,8 +4,4 @@ import org.project.entity.Entity;
public interface Item {
void use(Entity target);
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
}
}
@@ -8,7 +8,7 @@ public abstract class Armor implements Item {
private int maxDefense;
private int durability;
private int maxDurability;
private boolean isBroke;
public boolean isBroke;
public Armor(int defense, int durability) {
this.defense = defense;
@@ -18,13 +18,14 @@ public abstract class Armor implements Item {
this.isBroke = false;
}
public void checkBreak() {
public boolean checkBreak() {
if (durability <= 0) {
isBroke = true;
defense = 0;
durability = 0;
System.out.println("Armor is broken!");
}
return isBroke;
}
public void repair() {
@@ -62,4 +63,8 @@ public abstract class Armor implements Item {
public boolean isBroke() {
return isBroke;
}
public void setDefense(int defense) {
this.defense = defense;
}
}