Adding armors and updating the Armor Class.

This commit is contained in:
2026-05-09 23:28:16 +03:30
parent 0b00500450
commit 3804297a29
6 changed files with 72 additions and 22 deletions
@@ -3,12 +3,14 @@ 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.weapons.Sword;
import org.project.item.weapons.Weapon;
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);
}
@@ -23,13 +25,12 @@ public class Knight extends Player {
}
//Consuming mana
super.setMp(super.getMp()-15);
super.setMp(getMp()-15);
//Stunning the enemies
target.takeDamage(25);
if (target instanceof Enemy) {
((Enemy) target).setStunned(true);
}
if (getWeapon() instanceof Sword) {
((Sword) getWeapon()).uniqueAbility(target);
}
System.out.println("💥 Shield Bash! Enemy is stunned!");
}
@@ -1,31 +1,54 @@
package org.project.item.armors;
// TODO: UPDATE IMPLEMENTATION
public abstract class Armor {
import org.project.entity.Entity;
import org.project.item.Item;
public abstract class Armor implements Item {
private int defense;
private int maxDefense;
private int durability;
private int maxDurability;
private boolean isBroke;
public Armor(int defense, int durability) {
this.defense = defense;
this.durability = durability;
this.maxDefense = defense;
this.maxDurability = durability;
this.isBroke = false;
}
public void checkBreak() {
if (durability <= 0) {
isBroke = true;
defense = 0;
durability = 0;
System.out.println("Armor is broken!");
}
}
// TODO: (BONUS) UPDATE THE REPAIR METHOD
public void repair() {
isBroke = false;
defense = maxDefense;
durability = maxDurability;
if (isBroke) {
isBroke = false;
defense = maxDefense;
durability = maxDurability;
System.out.println("🔧 Armor repaired! Defense: " + defense + ", Durability: " + durability);
}
else {
System.out.println("Armor is not broken. No need to repair.");
}
}
public void reduceDurability(int amount) {
if (!isBroke) {
durability -= amount;
checkBreak();
}
}
@Override
public void use(Entity target) {
System.out.println("🛡️ " + getClass().getSimpleName() + " equipped. Defense: " + defense);
}
public int getDefense() {
@@ -0,0 +1,7 @@
package org.project.item.armors;
public class AssassinMask extends Armor {
public AssassinMask() {
super(4, 20);
}
}
@@ -1,6 +1,8 @@
package org.project.item.armors;
// TODO: UPDATE IMPLEMENTATION
public class KnightArmor {
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
//The knight's armor
public class KnightArmor extends Armor {
public KnightArmor() {
super(5, 25);
}
}
@@ -0,0 +1,8 @@
package org.project.item.armors;
//The Wizard's armor
public class WizardRobe extends Armor {
public WizardRobe() {
super(3, 15);
}
}
@@ -1,23 +1,32 @@
package org.project.item.weapons;
import org.project.entity.Entity;
import org.project.entity.enemies.Enemy;
import org.project.item.Item;
import java.util.ArrayList;
//The knight's weapon
public class Sword extends Weapon implements Item {
int abilityCharge;
public class Sword extends Weapon {
private int abilityCharge;
public Sword(int damage, int manaCost) {
super(damage, manaCost);
public Sword() {
super(10, 8);
this.abilityCharge = 0;
}
public void uniqueAbility(ArrayList<Entity> targets) {
//Bonus method
public void uniqueAbility(Entity target) {
abilityCharge += 2;
for (Entity target : targets) {
target.takeDamage(getDamage());
int totalDamage = getDamage() + (abilityCharge / 2);
target.takeDamage(totalDamage);
if (target instanceof Enemy) {
((Enemy) target).setStunned(true);
}
}
public int getAbilityCharge() {
return abilityCharge;
}
}