Player Class completed, built subclasses and completed first implements and constructors.
This commit is contained in:
Generated
+5
@@ -16,5 +16,10 @@
|
||||
<option name="name" value="JBoss Community repository" />
|
||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://maven.myket.ir" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.project.entity;
|
||||
|
||||
public interface Entity {
|
||||
|
||||
void attack(Entity target);
|
||||
|
||||
void defend();
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,16 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Knight {
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
|
||||
public class Knight extends Player implements Entity {
|
||||
public Knight(String name, int hp, int mp, Weapon weapon, Armor armor) {
|
||||
super(name, hp, mp, weapon, armor);
|
||||
setMaxMP(45);
|
||||
setMaxHP(45);
|
||||
}
|
||||
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
|
||||
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ import org.project.entity.Entity;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Player {
|
||||
|
||||
public abstract class Player implements Entity {
|
||||
protected String name;
|
||||
Weapon weapon;
|
||||
Armor armor;
|
||||
@@ -13,6 +13,9 @@ public abstract class Player {
|
||||
private int maxHP;
|
||||
private int mp;
|
||||
private int maxMP;
|
||||
private final int defendCost = 6;
|
||||
private boolean isDefending = false;
|
||||
private final int healCost = 12;
|
||||
|
||||
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
|
||||
this.name = name;
|
||||
@@ -30,17 +33,48 @@ public abstract class Player {
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
// TODO
|
||||
}
|
||||
//checking mana
|
||||
if (mp < defendCost) {
|
||||
System.out.println("Not enough mana to defend!");
|
||||
return;
|
||||
}
|
||||
|
||||
//reducing mana
|
||||
mp -= defendCost;
|
||||
|
||||
//activating defense mode
|
||||
isDefending = true;
|
||||
|
||||
System.out.println("🛡️ " + name + " raises shield, preparing to block next attack!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
hp -= damage - armor.getDefense();
|
||||
int actualDamage = damage;
|
||||
|
||||
//reducing damage if the player is in defend mode
|
||||
if (isDefending) {
|
||||
actualDamage = damage / 2;
|
||||
System.out.println("🛡️ Defense reduced damage from " + damage + " to " + actualDamage);
|
||||
isDefending = false;
|
||||
}
|
||||
|
||||
hp -= actualDamage;
|
||||
if (hp < 0) {hp = 0;}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int health) {
|
||||
//checking mana
|
||||
if (mp < healCost) {
|
||||
System.out.println("Not enough mana to heal!");
|
||||
return;
|
||||
}
|
||||
|
||||
//reducing mana
|
||||
mp -= healCost;
|
||||
|
||||
//increasing health
|
||||
hp += health;
|
||||
if (hp > maxHP) {
|
||||
hp = maxHP;
|
||||
@@ -49,10 +83,19 @@ public abstract class Player {
|
||||
|
||||
@Override
|
||||
public void fillMana(int mana) {
|
||||
int oldMana = mp;
|
||||
mp += mana;
|
||||
|
||||
mp += mana;
|
||||
if (mp > maxMP) {
|
||||
mp = maxMP;
|
||||
}
|
||||
|
||||
if (mp == maxMP) {
|
||||
System.out.println("Mana is now full! (" + mp + "/" + maxMP + ")");
|
||||
} else {
|
||||
System.out.println("Mana increased from " + oldMana + " to " + mp);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,4 +129,11 @@ public abstract class Player {
|
||||
return armor;
|
||||
}
|
||||
|
||||
public void setMaxMP(int amount) {
|
||||
maxMP = amount;
|
||||
}
|
||||
|
||||
public void setMaxHP(int amount) {
|
||||
maxHP = amount;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user