Compare commits
4
Commits
main
...
4f2320f632
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f2320f632 | ||
|
|
3804297a29 | ||
|
|
0b00500450 | ||
|
|
1316727c85 |
Generated
+5
@@ -16,5 +16,10 @@
|
|||||||
<option name="name" value="JBoss Community repository" />
|
<option name="name" value="JBoss Community repository" />
|
||||||
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
</remote-repository>
|
</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>
|
</component>
|
||||||
</project>
|
</project>
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.project.entity;
|
package org.project.entity;
|
||||||
|
|
||||||
public interface Entity {
|
public interface Entity {
|
||||||
|
|
||||||
void attack(Entity target);
|
void attack(Entity target);
|
||||||
|
|
||||||
void defend();
|
void defend();
|
||||||
@@ -14,8 +15,4 @@ public interface Entity {
|
|||||||
int getMaxHP();
|
int getMaxHP();
|
||||||
|
|
||||||
int getMaxMP();
|
int getMaxMP();
|
||||||
|
|
||||||
/*
|
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
package org.project.entity.enemies;
|
package org.project.entity.enemies;
|
||||||
|
|
||||||
|
import org.project.entity.Entity;
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
public abstract class Enemy implements Entity {
|
||||||
public abstract class Enemy {
|
|
||||||
Weapon weapon;
|
Weapon weapon;
|
||||||
private int hp;
|
private int hp;
|
||||||
private int mp;
|
private int mp;
|
||||||
|
private boolean isStunned = false;
|
||||||
|
private int stunTurns = 0;
|
||||||
|
|
||||||
public Enemy(int hp, int mp, Weapon weapon) {
|
public Enemy(int hp, int mp, Weapon weapon) {
|
||||||
this.hp = hp;
|
this.hp = hp;
|
||||||
@@ -20,6 +22,27 @@ public abstract class Enemy {
|
|||||||
hp -= damage;
|
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() {
|
public int getHp() {
|
||||||
return hp;
|
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;
|
package org.project.entity.players;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
import org.project.entity.Entity;
|
||||||
public class Knight {
|
import org.project.entity.enemies.Enemy;
|
||||||
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
|
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.armors.Armor;
|
||||||
import org.project.item.weapons.Weapon;
|
import org.project.item.weapons.Weapon;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
import java.util.ArrayList;
|
||||||
public abstract class Player {
|
|
||||||
|
|
||||||
|
public abstract class Player implements Entity {
|
||||||
protected String name;
|
protected String name;
|
||||||
Weapon weapon;
|
Weapon weapon;
|
||||||
Armor armor;
|
Armor armor;
|
||||||
@@ -13,6 +15,9 @@ public abstract class Player {
|
|||||||
private int maxHP;
|
private int maxHP;
|
||||||
private int mp;
|
private int mp;
|
||||||
private int maxMP;
|
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) {
|
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
@@ -30,17 +35,63 @@ public abstract class Player {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void defend() {
|
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
|
@Override
|
||||||
public void takeDamage(int damage) {
|
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
|
@Override
|
||||||
public void heal(int health) {
|
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;
|
hp += health;
|
||||||
if (hp > maxHP) {
|
if (hp > maxHP) {
|
||||||
hp = maxHP;
|
hp = maxHP;
|
||||||
@@ -49,12 +100,22 @@ public abstract class Player {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void fillMana(int mana) {
|
public void fillMana(int mana) {
|
||||||
|
int oldMana = mp;
|
||||||
|
mp += mana;
|
||||||
|
|
||||||
mp += mana;
|
mp += mana;
|
||||||
if (mp > maxMP) {
|
if (mp > maxMP) {
|
||||||
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() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
@@ -86,4 +147,19 @@ public abstract class Player {
|
|||||||
return armor;
|
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 {
|
public interface Item {
|
||||||
void use(Entity target);
|
void use(Entity target);
|
||||||
|
}
|
||||||
/*
|
|
||||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
@@ -1,31 +1,55 @@
|
|||||||
package org.project.item.armors;
|
package org.project.item.armors;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
import org.project.entity.Entity;
|
||||||
public abstract class Armor {
|
import org.project.item.Item;
|
||||||
|
|
||||||
|
public abstract class Armor implements Item {
|
||||||
private int defense;
|
private int defense;
|
||||||
private int maxDefense;
|
private int maxDefense;
|
||||||
private int durability;
|
private int durability;
|
||||||
private int maxDurability;
|
private int maxDurability;
|
||||||
|
public boolean isBroke;
|
||||||
private boolean isBroke;
|
|
||||||
|
|
||||||
public Armor(int defense, int durability) {
|
public Armor(int defense, int durability) {
|
||||||
this.defense = defense;
|
this.defense = defense;
|
||||||
this.durability = durability;
|
this.durability = durability;
|
||||||
|
this.maxDefense = defense;
|
||||||
|
this.maxDurability = durability;
|
||||||
|
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;
|
||||||
|
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 reduceDurability(int amount) {
|
||||||
public void repair() {
|
if (!isBroke) {
|
||||||
isBroke = false;
|
durability -= amount;
|
||||||
defense = maxDefense;
|
checkBreak();
|
||||||
durability = maxDurability;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void use(Entity target) {
|
||||||
|
System.out.println("🛡️ " + getClass().getSimpleName() + " equipped. Defense: " + defense);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getDefense() {
|
public int getDefense() {
|
||||||
@@ -39,4 +63,8 @@ public abstract class Armor {
|
|||||||
public boolean isBroke() {
|
public boolean isBroke() {
|
||||||
return 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;
|
package org.project.item.armors;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
//The knight's armor
|
||||||
public class KnightArmor {
|
public class KnightArmor extends Armor {
|
||||||
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
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;
|
package org.project.item.weapons;
|
||||||
|
|
||||||
import org.project.entity.Entity;
|
import org.project.entity.Entity;
|
||||||
|
import org.project.entity.enemies.Enemy;
|
||||||
|
import org.project.item.Item;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
//The knight's weapon
|
||||||
public class Sword {
|
public class Sword extends Weapon {
|
||||||
/*
|
private int abilityCharge;
|
||||||
THIS IS AN EXAMPLE OF A WEAPON DESIGN.
|
|
||||||
*/
|
|
||||||
|
|
||||||
int abilityCharge;
|
|
||||||
|
|
||||||
public Sword() {
|
public Sword() {
|
||||||
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
super(10, 8);
|
||||||
|
this.abilityCharge = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
|
//Bonus method
|
||||||
public void uniqueAbility(ArrayList<Entity> targets) {
|
public void uniqueAbility(Entity target) {
|
||||||
abilityCharge += 2;
|
abilityCharge += 2;
|
||||||
for (Entity target : targets) {
|
int totalDamage = getDamage() + (abilityCharge / 2);
|
||||||
target.takeDamage(getDamage());
|
|
||||||
|
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;
|
package org.project.item.weapons;
|
||||||
|
|
||||||
import org.project.entity.Entity;
|
import org.project.entity.Entity;
|
||||||
|
import org.project.item.Item;
|
||||||
|
|
||||||
// TODO: UPDATE IMPLEMENTATION
|
public abstract class Weapon implements Item {
|
||||||
public abstract class Weapon {
|
|
||||||
private int damage;
|
private int damage;
|
||||||
private int manaCost;
|
private int manaCost;
|
||||||
|
|
||||||
@@ -29,6 +29,14 @@ public abstract class Weapon {
|
|||||||
return manaCost;
|
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
|
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user