Merge pull request 'Merge develop into main' (#1) from develop into main
Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package org.project;
|
||||
|
||||
public class Colors {
|
||||
|
||||
public static final String RESET = "\u001B[0m";
|
||||
|
||||
public static final String RED = "\u001B[31m";
|
||||
public static final String GREEN = "\u001B[32m";
|
||||
public static final String YELLOW = "\u001B[33m";
|
||||
public static final String RED_BRIGHT = "\u001B[91m";
|
||||
public static final String CYAN = "\u001B[36m";
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
package org.project;
|
||||
|
||||
import org.project.combat.*;
|
||||
import org.project.entity.enemies.*;
|
||||
import org.project.entity.players.*;
|
||||
import org.project.location.Location;
|
||||
import org.project.managers.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class GameLoop {
|
||||
|
||||
private final Scanner scanner = new Scanner(System.in);
|
||||
|
||||
private final ActionDecisionManager actionManager = new ActionDecisionManager();
|
||||
private final StatusEffectManager statusManager = new StatusEffectManager();
|
||||
private final SpecialAbilityManager abilityManager = new SpecialAbilityManager();
|
||||
private final ManaCostManager manaManager = new ManaCostManager();
|
||||
|
||||
private final TotalAttackCalculator attackCalculator =
|
||||
new TotalAttackCalculator(statusManager, abilityManager, manaManager);
|
||||
|
||||
private Player player;
|
||||
private Enemy currentEnemy;
|
||||
|
||||
private boolean gameRunning = true;
|
||||
|
||||
private boolean hasGoblinKey;
|
||||
private boolean hasSkeletonKey;
|
||||
private boolean hasVampireKey;
|
||||
|
||||
private Location currentLocation;
|
||||
private final List<Location> locations = new ArrayList<>();
|
||||
|
||||
|
||||
public GameLoop() {
|
||||
initializeLocations();
|
||||
}
|
||||
|
||||
private void initializeLocations() {
|
||||
|
||||
Location valhalla = new Location("Valhalla");
|
||||
Location elysium = new Location("Elysium");
|
||||
Location niflheim = new Location("Niflheim");
|
||||
Location castle = new Location("Castle");
|
||||
|
||||
valhalla.connect(elysium);
|
||||
valhalla.connect(niflheim);
|
||||
elysium.connect(niflheim);
|
||||
niflheim.connect(castle);
|
||||
|
||||
locations.add(valhalla);
|
||||
locations.add(elysium);
|
||||
locations.add(niflheim);
|
||||
locations.add(castle);
|
||||
|
||||
currentLocation = valhalla;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
|
||||
System.out.println("====== JAVA KNIGHT ======");
|
||||
|
||||
chooseClass();
|
||||
spawnEnemy();
|
||||
|
||||
while (gameRunning) {
|
||||
showMenu();
|
||||
}
|
||||
|
||||
System.out.println("Game Ended.");
|
||||
}
|
||||
|
||||
private void chooseClass() {
|
||||
|
||||
System.out.println("""
|
||||
Choose class:
|
||||
1. Knight (HP:150 MP:80 DMG:12)
|
||||
2. Wizard (HP:80 MP:200 DMG:10)
|
||||
3. Assassin (HP:90 MP:120 DMG:15)
|
||||
""");
|
||||
|
||||
int choice = scanner.nextInt();
|
||||
|
||||
switch (choice) {
|
||||
case 2 -> player = new Wizard("Merlin");
|
||||
case 3 -> player = new Assassin("Shadow");
|
||||
default -> player = new Knight("Sir Duncan");
|
||||
}
|
||||
}
|
||||
|
||||
private void showMenu() {
|
||||
|
||||
System.out.println("====" + Colors.YELLOW + " GAME MENU " + Colors.RESET + "====");
|
||||
System.out.println("Location: " + currentLocation.getName());
|
||||
|
||||
if (currentEnemy != null)
|
||||
System.out.println("Enemy: " + currentEnemy);
|
||||
|
||||
System.out.println("""
|
||||
\n1. Fight
|
||||
2. Inventory
|
||||
3. Move
|
||||
0. Exit
|
||||
""");
|
||||
|
||||
if (hasAllKeys())
|
||||
System.out.println("4. Fight Dragon");
|
||||
|
||||
int choice = scanner.nextInt();
|
||||
|
||||
switch (choice) {
|
||||
case 1 -> startCombat();
|
||||
case 2 -> new InventoryManager().displayInventory(player);
|
||||
case 3 -> move();
|
||||
case 4 -> {
|
||||
if (hasAllKeys())
|
||||
fightDragon();
|
||||
}
|
||||
case 0 -> gameRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void move() {
|
||||
|
||||
List<Location> connected = currentLocation.getConnectedLocations();
|
||||
|
||||
if (connected.isEmpty()) {
|
||||
System.out.println("No paths from here.");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("Choose destination:");
|
||||
|
||||
for (int i = 0; i < connected.size(); i++)
|
||||
System.out.println((i + 1) + ". " + connected.get(i).getName());
|
||||
|
||||
int choice = scanner.nextInt();
|
||||
|
||||
if (choice < 1 || choice > connected.size())
|
||||
return;
|
||||
|
||||
currentLocation = connected.get(choice - 1);
|
||||
|
||||
spawnEnemy();
|
||||
}
|
||||
|
||||
private void spawnEnemy() {
|
||||
|
||||
Enemy[] enemies = {
|
||||
new Goblin(),
|
||||
new Skeleton(),
|
||||
new Vampire()
|
||||
};
|
||||
|
||||
currentEnemy = enemies[(int) (Math.random() * enemies.length)];
|
||||
}
|
||||
|
||||
private void startCombat() {
|
||||
|
||||
if (currentEnemy == null) {
|
||||
System.out.println("No enemy here.");
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println(Colors.RED_BRIGHT + "⚔ COMBAT STARTED! ⚔" + Colors.RESET);
|
||||
|
||||
|
||||
while (player.isLive() && currentEnemy.isLive()) {
|
||||
|
||||
statusManager.tick(player);
|
||||
statusManager.tick(currentEnemy);
|
||||
|
||||
abilityManager.tick(currentEnemy, player);
|
||||
abilityManager.tick(player, currentEnemy);
|
||||
|
||||
if (!player.isLive() || !currentEnemy.isLive())
|
||||
break;
|
||||
|
||||
playerTurn();
|
||||
currentEnemy.resetTurnState();
|
||||
|
||||
if (currentEnemy.isLive())
|
||||
enemyTurn();
|
||||
player.resetTurnState();
|
||||
}
|
||||
|
||||
if (player.isLive())
|
||||
victory();
|
||||
else
|
||||
gameRunning = false;
|
||||
}
|
||||
|
||||
|
||||
private void playerTurn() {
|
||||
System.out.println("====" + Colors.YELLOW + " YOUR TURN " + Colors.RESET + "====");
|
||||
System.out.println(player.getName() + "-> HP: " + player.getHp() + " | MP: " + player.getMp() + " | level: " + player.getLevel() + " | XP: " + player.getXp());
|
||||
System.out.println(currentEnemy.getName() + "-> HP: " + currentEnemy.getHp() + " | MP: " + currentEnemy.getMp());
|
||||
System.out.println("\n");
|
||||
var action = actionManager.userChooseAction();
|
||||
|
||||
AttackResult result = attackCalculator.calculate(player, currentEnemy, action);
|
||||
|
||||
int totalDamage = result.getDamageToTarget();
|
||||
int healAmount = result.getHealSelf();
|
||||
boolean isDefend = result.isDefended();
|
||||
|
||||
if (totalDamage > 0) {
|
||||
System.out.println(currentEnemy.getName() + " got " + totalDamage + " damage");
|
||||
currentEnemy.takeDamage(totalDamage);
|
||||
}
|
||||
|
||||
if (healAmount > 0) {
|
||||
player.heal(healAmount);
|
||||
if (player.getHp() < player.getMaxHP())
|
||||
System.out.println(player.getName() + "healed " + healAmount + " HP");
|
||||
}
|
||||
|
||||
if (isDefend) {
|
||||
player.defend();
|
||||
System.out.println(player.getName() + " will defend (50% damage)");
|
||||
}
|
||||
System.out.println("\n");
|
||||
}
|
||||
|
||||
private void enemyTurn() {
|
||||
System.out.println("====" + Colors.YELLOW + " ENEMY TURN " + Colors.RESET + "====\n");
|
||||
var action = actionManager.botChooseAction();
|
||||
|
||||
System.out.println("enemy random choose action: " + Colors.RED + action + Colors.RESET);
|
||||
|
||||
AttackResult result = attackCalculator.calculate(currentEnemy, player, action);
|
||||
|
||||
int totalDamage = result.getDamageToTarget();
|
||||
int healAmount = result.getHealSelf();
|
||||
boolean isDefend = result.isDefended();
|
||||
|
||||
|
||||
if (totalDamage > 0) {
|
||||
System.out.println(player.getName() + " got " + totalDamage + " damage");
|
||||
player.takeDamage(totalDamage);
|
||||
}
|
||||
|
||||
if (healAmount > 0) {
|
||||
currentEnemy.heal(healAmount);
|
||||
if (currentEnemy.getHp() < currentEnemy.getMaxHP())
|
||||
System.out.println(currentEnemy.getName() + " healed " + healAmount + " HP");
|
||||
|
||||
}
|
||||
|
||||
if (isDefend) {
|
||||
currentEnemy.defend();
|
||||
System.out.println(currentEnemy.getName() + " will defend (50% damage)");
|
||||
}
|
||||
|
||||
|
||||
System.out.println("\n");
|
||||
|
||||
}
|
||||
|
||||
private void victory() {
|
||||
|
||||
System.out.println(Colors.GREEN + "Victory!" + Colors.RESET);
|
||||
|
||||
currentEnemy.rewardXp(player);
|
||||
|
||||
checkKeyDrop();
|
||||
|
||||
player.restore();
|
||||
|
||||
currentEnemy = null;
|
||||
}
|
||||
|
||||
private void checkKeyDrop() {
|
||||
|
||||
if (Math.random() * 100 > 20)
|
||||
return;
|
||||
|
||||
if (currentEnemy instanceof Goblin && !hasGoblinKey) {
|
||||
hasGoblinKey = true;
|
||||
System.out.println("Goblin Key obtained!");
|
||||
}
|
||||
|
||||
else if (currentEnemy instanceof Skeleton && ! hasSkeletonKey) {
|
||||
hasSkeletonKey = true;
|
||||
System.out.println("Skeleton Key obtained!");
|
||||
}
|
||||
|
||||
else if (currentEnemy instanceof Vampire && !hasVampireKey) {
|
||||
hasVampireKey = true;
|
||||
System.out.println("Vampire Key obtained!");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasAllKeys() {
|
||||
return hasGoblinKey && hasSkeletonKey && hasVampireKey;
|
||||
}
|
||||
|
||||
private void fightDragon() {
|
||||
|
||||
currentEnemy = new Dragon();
|
||||
|
||||
System.out.println("The Dragon Appears!");
|
||||
|
||||
startCombat();
|
||||
|
||||
if (player.isLive())
|
||||
System.out.println("YOU SAVED JAVANEST!");
|
||||
else
|
||||
System.out.println("The Dragon has defeated you...");
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,11 @@
|
||||
package org.project;
|
||||
|
||||
import org.project.location.Location;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
// TODO: ADD LOCATIONS TO YOUR GAME
|
||||
List<Location> locations = new ArrayList<>();
|
||||
|
||||
// TODO: IMPLEMENT GAMEPLAY
|
||||
GameLoop game = new GameLoop();
|
||||
|
||||
game.start();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.project.abilities;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
|
||||
public class ArcaneStorm extends SpecialAbility{
|
||||
|
||||
/*
|
||||
Wizard use this special ability
|
||||
it Becomes invisible
|
||||
no longer gets damage
|
||||
*/
|
||||
|
||||
public ArcaneStorm() {
|
||||
super("ArcaneStorm",25, 3, AbilityTarget.TARGET);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onApply(Entity target) {
|
||||
super.onApply(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick(Entity target) {
|
||||
target.freeze();
|
||||
System.out.println(target.getName() + " is steel Frozen!");
|
||||
reduceDuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExpire(Entity self) {
|
||||
System.out.println(self.getName() + "'s special ability onExpired");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package org.project.abilities;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
|
||||
public class BoneStrike extends SpecialAbility{
|
||||
|
||||
/*
|
||||
Skeleton use this special ability
|
||||
its throws bones and damage enemies
|
||||
*/
|
||||
|
||||
private final int damage = 5;
|
||||
|
||||
public BoneStrike() {
|
||||
super("BoneThrow",10, 3, AbilityTarget.TARGET);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onApply(Entity target) {
|
||||
super.onApply(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick(Entity target) {
|
||||
target.takeDamage(damage);
|
||||
System.out.println(target.getName() + " suffers from " + getName());
|
||||
reduceDuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExpire(Entity self) {
|
||||
System.out.println(self.getName() + "'s special ability onExpired");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.project.abilities;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
|
||||
public class GuardianOath extends SpecialAbility{
|
||||
|
||||
/*
|
||||
|
||||
Knight use this special ability
|
||||
The first damage and the knight is completely restrained
|
||||
its gains some health
|
||||
|
||||
*/
|
||||
|
||||
public GuardianOath() {
|
||||
super("GuardianOath",15, 1, AbilityTarget.SELF);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onApply(Entity target) {
|
||||
super.onApply(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick(Entity self) {
|
||||
|
||||
self.heal(5);
|
||||
self.defend();
|
||||
System.out.println("Guardian Oath empowers Sir Duncan: +5 HP and 50% Decreased damage.\n ");
|
||||
reduceDuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExpire(Entity self) {
|
||||
System.out.println(self.getName() + "'s special ability onExpired");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.project.abilities;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
|
||||
public class InfernoBreath extends SpecialAbility{
|
||||
|
||||
/*
|
||||
|
||||
Dragon use this special ability
|
||||
its fiery breath deals huge damage to the enemy
|
||||
|
||||
*/
|
||||
|
||||
private final int breathDamage = 20;
|
||||
|
||||
public InfernoBreath() {
|
||||
super("InfernoBreath",25, 1,AbilityTarget.TARGET);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onApply(Entity target) {
|
||||
super.onApply(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick(Entity target) {
|
||||
target.takeDamage(breathDamage);
|
||||
System.out.println("ooooh! " + getName() + " impacted with " + target.getName());
|
||||
reduceDuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExpire(Entity self) {
|
||||
super.onExpire(self);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.project.abilities;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
|
||||
public class LifeSteal extends SpecialAbility{
|
||||
|
||||
/*
|
||||
|
||||
vampire use this special ability
|
||||
its bite's the enemy's nek
|
||||
|
||||
|
||||
*/
|
||||
|
||||
private final int healAmount = 15;
|
||||
|
||||
public LifeSteal() {
|
||||
|
||||
super("SuckingBlood",15, 1,AbilityTarget.SELF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApply(Entity target) {
|
||||
super.onApply(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick(Entity self) {
|
||||
self.heal(healAmount);
|
||||
System.out.println(self.getName() + " healed for " + healAmount + " (LifeSteal)");
|
||||
reduceDuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExpire(Entity self) {
|
||||
System.out.println(self.getName() + "'s special ability onExpired");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.project.abilities;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.Dagger;
|
||||
import org.project.weaponEffects.PoisonEffect;
|
||||
import org.w3c.dom.ls.LSOutput;
|
||||
|
||||
public class PoisonDagger extends SpecialAbility{
|
||||
|
||||
/*
|
||||
|
||||
Goblin use this special ability
|
||||
applies poison effect on goblin's weapon
|
||||
|
||||
*/
|
||||
|
||||
private final int poisonDamage = 5;
|
||||
|
||||
public PoisonDagger() {
|
||||
|
||||
super("poisonDagger",15,3,AbilityTarget.SELF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApply(Entity target) {
|
||||
super.onApply(target);
|
||||
target.setWeapon(new Dagger(new PoisonEffect()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick(Entity self) {
|
||||
|
||||
System.out.println(self.getName() + " used Poisonous Dagger ");
|
||||
reduceDuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExpire(Entity target) {
|
||||
target.setWeapon(new Dagger());
|
||||
System.out.println(target.getName() + " no longer has poisonous Dagger");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package org.project.abilities;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
|
||||
public abstract class SpecialAbility {
|
||||
|
||||
public enum AbilityTarget {
|
||||
SELF,
|
||||
TARGET
|
||||
}
|
||||
|
||||
protected String name;
|
||||
protected int manaCost;
|
||||
protected int duration;
|
||||
private final AbilityTarget target;
|
||||
|
||||
public SpecialAbility(String name,int manaCost, int duration, AbilityTarget target) {
|
||||
|
||||
this.name = name;
|
||||
this.manaCost = manaCost;
|
||||
this.duration = duration;
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
public AbilityTarget getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getManaCost() {return manaCost;}
|
||||
|
||||
public int getDuration() {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public void reduceDuration() {duration--;}
|
||||
|
||||
public void onApply(Entity target) {System.out.println(target.getName() + " activated " + name);}
|
||||
|
||||
public abstract void onTick(Entity target);
|
||||
|
||||
public void onExpire(Entity target) {}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.project.combat;
|
||||
|
||||
public class AttackResult {
|
||||
|
||||
private int damageToTarget;
|
||||
private int healSelf;
|
||||
private boolean defended;
|
||||
|
||||
public AttackResult(int damageToTarget, int healSelf, boolean defended) {
|
||||
this.damageToTarget = damageToTarget;
|
||||
this.healSelf = healSelf;
|
||||
this.defended = defended;
|
||||
}
|
||||
|
||||
public int getDamageToTarget() { return damageToTarget; }
|
||||
public int getHealSelf() { return healSelf; }
|
||||
public boolean isDefended() { return defended; }
|
||||
}
|
||||
@@ -0,0 +1,198 @@
|
||||
package org.project.combat;
|
||||
|
||||
import org.project.abilities.SpecialAbility;
|
||||
import org.project.entity.Entity;
|
||||
import org.project.entity.players.Player;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.weapons.Weapon;
|
||||
import org.project.managers.ActionDecisionManager;
|
||||
import org.project.managers.ManaCostManager;
|
||||
import org.project.managers.SpecialAbilityManager;
|
||||
import org.project.managers.StatusEffectManager;
|
||||
|
||||
public class TotalAttackCalculator {
|
||||
|
||||
private final StatusEffectManager statusEffectManager;
|
||||
private final SpecialAbilityManager specialAbilityManager;
|
||||
private final ManaCostManager manaCostManager;
|
||||
|
||||
private static final int HEAL_AMOUNT = 25;
|
||||
private static final int SHIELD_BASH_BASE_DAMAGE = 15;
|
||||
private static final int SHIELD_BASH_STUN_CHANCE = 30;
|
||||
|
||||
public TotalAttackCalculator(
|
||||
StatusEffectManager statusEffectManager,
|
||||
SpecialAbilityManager specialAbilityManager,
|
||||
ManaCostManager manaCostManager
|
||||
) {
|
||||
this.statusEffectManager = statusEffectManager;
|
||||
this.specialAbilityManager = specialAbilityManager;
|
||||
this.manaCostManager = manaCostManager;
|
||||
}
|
||||
|
||||
public AttackResult calculate(
|
||||
Entity attacker,
|
||||
Entity defender,
|
||||
ActionDecisionManager.actionsType action
|
||||
) {
|
||||
|
||||
switch (action) {
|
||||
|
||||
case lightAttack:
|
||||
return lightAttack(attacker, defender);
|
||||
|
||||
case heavyAttack:
|
||||
return heavyAttack(attacker, defender);
|
||||
|
||||
case defend:
|
||||
return defend(attacker);
|
||||
|
||||
case heal:
|
||||
return heal(attacker);
|
||||
|
||||
case ability:
|
||||
return ability(attacker, defender);
|
||||
|
||||
case shiedbash:
|
||||
return shieldBash(attacker, defender);
|
||||
}
|
||||
|
||||
return new AttackResult(0,0,false);
|
||||
}
|
||||
|
||||
// --------------------------------
|
||||
// LIGHT ATTACK
|
||||
// --------------------------------
|
||||
private AttackResult lightAttack(Entity attacker, Entity defender) {
|
||||
|
||||
int damage = attacker.getBaseDamage();
|
||||
|
||||
Weapon weapon = attacker.getWeapon();
|
||||
|
||||
if (weapon != null) {
|
||||
damage += weapon.getLightAttackDamage();
|
||||
|
||||
if (weapon.getEffect() != null)
|
||||
statusEffectManager.addEffect(weapon.getEffect(), defender);
|
||||
}
|
||||
|
||||
damage = applyArmor(defender, damage);
|
||||
|
||||
if (defender.isDefending())
|
||||
damage /= 2;
|
||||
|
||||
return new AttackResult(damage,0,false);
|
||||
}
|
||||
|
||||
// --------------------------------
|
||||
// HEAVY ATTACK
|
||||
// --------------------------------
|
||||
private AttackResult heavyAttack(Entity attacker, Entity defender) {
|
||||
|
||||
if (!manaCostManager.useHeavyAttack( attacker))
|
||||
return new AttackResult(0,0,false);
|
||||
|
||||
int damage = attacker.getBaseDamage() * 2;
|
||||
|
||||
Weapon weapon = attacker.getWeapon();
|
||||
|
||||
if (weapon != null) {
|
||||
|
||||
damage += weapon.getHeavyAttackDamage();
|
||||
|
||||
if (weapon.getEffect() != null)
|
||||
statusEffectManager.addEffect(weapon.getEffect(), defender);
|
||||
}
|
||||
|
||||
damage = applyArmor(defender, damage);
|
||||
|
||||
if (defender.isDefending())
|
||||
damage /= 2;
|
||||
|
||||
return new AttackResult(damage,0,false);
|
||||
}
|
||||
|
||||
// --------------------------------
|
||||
// DEFEND
|
||||
// --------------------------------
|
||||
private AttackResult defend(Entity attacker) {
|
||||
|
||||
if (!manaCostManager.useHeavyAttack( attacker))
|
||||
return new AttackResult(0,0,false);
|
||||
|
||||
return new AttackResult(0,0,true);
|
||||
}
|
||||
|
||||
// --------------------------------
|
||||
// HEAL
|
||||
// --------------------------------
|
||||
private AttackResult heal(Entity attacker) {
|
||||
|
||||
if (!manaCostManager.useHeavyAttack( attacker))
|
||||
return new AttackResult(0,0,false);
|
||||
|
||||
return new AttackResult(0,HEAL_AMOUNT,false);
|
||||
}
|
||||
|
||||
// --------------------------------
|
||||
// SPECIAL ABILITY
|
||||
// --------------------------------
|
||||
private AttackResult ability(Entity attacker, Entity defender) {
|
||||
|
||||
SpecialAbility ability = attacker.getSpacialAbility();
|
||||
|
||||
if (ability == null)
|
||||
return new AttackResult(0,0,false);
|
||||
|
||||
if (attacker instanceof Player && !manaCostManager.useSpecialAbility((Player) attacker))
|
||||
return new AttackResult(0,0,false);
|
||||
|
||||
Entity target =
|
||||
ability.getTarget() == SpecialAbility.AbilityTarget.SELF
|
||||
? attacker
|
||||
: defender;
|
||||
|
||||
specialAbilityManager.addAbility(ability, target);
|
||||
|
||||
return new AttackResult(0,0,false);
|
||||
}
|
||||
|
||||
// --------------------------------
|
||||
// SHIELD BASH
|
||||
// --------------------------------
|
||||
private AttackResult shieldBash(Entity attacker, Entity defender) {
|
||||
|
||||
if (!manaCostManager.useHeavyAttack( attacker))
|
||||
return new AttackResult(0,0,false);
|
||||
|
||||
Armor armor = attacker.getArmor();
|
||||
|
||||
if (armor == null)
|
||||
return new AttackResult(0,0,false);
|
||||
|
||||
if (armor.getType() != Armor.ArmorType.HEAVY)
|
||||
return new AttackResult(0,0,false);
|
||||
|
||||
int damage = SHIELD_BASH_BASE_DAMAGE + armor.getDefense() / 2;
|
||||
|
||||
damage = applyArmor(defender, damage);
|
||||
|
||||
if (Math.random() * 100 < SHIELD_BASH_STUN_CHANCE)
|
||||
defender.stun();
|
||||
|
||||
return new AttackResult(damage,0,false);
|
||||
}
|
||||
|
||||
// --------------------------------
|
||||
// ARMOR REDUCTION
|
||||
// --------------------------------
|
||||
private int applyArmor(Entity defender, int rawDamage) {
|
||||
|
||||
Armor armor = defender.getArmor();
|
||||
|
||||
if (armor == null)
|
||||
return rawDamage;
|
||||
|
||||
return armor.reduceDamage(rawDamage);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,90 @@
|
||||
package org.project.entity;
|
||||
|
||||
import org.project.abilities.SpecialAbility;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.weapons.Weapon;
|
||||
import org.project.managers.StatusEffectManager;
|
||||
import org.project.weaponEffects.StatusEffect;
|
||||
|
||||
public interface Entity {
|
||||
void attack(Entity target);
|
||||
|
||||
// =========================================================
|
||||
// IDENTITY
|
||||
// =========================================================
|
||||
|
||||
String getName();
|
||||
|
||||
// =========================================================
|
||||
// STATS
|
||||
// =========================================================
|
||||
|
||||
int getHp();
|
||||
int getMp();
|
||||
int getMaxHP();
|
||||
int getMaxMP();
|
||||
void useMana(int amount);
|
||||
|
||||
int getBaseDamage();
|
||||
|
||||
// =========================================================
|
||||
// EQUIPMENT
|
||||
// =========================================================
|
||||
|
||||
Weapon getWeapon();
|
||||
Armor getArmor();
|
||||
|
||||
void setWeapon(Weapon weapon);
|
||||
void setArmor(Armor armor);
|
||||
|
||||
Armor getPersonalArmor();
|
||||
|
||||
// =========================================================
|
||||
// ABILITIES
|
||||
// =========================================================
|
||||
|
||||
SpecialAbility getSpacialAbility();
|
||||
|
||||
void addAbilityEffect(SpecialAbility ability, Entity target);
|
||||
void tickAbilityEffects(Entity target);
|
||||
|
||||
// =========================================================
|
||||
// STATUS EFFECTS
|
||||
// =========================================================
|
||||
|
||||
void heal(int amount);
|
||||
void freeze();
|
||||
void stun();
|
||||
void addStatusEffect(StatusEffect effect);
|
||||
void tickStatusEffects();
|
||||
StatusEffectManager getEffectManager();
|
||||
|
||||
// // =========================================================
|
||||
// // RESOURCE MANAGEMENT
|
||||
// // =========================================================
|
||||
//
|
||||
// void useMana(int amount);
|
||||
|
||||
// =========================================================
|
||||
// COMBAT
|
||||
// =========================================================
|
||||
|
||||
void takeDamage(int amount);
|
||||
|
||||
// =========================================================
|
||||
// STATES
|
||||
// =========================================================
|
||||
|
||||
void defend();
|
||||
boolean isDefending();
|
||||
boolean isFrozen();
|
||||
boolean isStunned();
|
||||
void resetTurnState();
|
||||
|
||||
void heal(int health);
|
||||
|
||||
void fillMana(int mana);
|
||||
// =========================================================
|
||||
// INTERNAL SETTERS
|
||||
// =========================================================
|
||||
|
||||
void takeDamage(int damage);
|
||||
|
||||
int getMaxHP();
|
||||
|
||||
int getMaxMP();
|
||||
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
void setHp(int value);
|
||||
void setMp(int value);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.abilities.InfernoBreath;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.armors.DragonArmor;
|
||||
import org.project.item.weapons.Sword;
|
||||
|
||||
public class Dragon extends Enemy {
|
||||
|
||||
private static final String NAME = "Dragon";
|
||||
private static final int MAX_HP = 300;
|
||||
private static final int MAX_MP = 150;
|
||||
private static final int XP_REWARD = 500;
|
||||
private static final int BASE_DAMAGE = 30;
|
||||
|
||||
private final Armor personalArmor = new DragonArmor();
|
||||
|
||||
public Dragon() {
|
||||
|
||||
super(
|
||||
NAME,
|
||||
MAX_HP,
|
||||
MAX_MP,
|
||||
XP_REWARD,
|
||||
BASE_DAMAGE,
|
||||
null,
|
||||
new Sword(),
|
||||
new InfernoBreath()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Armor getPersonalArmor() {
|
||||
return personalArmor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Dragon{" +
|
||||
"MAX_HP : 300 | " +
|
||||
"MAX_MP : 150 | " +
|
||||
"XP_REWARD : 500 | " +
|
||||
"BASE_DAMAGE : 30 | " +
|
||||
"personalArmor = " + personalArmor +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,322 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.abilities.SpecialAbility;
|
||||
import org.project.entity.Entity;
|
||||
import org.project.entity.players.Player;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.weapons.Weapon;
|
||||
import org.project.managers.SpecialAbilityManager;
|
||||
import org.project.managers.StatusEffectManager;
|
||||
import org.project.weaponEffects.StatusEffect;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Enemy {
|
||||
Weapon weapon;
|
||||
public abstract class Enemy implements Entity {
|
||||
|
||||
// =========================================================
|
||||
// BASIC INFO
|
||||
// =========================================================
|
||||
|
||||
private final String name;
|
||||
|
||||
// =========================================================
|
||||
// STATS
|
||||
// =========================================================
|
||||
|
||||
private int xpReward;
|
||||
|
||||
private int maxHp;
|
||||
private int hp;
|
||||
|
||||
private int maxMp;
|
||||
private int mp;
|
||||
|
||||
public Enemy(int hp, int mp, Weapon weapon) {
|
||||
this.hp = hp;
|
||||
this.mp = mp;
|
||||
private int baseDamage;
|
||||
|
||||
// =========================================================
|
||||
// EQUIPMENT
|
||||
// =========================================================
|
||||
|
||||
private Armor armor;
|
||||
private Weapon weapon;
|
||||
|
||||
// =========================================================
|
||||
// ABILITIES
|
||||
// =========================================================
|
||||
|
||||
private final SpecialAbility specialAbility;
|
||||
|
||||
private final StatusEffectManager effectManager;
|
||||
private final SpecialAbilityManager abilityManager;
|
||||
|
||||
// =========================================================
|
||||
// STATES
|
||||
// =========================================================
|
||||
|
||||
private boolean defending;
|
||||
private boolean frozen;
|
||||
private boolean stunned;
|
||||
private boolean live;
|
||||
|
||||
// =========================================================
|
||||
// CONSTRUCTOR
|
||||
// =========================================================
|
||||
|
||||
public Enemy(
|
||||
String name,
|
||||
int maxHp,
|
||||
int maxMp,
|
||||
int xpReward,
|
||||
int baseDamage,
|
||||
Armor armor,
|
||||
Weapon weapon,
|
||||
SpecialAbility specialAbility
|
||||
) {
|
||||
|
||||
this.name = name;
|
||||
|
||||
this.maxHp = maxHp;
|
||||
this.hp = maxHp;
|
||||
|
||||
this.maxMp = maxMp;
|
||||
this.mp = maxMp;
|
||||
|
||||
this.xpReward = xpReward;
|
||||
|
||||
this.baseDamage = baseDamage;
|
||||
|
||||
this.armor = armor;
|
||||
this.weapon = weapon;
|
||||
|
||||
this.specialAbility = specialAbility;
|
||||
|
||||
this.effectManager = new StatusEffectManager();
|
||||
this.abilityManager = new SpecialAbilityManager();
|
||||
this.live = true;
|
||||
}
|
||||
|
||||
// =========================================================
|
||||
// XP REWARD
|
||||
// =========================================================
|
||||
|
||||
public void rewardXp(Player player) {
|
||||
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.gainXp(xpReward);
|
||||
|
||||
System.out.println(
|
||||
player.getName() +
|
||||
" gained " +
|
||||
xpReward +
|
||||
" XP from defeating " +
|
||||
name
|
||||
);
|
||||
}
|
||||
|
||||
// =========================================================
|
||||
// STATUS EFFECTS
|
||||
// =========================================================
|
||||
|
||||
@Override
|
||||
public void addStatusEffect(StatusEffect effect) {
|
||||
effectManager.addEffect(effect, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
hp -= damage;
|
||||
public void tickStatusEffects() {
|
||||
effectManager.tick(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatusEffectManager getEffectManager() {
|
||||
return effectManager;
|
||||
}
|
||||
|
||||
// =========================================================
|
||||
// ABILITIES
|
||||
// =========================================================
|
||||
|
||||
@Override
|
||||
public void addAbilityEffect(SpecialAbility ability, Entity target) {
|
||||
abilityManager.addAbility(ability, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tickAbilityEffects(Entity target) {
|
||||
abilityManager.tick(this, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpecialAbility getSpacialAbility() {
|
||||
return specialAbility;
|
||||
}
|
||||
|
||||
// =========================================================
|
||||
// COMBAT
|
||||
// =========================================================
|
||||
|
||||
@Override
|
||||
public void takeDamage(int amount) {
|
||||
|
||||
int finalDamage = Math.max(0, amount);
|
||||
|
||||
hp -= finalDamage;
|
||||
if (hp <= 0) {
|
||||
hp = 0;
|
||||
live = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int amount) {
|
||||
|
||||
if (!live) {
|
||||
return;
|
||||
}
|
||||
|
||||
hp += amount;
|
||||
if (hp > maxHp) {
|
||||
hp = maxHp;
|
||||
System.out.println("HP reached maximum amount " + maxHp);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void useMana(int amount) {
|
||||
|
||||
if (amount <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mp < amount) {
|
||||
|
||||
System.out.println(name + " doesn't have enough mana!");
|
||||
return;
|
||||
}
|
||||
|
||||
mp -= amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
defending = true;
|
||||
}
|
||||
|
||||
|
||||
// =========================================================
|
||||
// STATES
|
||||
// =========================================================
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isDefending() {
|
||||
return defending;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFrozen() {
|
||||
return frozen;
|
||||
}
|
||||
|
||||
public boolean isStunned() {return stunned;}
|
||||
|
||||
@Override
|
||||
public void freeze() {
|
||||
frozen = true;
|
||||
}
|
||||
|
||||
public void stun() {
|
||||
stunned = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetTurnState() {
|
||||
|
||||
defending = false;
|
||||
frozen = false;
|
||||
stunned = false;
|
||||
}
|
||||
|
||||
// =========================================================
|
||||
// GETTERS
|
||||
// =========================================================
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHp() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMp() {
|
||||
return mp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHP() {
|
||||
return maxHp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxMP() {
|
||||
return maxMp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getBaseDamage() {
|
||||
return baseDamage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Weapon getWeapon() {
|
||||
return weapon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Armor getArmor() {
|
||||
return armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Armor getPersonalArmor() {
|
||||
return armor;
|
||||
}
|
||||
|
||||
public boolean isLive() {
|
||||
return live;
|
||||
}
|
||||
|
||||
public int getXpReward() {
|
||||
return xpReward;
|
||||
}
|
||||
|
||||
// =========================================================
|
||||
// SETTERS
|
||||
// =========================================================
|
||||
|
||||
@Override
|
||||
public void setWeapon(Weapon weapon) {
|
||||
this.weapon = weapon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setArmor(Armor armor) {
|
||||
this.armor = armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHp(int value) {
|
||||
hp = Math.max(0, Math.min(value, maxHp));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMp(int value) {
|
||||
mp = Math.max(0, Math.min(value, maxMp));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.abilities.PoisonDagger;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.armors.GoblinArmor;
|
||||
import org.project.item.weapons.Dagger;
|
||||
|
||||
public class Goblin extends Enemy {
|
||||
|
||||
private static final String NAME = "Goblin";
|
||||
private static final int MAX_HP = 45;
|
||||
private static final int MAX_MP = 50;
|
||||
private static final int XP_REWARD = 30;
|
||||
private static final int BASE_DAMAGE = 5;
|
||||
|
||||
private final Armor personalArmor = new GoblinArmor();
|
||||
|
||||
public Goblin() {
|
||||
|
||||
super(
|
||||
NAME,
|
||||
MAX_HP,
|
||||
MAX_MP,
|
||||
XP_REWARD,
|
||||
BASE_DAMAGE,
|
||||
null,
|
||||
new Dagger(),
|
||||
new PoisonDagger()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Armor getPersonalArmor() {
|
||||
return personalArmor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Goblin{" +
|
||||
"MAX_HP : 45 | " +
|
||||
"MAX_MP : 50 | " +
|
||||
"XP_REWARD : 30 | " +
|
||||
"BASE_DAMAGE : 5 | " +
|
||||
"personalArmor = " + personalArmor +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,47 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Skeleton {
|
||||
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
|
||||
import org.project.abilities.BoneStrike;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.armors.SkeletonArmor;
|
||||
import org.project.item.weapons.Sword;
|
||||
|
||||
public class Skeleton extends Enemy {
|
||||
|
||||
private static final String NAME = "Skeleton";
|
||||
private static final int MAX_HP = 40;
|
||||
private static final int MAX_MP = 30;
|
||||
private static final int XP_REWARD = 25;
|
||||
private static final int BASE_DAMAGE = 7;
|
||||
|
||||
private final Armor personalArmor = new SkeletonArmor();
|
||||
|
||||
public Skeleton() {
|
||||
|
||||
super(
|
||||
NAME,
|
||||
MAX_HP,
|
||||
MAX_MP,
|
||||
XP_REWARD,
|
||||
BASE_DAMAGE,
|
||||
null,
|
||||
new Sword(),
|
||||
new BoneStrike()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Armor getPersonalArmor() {
|
||||
return personalArmor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Skeleton{" +
|
||||
"MAX_HP : 40 | " +
|
||||
"MAX_MP : 30 | " +
|
||||
"XP_REWARD : 25 | " +
|
||||
"BASE_DAMAGE : 7 | " +
|
||||
"personalArmor = " + personalArmor +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.abilities.LifeSteal;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.armors.VampireArmor;
|
||||
import org.project.item.weapons.Dagger;
|
||||
|
||||
public class Vampire extends Enemy {
|
||||
|
||||
private static final String NAME = "Vampire";
|
||||
private static final int MAX_HP = 90;
|
||||
private static final int MAX_MP = 80;
|
||||
private static final int XP_REWARD = 80;
|
||||
private static final int BASE_DAMAGE = 12;
|
||||
|
||||
private final Armor personalArmor = new VampireArmor();
|
||||
|
||||
public Vampire() {
|
||||
|
||||
super(
|
||||
NAME,
|
||||
MAX_HP,
|
||||
MAX_MP,
|
||||
XP_REWARD,
|
||||
BASE_DAMAGE,
|
||||
null,
|
||||
new Dagger(),
|
||||
new LifeSteal()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Armor getPersonalArmor() {
|
||||
return personalArmor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "vampire{" +
|
||||
"MAX_HP : 90 | " +
|
||||
"MAX_MP : 80 | " +
|
||||
"XP_REWARD : 80 | " +
|
||||
"BASE_DAMAGE : 12 | " +
|
||||
"personalArmor = " + personalArmor +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.abilities.ArcaneStorm;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.armors.AssassinArmor;
|
||||
import org.project.item.weapons.Dagger;
|
||||
|
||||
public class Assassin extends Player {
|
||||
|
||||
private static final int MAX_HP = 90;
|
||||
private static final int MAX_MP = 120;
|
||||
private static final int LEVEL = 1;
|
||||
private static final int XP = 0;
|
||||
private static final int BASE_DAMAGE = 15;
|
||||
|
||||
private final Armor personalArmor =
|
||||
new AssassinArmor();
|
||||
|
||||
public Assassin(String name) {
|
||||
|
||||
super(
|
||||
name,
|
||||
MAX_HP,
|
||||
MAX_MP,
|
||||
LEVEL,
|
||||
XP,
|
||||
null,
|
||||
BASE_DAMAGE,
|
||||
new Dagger(),
|
||||
new ArcaneStorm()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Armor getPersonalArmor() {
|
||||
return personalArmor;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,38 @@
|
||||
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.abilities.GuardianOath;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.armors.KnightArmor;
|
||||
import org.project.item.weapons.Sword;
|
||||
|
||||
public class Knight extends Player {
|
||||
|
||||
private static final int MAX_HP = 150;
|
||||
private static final int MAX_MP = 80;
|
||||
private static final int LEVEL = 1;
|
||||
private static final int XP = 0;
|
||||
private static final int BASE_DAMAGE = 12;
|
||||
|
||||
private final Armor personalArmor =
|
||||
new KnightArmor();
|
||||
|
||||
public Knight(String name) {
|
||||
|
||||
super(
|
||||
name,
|
||||
MAX_HP,
|
||||
MAX_MP,
|
||||
LEVEL,
|
||||
XP,
|
||||
null,
|
||||
BASE_DAMAGE,
|
||||
new Sword(),
|
||||
new GuardianOath()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Armor getPersonalArmor() {
|
||||
return personalArmor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,89 +1,359 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.abilities.SpecialAbility;
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.weapons.Weapon;
|
||||
import org.project.managers.SpecialAbilityManager;
|
||||
import org.project.managers.StatusEffectManager;
|
||||
import org.project.weaponEffects.StatusEffect;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Player {
|
||||
protected String name;
|
||||
Weapon weapon;
|
||||
Armor armor;
|
||||
public abstract class Player implements Entity {
|
||||
|
||||
// =========================================================
|
||||
// BASIC INFO
|
||||
// =========================================================
|
||||
|
||||
private final String name;
|
||||
|
||||
private int level;
|
||||
private int xp;
|
||||
|
||||
// =========================================================
|
||||
// STATS
|
||||
// =========================================================
|
||||
|
||||
private int maxHp;
|
||||
private int hp;
|
||||
private int maxHP;
|
||||
|
||||
private int maxMp;
|
||||
private int mp;
|
||||
private int maxMP;
|
||||
|
||||
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
|
||||
private int baseDamage;
|
||||
|
||||
// =========================================================
|
||||
// EQUIPMENT
|
||||
// =========================================================
|
||||
|
||||
private Armor armor;
|
||||
private Weapon weapon;
|
||||
|
||||
// =========================================================
|
||||
// ABILITIES
|
||||
// =========================================================
|
||||
|
||||
protected SpecialAbility specialAbility;
|
||||
|
||||
private final StatusEffectManager effectManager;
|
||||
private final SpecialAbilityManager abilityManager;
|
||||
|
||||
// =========================================================
|
||||
// STATES
|
||||
// =========================================================
|
||||
|
||||
private boolean defending;
|
||||
private boolean frozen;
|
||||
private boolean stunned;
|
||||
private boolean live;
|
||||
|
||||
// =========================================================
|
||||
// CONSTRUCTOR
|
||||
// =========================================================
|
||||
|
||||
public Player(
|
||||
String name,
|
||||
int maxHp,
|
||||
int maxMp,
|
||||
int level,
|
||||
int xp,
|
||||
Armor armor,
|
||||
int baseDamage,
|
||||
Weapon weapon,
|
||||
SpecialAbility specialAbility
|
||||
) {
|
||||
|
||||
this.name = name;
|
||||
this.hp = hp;
|
||||
this.mp = mp;
|
||||
|
||||
this.weapon = weapon;
|
||||
this.maxHp = maxHp;
|
||||
this.hp = maxHp;
|
||||
|
||||
this.maxMp = maxMp;
|
||||
this.mp = maxMp;
|
||||
|
||||
this.level = level;
|
||||
this.xp = xp;
|
||||
|
||||
this.armor = armor;
|
||||
this.baseDamage = baseDamage;
|
||||
this.weapon = weapon;
|
||||
|
||||
this.specialAbility = specialAbility;
|
||||
|
||||
this.effectManager = new StatusEffectManager();
|
||||
this.abilityManager = new SpecialAbilityManager();
|
||||
|
||||
this.defending = false;
|
||||
this.frozen = false;
|
||||
this.stunned = false;
|
||||
this.live = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// =========================================================
|
||||
// STATUS EFFECTS
|
||||
// =========================================================
|
||||
|
||||
@Override
|
||||
public void addStatusEffect(StatusEffect effect) {
|
||||
effectManager.addEffect(effect, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Entity target) {
|
||||
target.takeDamage(weapon.getDamage());
|
||||
public void tickStatusEffects() {
|
||||
effectManager.tick(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatusEffectManager getEffectManager() {
|
||||
return effectManager;
|
||||
}
|
||||
|
||||
// =========================================================
|
||||
// ABILITIES
|
||||
// =========================================================
|
||||
|
||||
@Override
|
||||
public void addAbilityEffect(SpecialAbility ability, Entity target) {
|
||||
abilityManager.addAbility(ability, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tickAbilityEffects(Entity target) {
|
||||
abilityManager.tick(this, target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SpecialAbility getSpacialAbility() {
|
||||
return specialAbility;
|
||||
}
|
||||
|
||||
// =========================================================
|
||||
// COMBAT
|
||||
// =========================================================
|
||||
|
||||
@Override
|
||||
public void takeDamage(int amount) {
|
||||
|
||||
int finalDamage = Math.max(0, amount);
|
||||
|
||||
|
||||
hp -= finalDamage;
|
||||
if (hp <= 0) {
|
||||
hp = 0;
|
||||
live = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void heal(int amount) {
|
||||
|
||||
if (!live) {
|
||||
return;
|
||||
}
|
||||
|
||||
hp += amount;
|
||||
|
||||
if (hp > maxHp) {
|
||||
hp = maxHp;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void useMana(int amount) {
|
||||
|
||||
if (amount <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mp < amount) {
|
||||
|
||||
System.out.println(name + " doesn't have enough mana!");
|
||||
return;
|
||||
}
|
||||
|
||||
mp -= amount;
|
||||
}
|
||||
|
||||
public void restoreMana(int amount) {
|
||||
|
||||
mp += amount;
|
||||
|
||||
if (mp > maxMp) {
|
||||
mp = maxMp;
|
||||
}
|
||||
}
|
||||
|
||||
// =========================================================
|
||||
// STATES
|
||||
// =========================================================
|
||||
|
||||
public void defend() {
|
||||
// TODO
|
||||
defending = true;
|
||||
}
|
||||
|
||||
public void freeze() {
|
||||
frozen = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
hp -= damage - armor.getDefense();
|
||||
public void stun() {
|
||||
stunned = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int health) {
|
||||
hp += health;
|
||||
if (hp > maxHP) {
|
||||
hp = maxHP;
|
||||
public void resetTurnState() {
|
||||
|
||||
defending = false;
|
||||
frozen = false;
|
||||
stunned = false;
|
||||
}
|
||||
|
||||
public void restore() {
|
||||
hp = maxHp;
|
||||
mp = maxMp;
|
||||
System.out.println(name + " fully restored!");
|
||||
System.out.println(" HP: " + hp + "/" + maxHp + " | MP: " + mp + "/" + maxMp + "\n");
|
||||
}
|
||||
|
||||
// =========================================================
|
||||
// LEVEL SYSTEM
|
||||
// =========================================================
|
||||
|
||||
public void gainXp(int amount) {
|
||||
|
||||
xp += amount;
|
||||
|
||||
while (xp >= level * 100) {
|
||||
|
||||
xp -= level * 100;
|
||||
levelUp();
|
||||
}
|
||||
}
|
||||
|
||||
public void levelUp() {
|
||||
|
||||
level++;
|
||||
|
||||
maxHp += 20;
|
||||
maxMp += 10;
|
||||
|
||||
baseDamage += 5;
|
||||
|
||||
hp = maxHp;
|
||||
mp = maxMp;
|
||||
|
||||
System.out.println(name + " leveled up!");
|
||||
System.out.println("Current Level: " + level);
|
||||
}
|
||||
|
||||
// =========================================================
|
||||
// GETTERS
|
||||
// =========================================================
|
||||
|
||||
@Override
|
||||
public void fillMana(int mana) {
|
||||
mp += mana;
|
||||
if (mp > maxMP) {
|
||||
mp = maxMP;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHp() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHP() {
|
||||
return maxHP;
|
||||
}
|
||||
|
||||
public int getMp() {
|
||||
return mp;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public int getXp() {
|
||||
return xp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHP() {
|
||||
return maxHp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxMP() {
|
||||
return maxMP;
|
||||
return maxMp;
|
||||
}
|
||||
|
||||
public Weapon getWeapon() {
|
||||
return weapon;
|
||||
@Override
|
||||
public int getBaseDamage() {
|
||||
return baseDamage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Armor getArmor() {
|
||||
return armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Weapon getWeapon() {
|
||||
return weapon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Armor getPersonalArmor() {
|
||||
return armor;
|
||||
}
|
||||
|
||||
public boolean isDefending() {
|
||||
return defending;
|
||||
}
|
||||
|
||||
public boolean isFrozen() {
|
||||
return frozen;
|
||||
}
|
||||
|
||||
public boolean isStunned() {
|
||||
return stunned;
|
||||
}
|
||||
|
||||
public boolean isLive() {
|
||||
return live;
|
||||
}
|
||||
|
||||
// =========================================================
|
||||
// SETTERS
|
||||
// =========================================================
|
||||
|
||||
@Override
|
||||
public void setHp(int value) {
|
||||
hp = Math.max(0, Math.min(value, maxHp));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMp(int value) {
|
||||
mp = Math.max(0, Math.min(value, maxMp));
|
||||
}
|
||||
|
||||
public void setArmor(Armor armor) {
|
||||
this.armor = armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setWeapon(Weapon weapon) {
|
||||
this.weapon = weapon;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.abilities.ArcaneStorm;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.armors.WizardArmor;
|
||||
import org.project.item.weapons.Sword;
|
||||
|
||||
public class Wizard extends Player {
|
||||
|
||||
private static final int MAX_HP = 80;
|
||||
private static final int MAX_MP = 200;
|
||||
private static final int LEVEL = 1;
|
||||
private static final int XP = 0;
|
||||
private static final int BASE_DAMAGE = 10;
|
||||
|
||||
private final Armor personalArmor =
|
||||
new WizardArmor();
|
||||
|
||||
public Wizard(String name) {
|
||||
|
||||
super(
|
||||
name,
|
||||
MAX_HP,
|
||||
MAX_MP,
|
||||
LEVEL,
|
||||
XP,
|
||||
null,
|
||||
BASE_DAMAGE,
|
||||
new Sword(),
|
||||
new ArcaneStorm()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Armor getPersonalArmor() {
|
||||
return personalArmor;
|
||||
}
|
||||
}
|
||||
@@ -3,9 +3,7 @@ package org.project.item;
|
||||
import org.project.entity.Entity;
|
||||
|
||||
public interface Item {
|
||||
void use(Entity target);
|
||||
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
String getName();
|
||||
|
||||
}
|
||||
|
||||
@@ -1,31 +1,77 @@
|
||||
package org.project.item.armors;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Armor {
|
||||
package org.project.item.armors;
|
||||
public class Armor {
|
||||
|
||||
public enum ArmorType {
|
||||
LIGHT,
|
||||
MEDIUM,
|
||||
HEAVY
|
||||
}
|
||||
|
||||
|
||||
private String name;
|
||||
private ArmorType type;
|
||||
|
||||
private int defense;
|
||||
private int maxDefense;
|
||||
|
||||
private int durability;
|
||||
private int maxDurability;
|
||||
|
||||
private boolean isBroke;
|
||||
private boolean isBroken;
|
||||
|
||||
public Armor(int defense, int durability) {
|
||||
this.defense = defense;
|
||||
this.durability = durability;
|
||||
// Constructor
|
||||
public Armor(String name, ArmorType type, int maxDefense, int maxDurability) {
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
this.maxDefense = maxDefense;
|
||||
this.defense = maxDefense;
|
||||
this.maxDurability = maxDurability;
|
||||
this.durability = maxDurability;
|
||||
this.isBroken = false;
|
||||
}
|
||||
|
||||
public void checkBreak() {
|
||||
|
||||
public int reduceDamage(int damage) {
|
||||
|
||||
if (isBroken) {
|
||||
return damage;
|
||||
}
|
||||
|
||||
int reducedDamage = damage - defense;
|
||||
|
||||
if (reducedDamage < 0) {
|
||||
reducedDamage = 0;
|
||||
}
|
||||
|
||||
reduceDurability(1);
|
||||
|
||||
return reducedDamage;
|
||||
}
|
||||
|
||||
public void reduceDurability(int amount) {
|
||||
durability -= amount;
|
||||
|
||||
if (durability <= 0) {
|
||||
isBroke = true;
|
||||
durability = 0;
|
||||
breakArmor();
|
||||
}
|
||||
}
|
||||
|
||||
// شکستن زره
|
||||
private void breakArmor() {
|
||||
isBroken = true;
|
||||
defense = 0;
|
||||
}
|
||||
|
||||
// ===== Getters =====
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
// TODO: (BONUS) UPDATE THE REPAIR METHOD
|
||||
public void repair() {
|
||||
isBroke = false;
|
||||
defense = maxDefense;
|
||||
durability = maxDurability;
|
||||
public ArmorType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public int getDefense() {
|
||||
@@ -36,7 +82,19 @@ public abstract class Armor {
|
||||
return durability;
|
||||
}
|
||||
|
||||
public boolean isBroke() {
|
||||
return isBroke;
|
||||
public int getMaxDurability() {
|
||||
return maxDurability;
|
||||
}
|
||||
|
||||
public boolean isBroken() {
|
||||
return isBroken;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name + " | Type: " + type +
|
||||
" | Defense: " + defense +
|
||||
" | Durability: " + durability + "/" + maxDurability +
|
||||
(isBroken ? " (BROKEN)" : "");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.project.item.armors;
|
||||
|
||||
public class AssassinArmor extends Armor {
|
||||
|
||||
private static final String NAME = "wizard Robe";
|
||||
private static final ArmorType ARMOR_TYPE = ArmorType.HEAVY;
|
||||
private static final int MAX_DEFENSE = 35;
|
||||
private static final int MAX_DURABILITY = 60;
|
||||
|
||||
public AssassinArmor() {
|
||||
super(NAME,
|
||||
ARMOR_TYPE,
|
||||
MAX_DEFENSE,
|
||||
MAX_DURABILITY
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.project.item.armors;
|
||||
|
||||
public class DragonArmor extends Armor {
|
||||
|
||||
private static final String NAME = "Dragon scale armor";
|
||||
private static final ArmorType ARMOR_TYPE = ArmorType.HEAVY;
|
||||
private static final int MAX_DEFENSE = 40;
|
||||
private static final int MAX_DURABILITY = 60;
|
||||
|
||||
public DragonArmor() {
|
||||
super(NAME,
|
||||
ARMOR_TYPE,
|
||||
MAX_DEFENSE,
|
||||
MAX_DURABILITY
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.project.item.armors;
|
||||
|
||||
public class GoblinArmor extends Armor {
|
||||
|
||||
private static final String NAME = "goblin Robe";
|
||||
private static final ArmorType ARMOR_TYPE = ArmorType.LIGHT;
|
||||
private static final int MAX_DEFENSE = 5;
|
||||
private static final int MAX_DURABILITY = 15;
|
||||
|
||||
public GoblinArmor() {
|
||||
super(NAME,
|
||||
ARMOR_TYPE,
|
||||
MAX_DEFENSE,
|
||||
MAX_DURABILITY
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,17 @@
|
||||
package org.project.item.armors;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class KnightArmor {
|
||||
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
||||
public class KnightArmor extends Armor {
|
||||
|
||||
private static final String NAME = "knight armor";
|
||||
private static final ArmorType ARMOR_TYPE = ArmorType.HEAVY;
|
||||
private static final int MAX_DEFENSE = 35;
|
||||
private static final int MAX_DURABILITY = 60;
|
||||
|
||||
public KnightArmor() {
|
||||
super(NAME,
|
||||
ARMOR_TYPE,
|
||||
MAX_DEFENSE,
|
||||
MAX_DURABILITY
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.project.item.armors;
|
||||
|
||||
public class SkeletonArmor extends Armor {
|
||||
|
||||
private static final String NAME = "skeleton armor";
|
||||
private static final ArmorType ARMOR_TYPE = ArmorType.LIGHT;
|
||||
private static final int MAX_DEFENSE = 15;
|
||||
private static final int MAX_DURABILITY = 20;
|
||||
|
||||
public SkeletonArmor() {
|
||||
super(NAME,
|
||||
ARMOR_TYPE,
|
||||
MAX_DEFENSE,
|
||||
MAX_DURABILITY
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.project.item.armors;
|
||||
|
||||
public class VampireArmor extends Armor {
|
||||
|
||||
private static final String NAME = "vampire armor";
|
||||
private static final ArmorType ARMOR_TYPE = ArmorType.MEDIUM;
|
||||
private static final int MAX_DEFENSE = 16;
|
||||
private static final int MAX_DURABILITY = 30;
|
||||
|
||||
public VampireArmor() {
|
||||
super(NAME,
|
||||
ARMOR_TYPE,
|
||||
MAX_DEFENSE,
|
||||
MAX_DURABILITY
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.project.item.armors;
|
||||
|
||||
public class WizardArmor extends Armor {
|
||||
|
||||
private static final String NAME = "wizard Robe";
|
||||
private static final ArmorType ARMOR_TYPE = ArmorType.MEDIUM;
|
||||
private static final int MAX_DEFENSE = 20;
|
||||
private static final int MAX_DURABILITY = 20;
|
||||
|
||||
public WizardArmor() {
|
||||
super(NAME,
|
||||
ARMOR_TYPE,
|
||||
MAX_DEFENSE,
|
||||
MAX_DURABILITY
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,40 @@
|
||||
package org.project.item.consumables;
|
||||
|
||||
import org.project.entity.players.Player;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Consumable {
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
|
||||
private String name;
|
||||
private int healAmount;
|
||||
private int charges;
|
||||
|
||||
public Consumable(String name, int healAmount, int charges) {
|
||||
this.name = name;
|
||||
this.healAmount = healAmount;
|
||||
this.charges = charges;
|
||||
}
|
||||
|
||||
public void use(Player target) {
|
||||
|
||||
if (charges <= 0) {
|
||||
System.out.println("The flask is empty!");
|
||||
return;
|
||||
}
|
||||
|
||||
target.heal(healAmount);
|
||||
charges--;
|
||||
|
||||
}
|
||||
|
||||
public int getCharges() {
|
||||
return charges;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
package org.project.item.consumables;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Flask {
|
||||
/*
|
||||
THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN.
|
||||
*/
|
||||
|
||||
// TODO: UPDATE USE METHOD
|
||||
@Override
|
||||
public void use(Entity target) {
|
||||
target.heal(target.getMaxHP() / 10);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.project.item.consumables;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.entity.players.Player;
|
||||
import org.project.item.Item;
|
||||
|
||||
public class HealFlask extends Consumable {
|
||||
|
||||
private int healAmount;
|
||||
|
||||
public HealFlask(String name, int healAmount, int charges) {
|
||||
super(name, healAmount, charges);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void use(Player target) {
|
||||
|
||||
super.use(target);
|
||||
System.out.println(target.getName() + " healed for " + healAmount);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.project.item.consumables;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.entity.players.Player;
|
||||
import org.project.item.Item;
|
||||
|
||||
public class ManaFlask extends Consumable {
|
||||
|
||||
private int manaAmount;
|
||||
|
||||
public ManaFlask(String name, int manaAmount, int charges) {
|
||||
|
||||
super(name, manaAmount, charges);
|
||||
}
|
||||
|
||||
|
||||
public void use(Player target) {
|
||||
super.use(target);
|
||||
|
||||
System.out.println(target.getName() + " got " + manaAmount + " mana");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.project.item.weapons;
|
||||
|
||||
import org.project.weaponEffects.StatusEffect;
|
||||
|
||||
public class Dagger extends Weapon {
|
||||
|
||||
private static final String NAME = "Sword";
|
||||
private static final int LIGHT_DAMAGE = 10;
|
||||
private static final int HEAVY_DAMAGE = 5;
|
||||
private static final int DURABILITY = 4;
|
||||
|
||||
public Dagger() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public Dagger(StatusEffect weaponEffect) {
|
||||
|
||||
super(
|
||||
NAME,
|
||||
LIGHT_DAMAGE,
|
||||
HEAVY_DAMAGE,
|
||||
weaponEffect,
|
||||
DURABILITY
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +1,26 @@
|
||||
package org.project.item.weapons;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.weaponEffects.StatusEffect;
|
||||
|
||||
import java.util.ArrayList;
|
||||
public class Sword extends Weapon {
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Sword {
|
||||
/*
|
||||
THIS IS AN EXAMPLE OF A WEAPON DESIGN.
|
||||
*/
|
||||
|
||||
int abilityCharge;
|
||||
private static final String NAME = "Sword";
|
||||
private static final int LIGHT_DAMAGE = 10;
|
||||
private static final int HEAVY_DAMAGE = 5;
|
||||
private static final int DURABILITY = 4;
|
||||
|
||||
public Sword() {
|
||||
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
||||
this(null);
|
||||
}
|
||||
|
||||
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
|
||||
public void uniqueAbility(ArrayList<Entity> targets) {
|
||||
abilityCharge += 2;
|
||||
for (Entity target : targets) {
|
||||
target.takeDamage(getDamage());
|
||||
}
|
||||
public Sword(StatusEffect weaponEffect) {
|
||||
|
||||
super(
|
||||
NAME,
|
||||
LIGHT_DAMAGE,
|
||||
HEAVY_DAMAGE,
|
||||
weaponEffect,
|
||||
DURABILITY
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,48 @@
|
||||
package org.project.item.weapons;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.weaponEffects.StatusEffect;
|
||||
|
||||
import org.project.item.Item;
|
||||
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Weapon {
|
||||
private int damage;
|
||||
private int manaCost;
|
||||
public abstract class Weapon implements Item {
|
||||
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS ATTRIBUTES
|
||||
*/
|
||||
private String name;
|
||||
private StatusEffect effect;
|
||||
private int lightAttackDamage;
|
||||
private int heavyAttackDamage;
|
||||
private int equipManaCost;
|
||||
|
||||
public Weapon(int damage, int manaCost) {
|
||||
this.damage = damage;
|
||||
this.manaCost = manaCost;
|
||||
|
||||
public Weapon(String name,int heavyAttackDamage,int lightAttackDamage, StatusEffect statusEffect, int equipManaCost) {
|
||||
this.name = name;
|
||||
this.lightAttackDamage = lightAttackDamage;
|
||||
this.heavyAttackDamage = heavyAttackDamage;
|
||||
this.effect = statusEffect;
|
||||
this.equipManaCost = equipManaCost;
|
||||
}
|
||||
|
||||
public int getHeavyAttackDamage() {
|
||||
return heavyAttackDamage;
|
||||
}
|
||||
|
||||
public int getLightAttackDamage() {
|
||||
return lightAttackDamage;
|
||||
}
|
||||
|
||||
public StatusEffect getEffect() {
|
||||
return effect;
|
||||
}
|
||||
|
||||
public void setEffect(StatusEffect effect) {
|
||||
this.effect = effect;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void use(Entity target) {
|
||||
target.takeDamage(damage);
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
public int getManaCost() {
|
||||
return manaCost;
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -3,26 +3,75 @@ package org.project.location;
|
||||
import org.project.entity.enemies.Enemy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class Location {
|
||||
private String name;
|
||||
|
||||
private ArrayList<Enemy> enemies;
|
||||
private final String name;
|
||||
|
||||
public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) {
|
||||
this.locations = locations;
|
||||
this.enemies = enemies;
|
||||
private final List<Location> connectedLocations;
|
||||
private final List<Enemy> enemies;
|
||||
|
||||
public Location(String name) {
|
||||
this.name = name;
|
||||
this.connectedLocations = new ArrayList<>();
|
||||
this.enemies = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Location(String name, List<Location> connectedLocations, List<Enemy> enemies) {
|
||||
this.name = name;
|
||||
|
||||
this.connectedLocations =
|
||||
connectedLocations != null ? new ArrayList<>(connectedLocations) : new ArrayList<>();
|
||||
|
||||
this.enemies =
|
||||
enemies != null ? new ArrayList<>(enemies) : new ArrayList<>();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public ArrayList<Location> getLocations() {
|
||||
return locations;
|
||||
public List<Location> getConnectedLocations() {
|
||||
return Collections.unmodifiableList(connectedLocations);
|
||||
}
|
||||
|
||||
public ArrayList<Enemy> getEnemies() {
|
||||
return enemies;
|
||||
public List<Enemy> getEnemies() {
|
||||
return Collections.unmodifiableList(enemies);
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// ADD / REMOVE LOCATIONS
|
||||
// ------------------------------------location
|
||||
|
||||
public void connect(Location other) {
|
||||
if (other == null || other == this) return;
|
||||
|
||||
if (!connectedLocations.contains(other)) {
|
||||
connectedLocations.add(other);
|
||||
}
|
||||
|
||||
if (!other.connectedLocations.contains(this)) {
|
||||
other.connectedLocations.add(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void removeLocation(Location location) {
|
||||
connectedLocations.remove(location);
|
||||
}
|
||||
|
||||
// ------------------------------------
|
||||
// ADD / REMOVE ENEMIES
|
||||
// ------------------------------------
|
||||
public void addEnemy(Enemy enemy) {
|
||||
if (enemy != null) {
|
||||
enemies.add(enemy);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeEnemy(Enemy enemy) {
|
||||
enemies.remove(enemy);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
package org.project.managers;
|
||||
|
||||
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
|
||||
|
||||
public class ActionDecisionManager {
|
||||
|
||||
public enum actionsType {
|
||||
lightAttack,
|
||||
heavyAttack,
|
||||
defend,
|
||||
heal,
|
||||
ability,
|
||||
shiedbash,
|
||||
inventory
|
||||
}
|
||||
|
||||
|
||||
private Random random = new Random();
|
||||
|
||||
|
||||
public actionsType userChooseAction() {
|
||||
actionsType res = null;
|
||||
while (true) {
|
||||
System.out.println("Choose attack type:\n");
|
||||
System.out.println("1.lightAttack");
|
||||
System.out.println("2.heavyAttack");
|
||||
System.out.println("3.heal");
|
||||
System.out.println("4.defend");
|
||||
System.out.println("5.ability");
|
||||
System.out.println("6.shielBash");
|
||||
System.out.println("7.inventory");
|
||||
|
||||
int choice = new Scanner(System.in).nextInt();
|
||||
switch (choice) {
|
||||
case 1:
|
||||
return actionsType.lightAttack;
|
||||
case 2:
|
||||
return actionsType.heavyAttack;
|
||||
case 3:
|
||||
return actionsType.heal;
|
||||
case 4:
|
||||
return actionsType.defend;
|
||||
case 5:
|
||||
return actionsType.ability;
|
||||
case 6:
|
||||
return actionsType.shiedbash;
|
||||
case 7:
|
||||
return actionsType.inventory;
|
||||
default:
|
||||
return actionsType.lightAttack;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public actionsType botChooseAction() {
|
||||
|
||||
actionsType[] possibleActions = {
|
||||
actionsType.lightAttack,
|
||||
actionsType.heavyAttack,
|
||||
actionsType.defend,
|
||||
actionsType.heal
|
||||
};
|
||||
|
||||
return possibleActions[random.nextInt(possibleActions.length)];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
package org.project.managers;
|
||||
|
||||
import org.project.Colors;
|
||||
import org.project.entity.players.Player;
|
||||
import org.project.item.consumables.HealFlask;
|
||||
import org.project.item.consumables.ManaFlask;
|
||||
import org.project.item.weapons.Dagger;
|
||||
import org.project.item.weapons.Sword;
|
||||
import org.project.weaponEffects.BurnEffect;
|
||||
import org.project.weaponEffects.FreezeEffect;
|
||||
import org.project.weaponEffects.PoisonEffect;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class InventoryManager {
|
||||
|
||||
private final HealFlask healFlask = new HealFlask("Heal Flask", 30, 3);
|
||||
private final ManaFlask manaFlask = new ManaFlask("Mana Flask", 20, 2);
|
||||
|
||||
|
||||
private final Scanner scanner = new Scanner(System.in);
|
||||
private final ManaCostManager manager = new ManaCostManager();
|
||||
|
||||
public void displayInventory(Player player) {
|
||||
|
||||
while (true) {
|
||||
|
||||
System.out.println("\n========" + Colors.YELLOW + " INVENTORY " + Colors.RESET + "========");
|
||||
System.out.println("""
|
||||
1. Equip Armor
|
||||
2. Equip / Change Weapon
|
||||
3. Equip / Change Weapon Effect
|
||||
4. Use Flask
|
||||
0. Exit
|
||||
""");
|
||||
|
||||
|
||||
int input = scanner.nextInt();
|
||||
|
||||
if (input < 0 || input > 4) {
|
||||
System.out.println("Enter a number between [0 - 3]");
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (input) {
|
||||
|
||||
// =========================
|
||||
// Exit
|
||||
// =========================
|
||||
|
||||
case 0:
|
||||
System.out.println("Closing inventory...");
|
||||
return;
|
||||
|
||||
// =========================
|
||||
// Armor
|
||||
// =========================
|
||||
|
||||
case 1:
|
||||
|
||||
if (player.getArmor() != null) {
|
||||
|
||||
System.out.println(
|
||||
player.getName() +
|
||||
Color.GREEN+
|
||||
" already has armor: " +
|
||||
Colors.RESET +
|
||||
player.getArmor().getName()
|
||||
);
|
||||
|
||||
} else {
|
||||
|
||||
manager.equipArmor(player, player.getPersonalArmor());
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// =========================
|
||||
// Weapon
|
||||
// =========================
|
||||
|
||||
case 2:
|
||||
|
||||
System.out.println("\n---" + Colors.YELLOW + " Weapons " + Colors.RESET + "---");
|
||||
System.out.println("""
|
||||
1. Sword
|
||||
2. Dagger
|
||||
0. Back
|
||||
""");
|
||||
|
||||
int choice = scanner.nextInt();
|
||||
|
||||
if (choice < 0 || choice > 2) {
|
||||
System.out.println("Enter a number between [0 - 2]");
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (choice) {
|
||||
|
||||
case 0:
|
||||
System.out.println("Coming back...");
|
||||
break;
|
||||
|
||||
case 1:
|
||||
manager.equipWeapon(
|
||||
player,
|
||||
new Sword(null)
|
||||
);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
manager.equipWeapon(player, new Dagger(null));
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
// =========================
|
||||
// Weapon Effects
|
||||
// =========================
|
||||
|
||||
case 3:
|
||||
|
||||
if (player.getWeapon() == null) {
|
||||
System.out.println(Colors.RED + "Equip a weapon first!" + Colors.RESET);
|
||||
break;
|
||||
}
|
||||
|
||||
System.out.println("\n---" + Colors.YELLOW + " Weapon Effects " + Colors.RESET + "---");
|
||||
System.out.println("""
|
||||
1. Poison Effect
|
||||
2. Freeze Effect
|
||||
3. Burn Effect
|
||||
0. Back
|
||||
""");
|
||||
|
||||
int choice2 = scanner.nextInt();
|
||||
|
||||
if (choice2 < 0 || choice2 > 3) {
|
||||
System.out.println("Enter a number between [0 - 4]");
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (choice2) {
|
||||
|
||||
case 0:
|
||||
System.out.println("Coming back...");
|
||||
break;
|
||||
|
||||
case 1:
|
||||
|
||||
manager.equipStatusEffect(player, new PoisonEffect());
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
manager.equipStatusEffect(player, new FreezeEffect());
|
||||
|
||||
break;
|
||||
|
||||
case 3:
|
||||
|
||||
manager.equipStatusEffect(player, new BurnEffect());
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
case 4:
|
||||
|
||||
System.out.println("\n---" + Colors.YELLOW + " Flasks " + Colors.RESET + "---");
|
||||
|
||||
System.out.println("1. Heal Flask (" + healFlask.getCharges() + ")");
|
||||
System.out.println("2. Mana Flask (" + manaFlask.getCharges() + ")");
|
||||
System.out.println("0. Back");
|
||||
|
||||
int flaskChoice = scanner.nextInt();
|
||||
|
||||
if (flaskChoice < 0 || flaskChoice > 2) {
|
||||
System.out.println("Enter a number between [0 - 2]");
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (flaskChoice) {
|
||||
|
||||
case 0:
|
||||
System.out.println("Coming back...");
|
||||
break;
|
||||
|
||||
case 1:
|
||||
|
||||
if (healFlask.getCharges() <= 0) {
|
||||
System.out.println(Colors.RED + "No Heal Flask charges left!" + Colors.RESET);
|
||||
break;
|
||||
}
|
||||
|
||||
healFlask.use(player);
|
||||
|
||||
System.out.println(
|
||||
Colors.GREEN +
|
||||
"Heal Flask used! Charges left: " +
|
||||
healFlask.getCharges() +
|
||||
Colors.RESET
|
||||
);
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
if (manaFlask.getCharges() <= 0) {
|
||||
System.out.println(Colors.RED + "No Mana Flask charges left!" + Colors.RESET);
|
||||
break;
|
||||
}
|
||||
|
||||
manaFlask.use(player);
|
||||
|
||||
System.out.println(
|
||||
Colors.CYAN +
|
||||
"Mana Flask used! Charges left: " +
|
||||
manaFlask.getCharges() +
|
||||
Colors.RESET
|
||||
);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
package org.project.managers;
|
||||
|
||||
import org.project.Colors;
|
||||
import org.project.abilities.SpecialAbility;
|
||||
import org.project.entity.Entity;
|
||||
import org.project.entity.players.Player;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.weapons.Weapon;
|
||||
import org.project.weaponEffects.StatusEffect;
|
||||
|
||||
public class ManaCostManager {
|
||||
|
||||
private final int heavyAttackManaCost = 8;
|
||||
private final int defendManaCost = 9;
|
||||
private final int healManaCost = 12;
|
||||
private final int shieldBashManaCost = 15;
|
||||
|
||||
// =========================
|
||||
// Weapon
|
||||
// =========================
|
||||
|
||||
public void equipWeapon(Player player, Weapon weapon) {
|
||||
|
||||
int manaCost = getWeaponEquipCost(weapon);
|
||||
|
||||
if (player.getMp() < manaCost) {
|
||||
|
||||
System.out.println("Not enough mana to equip weapon!");
|
||||
return;
|
||||
}
|
||||
|
||||
player.useMana(manaCost);
|
||||
|
||||
player.setWeapon(weapon);
|
||||
|
||||
System.out.println(
|
||||
player.getName() +
|
||||
" equipped weapon: " +
|
||||
weapon.getName()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Armor
|
||||
// =========================
|
||||
|
||||
public void equipArmor(Player player, Armor armor) {
|
||||
|
||||
int manaCost = getArmorEquipCost(armor);
|
||||
|
||||
if (player.getMp() < manaCost) {
|
||||
|
||||
System.out.println(Colors.RED + "Not enough mana to equip armor!" + Colors.RESET);
|
||||
return;
|
||||
}
|
||||
|
||||
player.useMana(manaCost);
|
||||
|
||||
player.setArmor(armor);
|
||||
|
||||
System.out.println(
|
||||
player.getName() +
|
||||
Colors.GREEN +
|
||||
" equipped armor: " +
|
||||
Colors.RESET +
|
||||
armor.getName()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Status Effect
|
||||
// =========================
|
||||
|
||||
public void equipStatusEffect(Player player,
|
||||
StatusEffect equippedEffect) {
|
||||
|
||||
Weapon weapon = player.getWeapon();
|
||||
|
||||
if (weapon == null) {
|
||||
|
||||
System.out.println(Colors.RED + "Equip a weapon first!" + Colors.RESET);
|
||||
return;
|
||||
}
|
||||
|
||||
int manaCost = equippedEffect.getEquipManaCost();
|
||||
|
||||
if (player.getMp() < manaCost) {
|
||||
|
||||
System.out.println(Colors.RED + "Not enough mana to equip this effect!" + Colors.RESET);
|
||||
return;
|
||||
}
|
||||
|
||||
player.useMana(manaCost);
|
||||
|
||||
weapon.setEffect(equippedEffect);
|
||||
|
||||
System.out.println(
|
||||
player.getName() +
|
||||
Colors.GREEN +
|
||||
" equipped effect: " +
|
||||
Colors.RESET +
|
||||
equippedEffect.getName()
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Special Ability
|
||||
// =========================
|
||||
|
||||
public boolean useSpecialAbility(Entity entity) {
|
||||
|
||||
SpecialAbility ability = entity.getSpacialAbility();
|
||||
|
||||
if (ability == null) {
|
||||
|
||||
System.out.println(Colors.RED + "No special ability equipped!" + Colors.RESET);
|
||||
return false;
|
||||
}
|
||||
|
||||
int manaCost = ability.getManaCost();
|
||||
|
||||
if (entity.getMp() < manaCost) {
|
||||
|
||||
System.out.println(Colors.RED + "Not enough mana to use special ability!" + Colors.RESET);
|
||||
return false;
|
||||
}
|
||||
|
||||
entity.useMana(manaCost);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Heavy Attack
|
||||
// =========================
|
||||
|
||||
public boolean useHeavyAttack(Entity entity) {
|
||||
|
||||
if (entity.getMp() < heavyAttackManaCost) {
|
||||
|
||||
System.out.println(Colors.RED + "Not enough mana!" + Colors.RESET);
|
||||
return false;
|
||||
}
|
||||
|
||||
entity.useMana(heavyAttackManaCost);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Defend
|
||||
// =========================
|
||||
|
||||
public boolean useDefend(Entity entity) {
|
||||
|
||||
if (entity.getMp() < defendManaCost) {
|
||||
|
||||
System.out.println(Colors.RED + "Not enough mana!" + Colors.RESET);
|
||||
return false;
|
||||
}
|
||||
|
||||
entity.useMana(defendManaCost);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Heal
|
||||
// =========================
|
||||
|
||||
public boolean useHeal(Entity entity) {
|
||||
|
||||
if (entity.getMp() < healManaCost) {
|
||||
|
||||
System.out.println(Colors.RED + "Not enough mana!" + Colors.RESET);
|
||||
return false;
|
||||
}
|
||||
|
||||
entity.useMana(healManaCost);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Shield Bash
|
||||
// =========================
|
||||
|
||||
public boolean useShieldBash(Player player) {
|
||||
|
||||
Armor armor = player.getArmor();
|
||||
|
||||
if (armor == null) {
|
||||
|
||||
System.out.println(Colors.RED + "You need armor to use Shield Bash!" + Colors.RESET);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (armor.getType() != Armor.ArmorType.HEAVY) {
|
||||
|
||||
System.out.println(Colors.RED + "Shield Bash requires HEAVY armor!" + Colors.RESET);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (player.getMp() < shieldBashManaCost) {
|
||||
|
||||
System.out.println(Colors.RED + "Not enough mana!" + Colors.RESET);
|
||||
return false;
|
||||
}
|
||||
|
||||
player.useMana(shieldBashManaCost);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Mana Costs
|
||||
// =========================
|
||||
|
||||
private int getArmorEquipCost(Armor armor) {
|
||||
|
||||
return switch (armor.getType()) {
|
||||
|
||||
case LIGHT -> 3;
|
||||
|
||||
case MEDIUM -> 6;
|
||||
|
||||
case HEAVY -> 10;
|
||||
};
|
||||
}
|
||||
|
||||
private int getWeaponEquipCost(Weapon weapon) {
|
||||
|
||||
int damage = weapon.getLightAttackDamage();
|
||||
|
||||
if (damage <= 10) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (damage <= 20) {
|
||||
return 6;
|
||||
}
|
||||
|
||||
return 10;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package org.project.managers;
|
||||
|
||||
import org.project.abilities.*;
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.armors.GoblinArmor;
|
||||
|
||||
import javax.swing.text.Position;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SpecialAbilityManager {
|
||||
|
||||
private final Map<Entity, List<SpecialAbility>> activeAbilities =
|
||||
new HashMap<>();
|
||||
|
||||
// =========================
|
||||
// Add Ability
|
||||
// =========================
|
||||
|
||||
public void addAbility(SpecialAbility ability, Entity target) {
|
||||
|
||||
if (ability == null || target == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
activeAbilities.putIfAbsent(target, new ArrayList<>());
|
||||
|
||||
ability.onApply(target);
|
||||
|
||||
activeAbilities.get(target).add(ability);
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Update Ability Effects
|
||||
// =========================
|
||||
|
||||
public void tick(Entity abilityUser, Entity target) {
|
||||
|
||||
List<SpecialAbility> abilities = activeAbilities.get(abilityUser);
|
||||
|
||||
if (abilities == null || abilities.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Iterator<SpecialAbility> iterator = abilities.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
|
||||
SpecialAbility ability = iterator.next();
|
||||
|
||||
if (ability instanceof GuardianOath || ability instanceof PoisonDagger || ability instanceof LifeSteal)
|
||||
ability.onTick(abilityUser);
|
||||
|
||||
if (ability instanceof InfernoBreath || ability instanceof BoneStrike || ability instanceof ArcaneStorm)
|
||||
ability.onTick(target);
|
||||
|
||||
|
||||
ability.reduceDuration();
|
||||
|
||||
if (ability.getDuration() <= 0) {
|
||||
|
||||
ability.onExpire(abilityUser);
|
||||
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup empty list
|
||||
if (abilities.isEmpty()) {
|
||||
activeAbilities.remove(target);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package org.project.managers;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.weaponEffects.StatusEffect;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class StatusEffectManager {
|
||||
|
||||
private Map<Entity, List<StatusEffect>> activeEffects = new HashMap<>();
|
||||
|
||||
public void addEffect(StatusEffect newEffect, Entity target) {
|
||||
if (newEffect == null) return;
|
||||
|
||||
activeEffects.putIfAbsent(target, new ArrayList<>());
|
||||
List<StatusEffect> effects = activeEffects.get(target);
|
||||
|
||||
for (StatusEffect existing : effects) {
|
||||
|
||||
if (existing.getName().equals(newEffect.getName())) {
|
||||
|
||||
|
||||
if (existing.getStackType() == null) {
|
||||
return;
|
||||
} else if (existing.getStackType() == StatusEffect.StackType.duration) {
|
||||
|
||||
existing.setDuration(existing.getDuration() + newEffect.getDuration());
|
||||
|
||||
} else if (existing.getStackType() == StatusEffect.StackType.damage) {
|
||||
|
||||
existing.setDamage(existing.getDamage()+ newEffect.getDamage());
|
||||
|
||||
} else if (existing.getStackType() == StatusEffect.StackType.both) {
|
||||
|
||||
existing.setDamage(existing.getDamage()+ newEffect.getDamage());
|
||||
existing.setDuration(existing.getDuration() + newEffect.getDuration());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
effects.add(newEffect);
|
||||
newEffect.onApply(target);
|
||||
}
|
||||
|
||||
|
||||
public void tick(Entity target) {
|
||||
|
||||
List<StatusEffect> effects = activeEffects.get(target);
|
||||
if (effects == null) return;
|
||||
|
||||
Iterator<StatusEffect> iterator = effects.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
|
||||
StatusEffect effect = iterator.next();
|
||||
|
||||
effect.onTick(target);
|
||||
effect.reduceDuration();
|
||||
|
||||
if (effect.getDuration() <= 0) {
|
||||
effect.onExpire(target);
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasEffect(Entity target, String name) {
|
||||
|
||||
List<StatusEffect> effects = activeEffects.get(target);
|
||||
if (effects == null) return false;
|
||||
|
||||
for (StatusEffect effect : effects) {
|
||||
if (effect.getName().equals(name))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.project.weaponEffects;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
|
||||
public class BurnEffect extends StatusEffect{
|
||||
|
||||
|
||||
public BurnEffect() {
|
||||
super("Burn", 10,5 , 3, StackType.damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApply(Entity target) {
|
||||
System.out.println(target.getName() + " is burned!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.project.weaponEffects;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
|
||||
public class FreezeEffect extends StatusEffect{
|
||||
|
||||
public FreezeEffect() {
|
||||
super("Freeze",1,5 , 1, StatusEffect.StackType.damage);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onTick(Entity target) {
|
||||
target.freeze();
|
||||
super.onTick(target);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExpire(Entity target) {
|
||||
System.out.println(target.getName() + " is Frozen!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.project.weaponEffects;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
|
||||
public class PoisonEffect extends StatusEffect{
|
||||
|
||||
|
||||
public PoisonEffect() {
|
||||
super("Poison",10,5 , 3, StackType.damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onApply(Entity target) {
|
||||
System.out.println(target.getName() + " is poisoned!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package org.project.weaponEffects;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
|
||||
public abstract class StatusEffect {
|
||||
|
||||
public enum StackType {
|
||||
|
||||
none, // this effect is not stackable
|
||||
duration, // in duplication, just duration increases
|
||||
damage,// in duplication, just damage increases
|
||||
both // increases duration and damage
|
||||
}
|
||||
|
||||
protected String name;
|
||||
private int duration;
|
||||
private int equipManaCost;
|
||||
protected int damage;
|
||||
protected StackType stackType;
|
||||
|
||||
|
||||
public StatusEffect(String name, int damage, int equipManaCost, int duration, StackType stackType) {
|
||||
this.name = name;
|
||||
this.damage = damage;
|
||||
this.equipManaCost = equipManaCost;
|
||||
this.duration = duration;
|
||||
this.stackType = stackType;
|
||||
}
|
||||
|
||||
public String getName() { return name; }
|
||||
|
||||
public int getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
public void setDamage(int damage) {
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
public int getDuration() { return duration; }
|
||||
|
||||
public void setDuration(int duration) {
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public StackType getStackType() { return stackType; }
|
||||
|
||||
public int getEquipManaCost() {
|
||||
return equipManaCost;
|
||||
}
|
||||
|
||||
public void reduceDuration() {
|
||||
duration--;
|
||||
}
|
||||
|
||||
public void onApply(Entity target) {}
|
||||
|
||||
public void onTick(Entity target) {
|
||||
target.takeDamage(damage);
|
||||
System.out.println(target.getName() + " suffers " + damage + " damage form " + name);
|
||||
reduceDuration();
|
||||
}
|
||||
|
||||
public void onExpire(Entity target) {System.out.println(target.getName() + " is no longer suffering form " + name);}
|
||||
}
|
||||
@@ -1,175 +1,348 @@
|
||||
# Fourth Assignment - Java Knight ⚔️
|
||||
A turn-based RPG with Roguelike elements which can be run in the terminal.
|
||||
# 🛡️ Java‑Knight RPG
|
||||
|
||||
### **Prologue: The Legend of Javanest**
|
||||
*For centuries, the land of Javanest lived in peace, until a magical Dragon attacked, plunging the realm into absolute darkness. With a wicked curse, the Dragon transformed the innocent people into horrific monsters: Goblins, Skeletons, and Vampires. Retreating to its impenetrable Castle, the Dragon divided the three keys to its lair and hid them among these cursed creatures. Now, it is your duty to step up and save the land. You must battle these monsters, recover the unique key from each monster type, and finally slay the Dragon to break the curse and restore peace to Javanest!*
|
||||
<p align="center">
|
||||
<img src="image.png" width="100%">
|
||||
</p>
|
||||
|
||||
### **Introduction**
|
||||
Welcome to **Java knight**, a turn-based RPG inspired by Roguelike games! In this assignment, you will develop a **text-based role-playing game (RPG)**. This project is designed to rigorously test your understanding of **Object-Oriented Programming (OOP) principles**.
|
||||
<p align="center">
|
||||
<img src="Logo.png" width="160">
|
||||
</p>
|
||||
|
||||
⚠️ **REQUIREMENT:** You **must** utilize all the OOP concepts you have learned so far—including *Inheritance, Interfaces, Abstract Classes, Encapsulation, Polymorphism, Overloading, and Overriding*. It is extremely important that you use everything in its right place. Your design and architecture will be graded based on how well you apply these principles to avoid code duplication and maintain a clean structure.
|
||||
A console‑based fantasy RPG written entirely in pure Java.
|
||||
|
||||
🎯 **Your goal is not just to complete the assignment but to learn and apply OOP effectively!**
|
||||
|
||||
### **What is a Turn-Based Game?**
|
||||
In this combat system, two sides - which are usually the player's side and the enemy's side - attack each other in turns. The side which is not attacking can perform actions to avoid or deflect the enemy's attack.
|
||||
|
||||
### **Core Mechanics:**
|
||||
- **Turn-based combat** – Players and monsters take turns attacking each other.
|
||||
- **Character classes with Unique Traits** – Players can choose from archetypes like **Knight, Assassin, or Wizard**, each starting with distinctly different base stats.
|
||||
- **Unified Mana/Stamina System** – All player classes use a unified resource (Mana/Stamina) to perform actions.
|
||||
- **Standardized Action Set** – Every player character has exactly 5 specific actions available during their turn.
|
||||
- **Experience & Leveling System** – Earn XP based on enemy strength to automatically level up and increase your base stats.
|
||||
- **Progression System** – You cannot fight the Dragon immediately. You must farm enemies for a chance to drop their specific key, collect all three, and grow stronger first.
|
||||
Fight monsters, explore mythical locations, manage your inventory, unlock abilities and defeat the Dragon of Valhalla.
|
||||
|
||||
---
|
||||
|
||||
## Tasks 📝
|
||||
# 📚 Table of Contents
|
||||
|
||||
### 1️⃣ Step 1: Fork & Setup 🍴
|
||||
1. **Fork** this repository and clone it to your local machine.
|
||||
```bash
|
||||
git clone https://git.meshcomp.ir/AdvancedProgramming1404/HW-04-JAVA-KNIGHT.git
|
||||
```
|
||||
2. Create a new branch named `develop` and switch to it.
|
||||
```bash
|
||||
git checkout -b develop
|
||||
```
|
||||
### 2️⃣ Step 2: Implement the Class Hierarchy 🌲
|
||||
|
||||
A well-structured OOP hierarchy is crucial. Avoid duplicating code by placing shared logic in abstract classes.
|
||||
|
||||
- **Entities & Locations:** You have `Entity`, `Item`(Bonus) , and `Location`.
|
||||
- **Players:** `Player` is an abstract class implementing `Entity`. Subclasses: `Wizard`, `Knight`, `Assassin`.
|
||||
- **Base Stat Differences:** Each class must have distinct starting stats. For example:
|
||||
- **Knight:** Highest Base Damage.
|
||||
- **Wizard:** Highest Max Health (HP).
|
||||
- **Assassin:** Highest Max Stamina/Mana.
|
||||
- **Enemies:** `Enemy` is an abstract class implementing `Entity`. Subclasses: `Skeleton`, `Goblin`, `Vampire`, and **`Dragon`**.
|
||||
- **The Boss:** Even though `Dragon` is the final boss, it **must** be a subclass of `Enemy` to inherit common combat properties, while possessing extremely high stats and unique mechanics.
|
||||
- **Item (Bonus):** `Consumable`, `Armor`, `Weapon` are abstract classes implementing `Item`. example :
|
||||
- KnightArmor extends Armor - you can add more subclasses of Armor for extra score
|
||||
- Sword extends Weapon - you can add more subclasses of Weapon for extra score
|
||||
- Flask extends Consumable - you can add more subclasses of Consumable for extra score
|
||||
|
||||

|
||||
|
||||
### 3️⃣ Step 3: Implement Player & Monster Methods 🏹
|
||||
|
||||
**Player Actions (The Rule of Five):**
|
||||
Every player class **must** implement exactly the following 5 actions (You can use an interface like `ICombatActions`). Every action (except Light Attack) consumes a specific amount of Mana/Stamina. The **Special Ability** must consume the *highest* amount of Mana compared to the others.
|
||||
1. **Light Attack:** Deals moderate damage and costs **NO Mana**. (Note: If the player runs out of Mana/Stamina, this is the ONLY action they can perform.)
|
||||
2. **Heavy Attack:** Deals high damage, medium Mana cost.
|
||||
3. **Defend:** Completely blocks or significantly reduces the damage of the enemy's *next* strike. Medium Mana cost.
|
||||
4. **Heal:** Restores a portion of the player's HP. Medium-high Mana cost.
|
||||
5. **Special Ability:** A unique class-based ultimate move (Highest Mana cost):
|
||||
- **Wizard** 🧙♂️: Casts a devastating spell that damages the enemy while simultaneously replenishing some HP.
|
||||
- **Assassin** 🗡️: Turns invisible, dodging the next incoming attack completely and guaranteeing a *Critical Hit* on their next turn.
|
||||
- **Knight** ⚔️: Performs a shield bash that stuns the enemy, forcing them to skip their next turn while dealing heavy damage.
|
||||
|
||||
**Monster Abilities:**
|
||||
- **Goblin** 👹: High critical hit chance but low health.
|
||||
- **Skeleton** ☠️: Can resurrect once per battle with 50% HP.
|
||||
- **Vampire** 🦇: Lifesteal ability – a portion of the damage it deals to the player is added back to its own health.
|
||||
- **Dragon (Final Boss)** 🐉: Immune to normal defense. Its fiery breath bypasses shields and deals massive damage.
|
||||
|
||||
🔹 Make sure each entity **prints messages** when performing actions. example output (while in combat) :
|
||||
|
||||
```bash
|
||||
You chose to FIGHT!
|
||||
|
||||
[Ser Duncan - 45/45 HP | 40/40 Mana]
|
||||
[Goblin - 30/30 HP]
|
||||
- Overview
|
||||
- Core Features
|
||||
- Player Classes
|
||||
- Systems & Managers
|
||||
- Items & Equipment
|
||||
- Combat System
|
||||
- Locations
|
||||
- Boss Fight
|
||||
- Project Structure
|
||||
- How to Run
|
||||
- Future Improvements
|
||||
- Example Output
|
||||
- Author
|
||||
|
||||
---
|
||||
|
||||
Your Turn:
|
||||
1. Light Attack | 2. Heavy Attack (-8 Mana) | 3. Defend (-6 Mana) | 4. Heal (-12 Mana) | 5. Shield Bash (-15 Mana)
|
||||
# ⚔️ Overview
|
||||
|
||||
Java‑Knight is a modular **turn‑based RPG engine** built with Java and object‑oriented design.
|
||||
|
||||
The project focuses on:
|
||||
|
||||
- Clean OOP architecture
|
||||
- Modular manager systems
|
||||
- Expandable combat mechanics
|
||||
- Class‑based gameplay
|
||||
- Status effect system
|
||||
- Inventory & equipment system
|
||||
|
||||
The **GameLoop** controls the main gameplay cycle including player actions, combat resolution and movement between locations.
|
||||
|
||||
---
|
||||
|
||||
# 🧩 Core Features
|
||||
|
||||
## 🎮 Gameplay Loop
|
||||
|
||||
The **GameLoop** manages:
|
||||
|
||||
- Player creation
|
||||
- Class selection
|
||||
- Location movement
|
||||
- Enemy spawning
|
||||
- Combat handling
|
||||
- Inventory usage
|
||||
|
||||
Locations are interconnected and enemies spawn dynamically.
|
||||
|
||||
---
|
||||
|
||||
# 🧙 Player Classes
|
||||
|
||||
Each class has its own stats, armor and special ability.
|
||||
|
||||
| Class | Ability | Description |
|
||||
|------|------|------|
|
||||
| Knight | Guardian Oath | Heals and increases damage |
|
||||
| Wizard | Arcane Storm | Powerful magic attack |
|
||||
| Assassin | Poison Dagger | Poison damage and burst attack |
|
||||
|
||||
---
|
||||
|
||||
# 🛠 Systems & Managers
|
||||
|
||||
The architecture separates game logic into managers.
|
||||
|
||||
| Manager | Responsibility |
|
||||
|------|------|
|
||||
| ActionDecisionManager | Handles combat decisions |
|
||||
| InventoryManager | Equipment & item usage |
|
||||
| ManaCostManager | Mana cost calculations |
|
||||
| SpecialAbilityManager | Executes abilities |
|
||||
| StatusEffectManager | Applies burn, poison, freeze |
|
||||
| TotalAttackCalculator | Calculates final damage |
|
||||
|
||||
This modular design keeps the **GameLoop clean and maintainable**.
|
||||
|
||||
---
|
||||
|
||||
# ⚗️ Items & Equipment
|
||||
|
||||
## ⚔ Weapons
|
||||
|
||||
- Sword
|
||||
- Dagger
|
||||
|
||||
Weapons can receive special effects.
|
||||
|
||||
---
|
||||
|
||||
## 🌫 Weapon Effects
|
||||
|
||||
| Effect | Description |
|
||||
|------|------|
|
||||
| BurnEffect | Damage over time |
|
||||
| FreezeEffect | Slows or freezes target |
|
||||
| PoisonEffect | Gradual HP drain |
|
||||
|
||||
---
|
||||
|
||||
## 🛡 Armor
|
||||
|
||||
Each class uses its own armor type.
|
||||
|
||||
Examples:
|
||||
|
||||
- KnightArmor
|
||||
- WizardArmor
|
||||
- AssassinArmor
|
||||
|
||||
Armor increases defense and survivability.
|
||||
|
||||
---
|
||||
|
||||
## 🧴 Consumables
|
||||
|
||||
Consumables are located in:
|
||||
|
||||
```
|
||||
org.project.item.consumables
|
||||
```
|
||||
|
||||
```bash
|
||||
→ Chose: Light Attack
|
||||
⚔️ Ser Duncan (Knight) used Light Attack! (0 Mana)
|
||||
Goblin took 10 damage!
|
||||
Goblin has 20/30 HP remaining.
|
||||
Ser Duncan Mana: 40/40
|
||||
Available items:
|
||||
|
||||
- **HealFlask** → restores HP
|
||||
- **ManaFlask** → restores MP
|
||||
|
||||
These can be used during gameplay from the **Inventory menu**.
|
||||
|
||||
---
|
||||
|
||||
# 🧠 Combat System
|
||||
|
||||
Combat is **turn‑based**.
|
||||
|
||||
Each round:
|
||||
|
||||
1. Status effects update
|
||||
2. Player action
|
||||
3. Enemy AI action
|
||||
|
||||
Features:
|
||||
|
||||
- Damage calculation system
|
||||
- Defense mechanics
|
||||
- Status effects
|
||||
- Ability cooldowns
|
||||
- Mana system
|
||||
- XP rewards
|
||||
- Key drop system
|
||||
|
||||
---
|
||||
|
||||
# 🗺 Locations
|
||||
|
||||
| Location | Description |
|
||||
|------|------|
|
||||
| Valhalla | Starting realm |
|
||||
| Elysium | Sacred plains |
|
||||
| Niflheim | Frozen undead land |
|
||||
| Castle | Dragon battlefield |
|
||||
|
||||
Moving between locations spawns enemies:
|
||||
|
||||
- Goblin
|
||||
- Skeleton
|
||||
- Vampire
|
||||
|
||||
---
|
||||
|
||||
# 🐉 Boss Fight
|
||||
|
||||
To unlock the final boss you must collect:
|
||||
|
||||
- GoblinKey
|
||||
- SkeletonKey
|
||||
- VampireKey
|
||||
|
||||
After collecting all keys you can trigger:
|
||||
|
||||
```
|
||||
Fight Dragon
|
||||
```
|
||||
Goblin's Turn :
|
||||
👹 Goblin used Critical Strike!
|
||||
💥 Critical hit! Ser Duncan took 20 damage!
|
||||
Ser Duncan has 25/45 HP remaining.
|
||||
```
|
||||
🔹 *Narrative Console:* Use ANSI escape codes to print colorful narrative logs (e.g., Red for damage, Blue for Mana usage, Green for healing).
|
||||
|
||||
Defeat the **Dragon of Valhalla** to win the game.
|
||||
|
||||
### 4️⃣ Step 4: Implement the Game Loop & Progression 🎮
|
||||
---
|
||||
|
||||
1. **The Core Loop:** The game starts with the player entering a location. A random standard enemy (`Goblin`, `Skeleton`, or `Vampire`) spawns immediately.
|
||||
2. **Player Choices:** Before engaging, the player is presented with the following options:
|
||||
- **1. Fight the enemy:** Enter the turn-based combat sequence.
|
||||
- **2. Move to another location:** Skip the current enemy and spawn a new random one.
|
||||
- **3. Go to the Castle to fight the Dragon:** *(Note: This option must remain strictly hidden or locked until the player has successfully collected all 3 keys).*
|
||||
3. **The Key Drop Logic (RNG Gatekeeping):**
|
||||
- When the player defeats an enemy, there is a **specific percentage chance (e.g., 20%)** that it will drop the unique key associated with its species (Goblin Key, Skeleton Key, Vampire Key).
|
||||
- **One Key Per Species:** Once a player obtains a specific key (e.g., Goblin Key), subsequent enemies of that same type (other Goblins) will **never** drop a key again.
|
||||
- The player **must collect all 3 distinct keys** to unlock Option 3 and enter the Castle.
|
||||
4. **Post-Combat Recovery:** After each successful battle, the player's HP and Mana bars must automatically replenish (either fully or partially) to their base amounts so they are ready for the next encounter.
|
||||
5. **Experience & Leveling System:**
|
||||
- Defeating an enemy grants **XP**. The amount of XP must scale proportionally to the enemy's power level.
|
||||
- Upon reaching an XP threshold, the player levels up. **Leveling up must automatically increase the player's Max HP and Max Stamina/Mana**, making them strong enough to eventually face the Dragon.
|
||||
6. **Final Boss Fight:** Once the 3 Keys are obtained and the player chooses to go to the Castle, they will face the Dragon. Defeating the Dragon breaks the curse, resulting in **Victory**. Dying at any point results in **Game Over**.
|
||||
# 🎨 Console Colors
|
||||
|
||||
🔹 Example game loop structure:
|
||||
ANSI colors are used for better terminal visuals.
|
||||
|
||||
```java
|
||||
while (player.isAlive() && enemy.isAlive())
|
||||
player.attack(enemy);
|
||||
if (enemy.isAlive()) {
|
||||
enemy.attack(player);
|
||||
}
|
||||
}
|
||||
Colors.RED = "\u001B[31m";
|
||||
Colors.GREEN = "\u001B[32m";
|
||||
Colors.YELLOW = "\u001B[33m";
|
||||
Colors.CYAN = "\u001B[36m";
|
||||
Colors.RESET = "\u001B[0m";
|
||||
```
|
||||
|
||||
Example:
|
||||
|
||||
### 5️⃣ Step 5: Extra Features & Bonus Tasks ⭐
|
||||
*(Optional for extra credit)*
|
||||
|
||||
✅ **Dynamic Economy & Merchant System:** Implement coins that drop from enemies. Add a "Visit Merchant" option to the main loop where players can spend coins to buy specific weapons, armors, or consumables.
|
||||
✅ **Multiple Weapons & Inventory:** Players can buy, store, and swap between multiple weapons or use consumables mid-combat.
|
||||
✅ **Multiplayer/Party Mode:** Allow multiple players to team up and fight multiple enemies together. The Dragon's breath attack will damage the entire party simultaneously.
|
||||
✅ **PvP Mode:** Implement a **Player vs. Player** combat system.
|
||||
|
||||
### 6️⃣ Step 6: Write a Comprehensive README 📄
|
||||
As the final mandatory step of your development, you must replace the default `README.md` with your own comprehensive documentation. Your README should include:
|
||||
- A brief introduction to the game.
|
||||
- How to compile and run your project from the terminal.
|
||||
- An explanation of the classes, design patterns, and OOP principles you used.
|
||||
- A brief guide on how to play (controls, stats, classes).
|
||||
```
|
||||
Guardian Oath: Sir Duncan heals +5 HP and gains 50% increased damage.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Evaluation Criteria ⚖
|
||||
# 🧩 Project Structure
|
||||
|
||||
| **Criteria** | **Points** |
|
||||
|-------------------------------------------------------------|------------|
|
||||
| Proper use of OOP principles | **50** |
|
||||
| Working combat mechanics, Leveling System & Enemy abilities | **20** |
|
||||
| Clear and Comprehensive `README.md` | **20** |
|
||||
| Code readability, documentation, and comments | **10** |
|
||||
| Meaningful, interactive, & colored console outputs | **10** |
|
||||
| Inventory (item) and Merchant System (bonus) | **20** |
|
||||
| Other Extra features (bonus tasks) | **20** |
|
||||
| **Total Score** | **150** |
|
||||
```
|
||||
org.project
|
||||
┣ abilities
|
||||
┃ ┣ ArcaneStorm.java
|
||||
┃ ┣ BoneStrike.java
|
||||
┃ ┣ GuardianOath.java
|
||||
┃ ┣ InfernoBreath.java
|
||||
┃ ┣ LifeSteal.java
|
||||
┃ ┣ PoisonDagger.java
|
||||
┃ ┗ SpecialAbility.java
|
||||
┣ combat
|
||||
┃ ┣ AttackResult.java
|
||||
┃ ┗ TotalAttackCalculator.java
|
||||
┣ entity
|
||||
┃ ┣ players
|
||||
┃ ┗ enemies
|
||||
┣ item
|
||||
┃ ┣ armors
|
||||
┃ ┣ weapons
|
||||
┃ ┗ consumables
|
||||
┣ managers
|
||||
┃ ┣ InventoryManager.java
|
||||
┃ ┣ ActionDecisionManager.java
|
||||
┃ ┣ ManaCostManager.java
|
||||
┃ ┣ SpecialAbilityManager.java
|
||||
┃ ┗ StatusEffectManager.java
|
||||
┣ weaponEffects
|
||||
┃ ┣ BurnEffect.java
|
||||
┃ ┣ FreezeEffect.java
|
||||
┃ ┗ PoisonEffect.java
|
||||
┣ location
|
||||
┃ ┗ Location.java
|
||||
┣ Colors.java
|
||||
┣ GameLoop.java
|
||||
┗ Main.java
|
||||
```
|
||||
|
||||
## Tips 🚀
|
||||
- **Follow OOP principles**: Avoid redundant code by using inheritance properly. Think carefully about what belongs in an abstract class vs. a specific subclass. Make sure you use overriding and overloading correctly.
|
||||
- **Test your code**: Run different scenarios (fighting, running out of mana, leveling up, dying) to ensure everything works as expected.
|
||||
- **Ask for help**: If you're stuck, reach out to your classmates or mentors.
|
||||
---
|
||||
|
||||
## Submission ⌛
|
||||
- **Deadline**: Submit your assignment before **21 Ordibehesht (May 11th, 2026)**.
|
||||
- **Submission Format**: Push your code to your forked repository, create a PR, and ensure your comprehensive `README.md` is included in the root directory.
|
||||
# 🚀 How to Run
|
||||
|
||||

|
||||
###### - Born of God and Void. You shall seal the blinding light that plagues their dreams. You are the Vessel. You are the Java Knight.
|
||||
Compile the project:
|
||||
|
||||
```
|
||||
javac -d out src/main/java/org/project/Main.java
|
||||
```
|
||||
|
||||
Run the game:
|
||||
|
||||
```
|
||||
java -cp out org.project.Main
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# 💬 Example Console Output
|
||||
|
||||
```
|
||||
====== JAVA KNIGHT ======
|
||||
Choose class:
|
||||
1. Knight (HP:150 MP:80 DMG:12)
|
||||
2. Wizard (HP:80 MP:200 DMG:10)
|
||||
3. Assassin (HP:90 MP:120 DMG:15)
|
||||
|
||||
1
|
||||
==== GAME MENU ====
|
||||
Location: Valhalla
|
||||
Enemy: vampire{MAX_HP : 90 | MAX_MP : 80 | XP_REWARD : 80 | BASE_DAMAGE : 12 | personalArmor = vampire armor | Type: MEDIUM | Defense: 16 | Durability: 30/30}
|
||||
|
||||
1. Fight
|
||||
2. Inventory
|
||||
3. Move
|
||||
0. Exit
|
||||
|
||||
1
|
||||
⚔ COMBAT STARTED! ⚔
|
||||
==== YOUR TURN ====
|
||||
Sir Duncan-> HP: 150 | MP: 80 | level: 1 | XP: 0
|
||||
Vampire-> HP: 90 | MP: 80
|
||||
|
||||
|
||||
Choose attack type:
|
||||
|
||||
1.lightAttack
|
||||
2.heavyAttack
|
||||
3.heal
|
||||
4.defend
|
||||
5.ability
|
||||
6.shielBash
|
||||
7.inventory
|
||||
2
|
||||
Vampire got 34 damage
|
||||
|
||||
|
||||
==== ENEMY TURN ====
|
||||
|
||||
enemy random choose action: lightAttack
|
||||
Sir Duncan got 17 damage
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# 🧠 Future Improvements
|
||||
|
||||
- Multiple enemies per location
|
||||
- Save / Load system
|
||||
- More consumables
|
||||
- More classes
|
||||
- Advanced enemy AI
|
||||
- Graphical version (JavaFX / LWJGL)
|
||||
|
||||
---
|
||||
|
||||
# 🧑💻 Author
|
||||
|
||||
Created by **Mohammadreza Ashrafian**
|
||||
|
||||
2026
|
||||
|
||||
⚔️ *May your code be strong and your armor unbreakable.*
|
||||
|
||||
Reference in New Issue
Block a user