4 Commits
19 changed files with 314 additions and 46 deletions
+5
View File
@@ -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();
@@ -14,8 +15,4 @@ public interface Entity {
int getMaxHP();
int getMaxMP();
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
}
@@ -1,12 +1,14 @@
package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.item.weapons.Weapon;
// TODO: UPDATE IMPLEMENTATION
public abstract class Enemy {
public abstract class Enemy implements Entity {
Weapon weapon;
private int hp;
private int mp;
private boolean isStunned = false;
private int stunTurns = 0;
public Enemy(int hp, int mp, Weapon weapon) {
this.hp = hp;
@@ -20,6 +22,27 @@ public abstract class Enemy {
hp -= damage;
}
public void setStunned(boolean stunned) {
this.isStunned = stunned;
if (stunned) {
this.stunTurns = 1; //Stunned in one turn
}
}
//Decreasing the stunned turns
public void decrementStun() {
if (isStunned) {
stunTurns--;
if (stunTurns <= 0) {
isStunned = false;
}
}
}
public boolean isStunned() {
return isStunned;
}
public int getHp() {
return hp;
}
@@ -0,0 +1,11 @@
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, Weapon weapon, Armor armor) {
super(name, 45, 60, weapon, armor);
}
}
@@ -1,6 +1,36 @@
package org.project.entity.players;
// TODO: UPDATE IMPLEMENTATION
public class Knight {
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
import org.project.entity.Entity;
import org.project.entity.enemies.Enemy;
import org.project.item.armors.Armor;
import org.project.item.armors.KnightArmor;
import org.project.item.weapons.Sword;
import org.project.item.weapons.Weapon;
import java.util.ArrayList;
public class Knight extends Player {
public Knight(String name) {
super(name, 45, 45, new Sword(), new KnightArmor());
}
@Override
public void uniqueAbility(Entity target) {
//Checking if the mana is enough of not
if (getMp() < 15) {
System.out.println("Mana is not enough for Shield Bash!");
return;
}
//Consuming mana
setMp(getMp()-15);
//Stunning the enemies
if (getWeapon() instanceof Sword) {
((Sword) getWeapon()).uniqueAbility(target);
}
System.out.println("💥 Shield Bash! Enemy is stunned!");
}
}
@@ -4,8 +4,10 @@ import org.project.entity.Entity;
import org.project.item.armors.Armor;
import org.project.item.weapons.Weapon;
// TODO: UPDATE IMPLEMENTATION
public abstract class Player {
import java.util.ArrayList;
public abstract class Player implements Entity {
protected String name;
Weapon weapon;
Armor armor;
@@ -13,6 +15,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 +35,63 @@ 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);
setDefending(false);
}
if (armor != null && !armor.isBroke()) {
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
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,12 +100,22 @@ 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);
}
}
public abstract void uniqueAbility(Entity target);
public String getName() {
return name;
@@ -86,4 +147,19 @@ public abstract class Player {
return armor;
}
public boolean isDefending() {
return isDefending;
}
public void setHp(int hp) {
this.hp = hp;
}
public void setMp(int mp) {
this.mp = mp;
}
public void setDefending(boolean defending) {
isDefending = defending;
}
}
@@ -0,0 +1,11 @@
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, Weapon weapon, Armor armor) {
super(name, 60, 45, weapon, armor);
}
}
@@ -4,8 +4,4 @@ import org.project.entity.Entity;
public interface Item {
void use(Entity target);
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
}
}
@@ -1,31 +1,55 @@
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 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() {
public boolean checkBreak() {
if (durability <= 0) {
isBroke = true;
defense = 0;
durability = 0;
System.out.println("Armor is broken!");
}
return isBroke;
}
public void repair() {
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.");
}
}
// TODO: (BONUS) UPDATE THE REPAIR METHOD
public void repair() {
isBroke = false;
defense = maxDefense;
durability = maxDurability;
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() {
@@ -39,4 +63,8 @@ public abstract class Armor {
public boolean isBroke() {
return isBroke;
}
public void setDefense(int defense) {
this.defense = defense;
}
}
@@ -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);
}
}
@@ -0,0 +1,12 @@
package org.project.item.weapons;
import org.project.item.Item;
//The skeleton's weapon
public class BoneDagger extends Weapon implements Item {
int abilityCharge;
public BoneDagger(int damage, int manaCost) {
super(damage, manaCost);
}
}
@@ -0,0 +1,12 @@
package org.project.item.weapons;
import org.project.item.Item;
//The assassin's weapon
public class Dagger extends Weapon implements Item {
int abilityCharge;
public Dagger(int damage, int manaCost) {
super(damage, manaCost);
}
}
@@ -0,0 +1,12 @@
package org.project.item.weapons;
import org.project.item.Item;
//The vampire's weapon
public class Rapier extends Weapon implements Item {
int abilityCharge;
public Rapier(int damage, int manaCost) {
super(damage, manaCost);
}
}
@@ -1,26 +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;
// TODO: UPDATE IMPLEMENTATION
public class Sword {
/*
THIS IS AN EXAMPLE OF A WEAPON DESIGN.
*/
int abilityCharge;
//The knight's weapon
public class Sword extends Weapon {
private int abilityCharge;
public Sword() {
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
super(10, 8);
this.abilityCharge = 0;
}
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
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;
}
}
@@ -0,0 +1,12 @@
package org.project.item.weapons;
import org.project.item.Item;
//The goblin's weapon
public class ToothedHook extends Weapon implements Item {
int abilityCharge;
public ToothedHook(int damage, int manaCost) {
super(damage, manaCost);
}
}
@@ -0,0 +1,12 @@
package org.project.item.weapons;
import org.project.item.Item;
//The wizard's weapon
public class Wand extends Weapon implements Item {
int abilityCharge;
public Wand(int damage, int manaCost) {
super(damage, manaCost);
}
}
@@ -1,9 +1,9 @@
package org.project.item.weapons;
import org.project.entity.Entity;
import org.project.item.Item;
// TODO: UPDATE IMPLEMENTATION
public abstract class Weapon {
public abstract class Weapon implements Item {
private int damage;
private int manaCost;
@@ -29,6 +29,14 @@ public abstract class Weapon {
return manaCost;
}
public void setDamage(int damage) {
this.damage = damage;
}
public void setManaCost(int manaCost) {
this.manaCost = manaCost;
}
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/