update players project

This commit is contained in:
2026-05-03 19:18:27 +03:30
parent 2bfb6a891c
commit 4935b9f901
5 changed files with 81 additions and 46 deletions
@@ -1,5 +1,7 @@
package org.project.entity;
import org.project.item.weapons.Weapon;
public interface Entity {
void attack(Entity target, double multiplier);
@@ -7,15 +9,31 @@ public interface Entity {
void heal(int health);
void fillMana(int mana);
void takeDamage(int damage);
int getHP();
void setHP(int hp);
int getMaxHP();
int getMP();
void setMP(int mana);
void setMaxHP(int maxHP);
int getMaxMP();
void setMaxMP(int maxMP);
boolean isDefending();
void setDefending(boolean defending);
double getDefendRate();
void setDefendRate(double defendRate);
Weapon getWeapon();
}
@@ -19,9 +19,9 @@ public class Assassin extends Player {
@Override
public void heavyAttack(Entity target) {
if (getMp() >= 8) {
if (getMP() >= 8) {
attack(target, 2.5);
setMp(getMp() - 8);
setMP(getMP() - 8);
}
else {
System.out.println("Not enough MP");
@@ -30,9 +30,9 @@ public class Assassin extends Player {
@Override
public void defend() {
if (getMp() >= 4) {
if (getMP() >= 4) {
super.defend();
setMp(getMp() - 4);
setMP(getMP() - 4);
}
else {
System.out.println("Not enough MP");
@@ -41,10 +41,10 @@ public class Assassin extends Player {
@Override
public void specialAbility(Entity target) {
if (getMp() >= 20) {
if (getMP() >= 20) {
setDefendRate(1);
defend();
setMp(getMp() - 20);
setMP(getMP() - 20);
//incomplete
}
else {
@@ -54,9 +54,9 @@ public class Assassin extends Player {
@Override
public void heal(int health) {
if (getMp() >= 5) {
if (getMP() >= 5) {
super.heal(health);
setMp(getMp() - 5);
setMP(getMP() - 5);
}
else {
System.out.println("Not enough MP");
@@ -19,9 +19,9 @@ public class Knight extends Player {
@Override
public void heavyAttack(Entity target) {
if (getMp() >= 8) {
if (getMP() >= 8) {
attack(target, 1.8);
setMp(getMp() - 8);
setMP(getMP() - 8);
}
else {
System.out.println("Not enough MP");
@@ -30,9 +30,9 @@ public class Knight extends Player {
@Override
public void defend() {
if (getMp() >= 4) {
if (getMP() >= 4) {
super.defend();
setMp(getMp() - 4);
setMP(getMP() - 4);
}
else {
System.out.println("Not enough MP");
@@ -41,9 +41,9 @@ public class Knight extends Player {
@Override
public void specialAbility(Entity target) {
if (getMp() >= 20) {
if (getMP() >= 20) {
attack(target, 2);
setMp(getMp() - 20);
setMP(getMP() - 20);
//incomplete
}
else {
@@ -53,9 +53,9 @@ public class Knight extends Player {
@Override
public void heal(int health) {
if (getMp() >= 5) {
if (getMP() >= 5) {
super.heal(health);
setMp(getMp() - 5);
setMP(getMP() - 5);
}
else {
System.out.println("Not enough MP");
@@ -54,23 +54,14 @@ public abstract class Player implements Entity, combatOptions {
@Override
public void takeDamage(int damage) {
hp -= damage - armor.getDefense();
int finalDamage = damage - armor.getDefense();
setHP(-finalDamage);
}
@Override
public void heal(int health) {
hp += health;
if (hp > maxHP) {
hp = maxHP;
}
}
@Override
public void fillMana(int mana) {
mp += mana;
if (mp > maxMP) {
mp = maxMP;
}
setHP(getHP() + health);
}
@@ -78,14 +69,18 @@ public abstract class Player implements Entity, combatOptions {
return name;
}
public int getHp() {
@Override
public int getHP() {
return hp;
}
public void fillHp(int hp) {
this.hp += hp;
@Override
public void setHP(int hp) {
this.hp = hp;
if (this.hp > maxHP) {
this.hp = maxHP;
} else if (this.hp < 0) {
this.hp = 0;
}
}
@@ -94,19 +89,39 @@ public abstract class Player implements Entity, combatOptions {
return maxHP;
}
public int getMp() {
@Override
public void setMaxHP(int maxHP) {
this.maxHP = maxHP;
}
@Override
public int getMP() {
return mp;
}
public void setMp(int mp) {
this.mp = mp;
@Override
public void setMP(int mana) {
mp = mana;
if (mp > maxMP) {
mp = maxMP;
} else if (mp < 0) {
mp = 0;
}
}
@Override
public int getMaxMP() {
return maxMP;
}
@Override
public void setMaxMP(int maxMP) {
this.maxMP = maxMP;
}
@Override
public Weapon getWeapon() {
return weapon;
}
@@ -121,8 +136,10 @@ public abstract class Player implements Entity, combatOptions {
@Override
public void setDefending(boolean defending) { this.defending = defending; }
@Override
public double getDefendRate() { return defendRate; }
@Override
public void setDefendRate(double defendRate) { this.defendRate = defendRate; }
}
@@ -18,9 +18,9 @@ public class Wizard extends Player{
@Override
public void heavyAttack(Entity target) {
if (getMp() >= 5) {
if (getMP() >= 5) {
attack(target, 1.6);
setMp(getMp() - 5);
setMP(getMP() - 5);
}
else {
System.out.println("Not enough MP");
@@ -29,9 +29,9 @@ public class Wizard extends Player{
@Override
public void defend() {
if (getMp() >= 4) {
if (getMP() >= 4) {
super.defend();
setMp(getMp() - 4);
setMP(getMP() - 4);
}
else {
System.out.println("Not enough MP");
@@ -40,10 +40,10 @@ public class Wizard extends Player{
@Override
public void specialAbility(Entity target) {
if (getMp() >= 20) {
if (getMP() >= 20) {
attack(target, 2);
setMp(getMp() - 20);
fillHp(10);
setMP(getMP() - 20);
setHP(getHP() + 10);
}
else {
System.out.println("Not enough MP");
@@ -52,9 +52,9 @@ public class Wizard extends Player{
@Override
public void heal(int health) {
if (getMp() >= 5) {
if (getMP() >= 5) {
super.heal(health);
setMp(getMp() - 5);
setMP(getMP() - 5);
}
else {
System.out.println("Not enough MP");