develop #1

Open
Z.Gharagozloo.M wants to merge 14 commits from develop into main
7 changed files with 44 additions and 29 deletions
Showing only changes of commit 4f2320f632 - Show all commits
@@ -15,8 +15,4 @@ public interface Entity {
int getMaxHP(); int getMaxHP();
int getMaxMP(); 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; import org.project.item.weapons.Weapon;
public class Assassin extends Player implements Entity { public class Assassin extends Player implements Entity {
public Assassin(String name, int hp, int mp, Weapon weapon, Armor armor) { public Assassin(String name, Weapon weapon, Armor armor) {
super(name, hp, mp, weapon, armor); super(name, 45, 60, weapon, armor);
setMaxMP(60);
setMaxHP(45);
} }
} }
@@ -3,6 +3,7 @@ package org.project.entity.players;
import org.project.entity.Entity; import org.project.entity.Entity;
import org.project.entity.enemies.Enemy; import org.project.entity.enemies.Enemy;
import org.project.item.armors.Armor; import org.project.item.armors.Armor;
import org.project.item.armors.KnightArmor;
import org.project.item.weapons.Sword; import org.project.item.weapons.Sword;
import org.project.item.weapons.Weapon; import org.project.item.weapons.Weapon;
@@ -10,22 +11,20 @@ import java.util.ArrayList;
public class Knight extends Player { public class Knight extends Player {
Sword sword = new Sword() public Knight(String name) {
public Knight(String name, Weapon weapon, Armor armor) { super(name, 45, 45, new Sword(), new KnightArmor());
super(name, 45, 45, weapon, armor);
} }
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
@Override @Override
public void uniqueAbility(Entity target) { public void uniqueAbility(Entity target) {
//Checking if the mana is enough of not //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!"); System.out.println("Mana is not enough for Shield Bash!");
return; return;
} }
//Consuming mana //Consuming mana
super.setMp(getMp()-15); setMp(getMp()-15);
//Stunning the enemies //Stunning the enemies
if (getWeapon() instanceof Sword) { if (getWeapon() instanceof Sword) {
@@ -55,14 +55,29 @@ public abstract class Player implements Entity {
int actualDamage = damage; int actualDamage = damage;
//reducing damage if the player is in defend mode //reducing damage if the player is in defend mode
if (isDefending) { if (isDefending()) {
actualDamage = damage / 2; actualDamage = damage / 2;
System.out.println("🛡️ Defense reduced damage from " + damage + " to " + actualDamage); System.out.println("🛡️ Defense reduced damage from " + damage + " to " + actualDamage);
isDefending = false; setDefending(false);
} }
hp -= actualDamage; if (armor != null && !armor.isBroke()) {
if (hp < 0) {hp = 0;} 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 @Override
@@ -132,6 +147,10 @@ public abstract class Player implements Entity {
return armor; return armor;
} }
public boolean isDefending() {
return isDefending;
}
public void setHp(int hp) { public void setHp(int hp) {
this.hp = hp; this.hp = hp;
} }
@@ -139,4 +158,8 @@ public abstract class Player implements Entity {
public void setMp(int mp) { public void setMp(int mp) {
this.mp = 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; import org.project.item.weapons.Weapon;
public class Wizard extends Player implements Entity { public class Wizard extends Player implements Entity {
public Wizard (String name, int hp, int mp, Weapon weapon, Armor armor) { public Wizard (String name, Weapon weapon, Armor armor) {
super(name, hp, mp, weapon, armor); super(name, 60, 45, weapon, armor);
setMaxMP(45);
setMaxHP(60);
} }
} }
@@ -4,8 +4,4 @@ import org.project.entity.Entity;
public interface Item { public interface Item {
void use(Entity target); 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 maxDefense;
private int durability; private int durability;
private int maxDurability; private int maxDurability;
private boolean isBroke; public boolean isBroke;
public Armor(int defense, int durability) { public Armor(int defense, int durability) {
this.defense = defense; this.defense = defense;
@@ -18,13 +18,14 @@ public abstract class Armor implements Item {
this.isBroke = false; this.isBroke = false;
} }
public void checkBreak() { public boolean checkBreak() {
if (durability <= 0) { if (durability <= 0) {
isBroke = true; isBroke = true;
defense = 0; defense = 0;
durability = 0; durability = 0;
System.out.println("Armor is broken!"); System.out.println("Armor is broken!");
} }
return isBroke;
} }
public void repair() { public void repair() {
@@ -62,4 +63,8 @@ public abstract class Armor implements Item {
public boolean isBroke() { public boolean isBroke() {
return isBroke; return isBroke;
} }
public void setDefense(int defense) {
this.defense = defense;
}
} }