implement Entity class

This commit is contained in:
2026-05-10 16:15:54 +03:30
parent 494f97935e
commit e14965a649
@@ -1,19 +1,41 @@
package org.project.entity; package org.project.entity;
public interface Entity { import org.project.item.weapons.Weapon;
void attack(Entity target);
void defend(); public abstract class Entity {
void heal(int health); private Weapon weapon;
private int hp;
private int maxHP;
void fillMana(int mana);
void takeDamage(int damage); public Entity(Weapon weapon, int hp, int maxHP) {
this.weapon = weapon;
this.hp = hp;
this.maxHP = maxHP;
}
int getMaxHP(); public boolean isAlive() {
if(hp>0)
return true;
int getMaxMP(); return false;
}
public abstract void attack(Entity target);
public void heal(int health) {
hp += health;
if (hp > maxHP) {
hp = maxHP;
}
}
public void takeDamage(int damage) {hp -= weapon.getDamage();}
public int getMaxHP() {return maxHP;}
public int getHP() {return hp;}
public Weapon getWeapon() {return weapon;}
/* /*
TODO: ADD OTHER REQUIRED AND BONUS METHODS TODO: ADD OTHER REQUIRED AND BONUS METHODS