From 1f16d21aa62b32a60fbb149b007f12000644ebcd Mon Sep 17 00:00:00 2001 From: navid Date: Wed, 13 May 2026 14:14:25 +0330 Subject: [PATCH 1/2] Exercise 4 --- .../src/main/java/org/project/Main.java | 226 +++++++++++++++++- .../main/java/org/project/entity/Entity.java | 13 +- .../org/project/entity/enemies/Dragon.java | 26 ++ .../org/project/entity/enemies/Enemy.java | 65 ++++- .../org/project/entity/enemies/Goblin.java | 37 +++ .../org/project/entity/enemies/Skeleton.java | 39 ++- .../org/project/entity/enemies/Vampire.java | 23 ++ .../org/project/entity/players/Assassin.java | 74 ++++++ .../org/project/entity/players/Knight.java | 69 +++++- .../org/project/entity/players/Player.java | 76 +++--- .../org/project/entity/players/Wizard.java | 69 ++++++ .../src/main/java/org/project/item/Item.java | 11 - .../java/org/project/item/armors/Armor.java | 42 ---- .../org/project/item/armors/KnightArmor.java | 6 - .../project/item/consumables/Consumable.java | 8 - .../org/project/item/consumables/Flask.java | 16 -- .../java/org/project/item/weapons/Sword.java | 26 -- .../java/org/project/item/weapons/Weapon.java | 35 --- .../java/org/project/location/Location.java | 1 + .../target/classes/org/project/Main.class | Bin 0 -> 8134 bytes .../classes/org/project/entity/Entity.class | Bin 0 -> 392 bytes .../org/project/entity/enemies/Dragon.class | Bin 0 -> 853 bytes .../org/project/entity/enemies/Enemy.class | Bin 0 -> 1683 bytes .../org/project/entity/enemies/Goblin.class | Bin 0 -> 1086 bytes .../org/project/entity/enemies/Skeleton.class | Bin 0 -> 1012 bytes .../org/project/entity/enemies/Vampire.class | Bin 0 -> 808 bytes .../org/project/entity/players/Assassin.class | Bin 0 -> 2058 bytes .../org/project/entity/players/Knight.class | Bin 0 -> 1931 bytes .../org/project/entity/players/Player.class | Bin 0 -> 2591 bytes .../org/project/entity/players/Wizard.class | Bin 0 -> 1932 bytes .../org/project/location/Location.class | Bin 0 -> 1239 bytes 31 files changed, 661 insertions(+), 201 deletions(-) create mode 100644 Java-Knight/src/main/java/org/project/entity/enemies/Dragon.java create mode 100644 Java-Knight/src/main/java/org/project/entity/enemies/Goblin.java create mode 100644 Java-Knight/src/main/java/org/project/entity/enemies/Vampire.java create mode 100644 Java-Knight/src/main/java/org/project/entity/players/Assassin.java create mode 100644 Java-Knight/src/main/java/org/project/entity/players/Wizard.java delete mode 100644 Java-Knight/src/main/java/org/project/item/Item.java delete mode 100644 Java-Knight/src/main/java/org/project/item/armors/Armor.java delete mode 100644 Java-Knight/src/main/java/org/project/item/armors/KnightArmor.java delete mode 100644 Java-Knight/src/main/java/org/project/item/consumables/Consumable.java delete mode 100644 Java-Knight/src/main/java/org/project/item/consumables/Flask.java delete mode 100644 Java-Knight/src/main/java/org/project/item/weapons/Sword.java delete mode 100644 Java-Knight/src/main/java/org/project/item/weapons/Weapon.java create mode 100644 Java-Knight/target/classes/org/project/Main.class create mode 100644 Java-Knight/target/classes/org/project/entity/Entity.class create mode 100644 Java-Knight/target/classes/org/project/entity/enemies/Dragon.class create mode 100644 Java-Knight/target/classes/org/project/entity/enemies/Enemy.class create mode 100644 Java-Knight/target/classes/org/project/entity/enemies/Goblin.class create mode 100644 Java-Knight/target/classes/org/project/entity/enemies/Skeleton.class create mode 100644 Java-Knight/target/classes/org/project/entity/enemies/Vampire.class create mode 100644 Java-Knight/target/classes/org/project/entity/players/Assassin.class create mode 100644 Java-Knight/target/classes/org/project/entity/players/Knight.class create mode 100644 Java-Knight/target/classes/org/project/entity/players/Player.class create mode 100644 Java-Knight/target/classes/org/project/entity/players/Wizard.class create mode 100644 Java-Knight/target/classes/org/project/location/Location.class diff --git a/Java-Knight/src/main/java/org/project/Main.java b/Java-Knight/src/main/java/org/project/Main.java index 6bde20e..23be10a 100644 --- a/Java-Knight/src/main/java/org/project/Main.java +++ b/Java-Knight/src/main/java/org/project/Main.java @@ -1,15 +1,231 @@ package org.project; import org.project.location.Location; +import org.project.entity.Entity; +import org.project.entity.enemies.*; +import org.project.entity.players.*; import java.util.ArrayList; import java.util.List; +import java.util.Random; +import java.util.Scanner; public class Main { - public static void main(String[] args) { - // TODO: ADD LOCATIONS TO YOUR GAME - List locations = new ArrayList<>(); + private static Scanner scanner = new Scanner(System.in); + private static Player player; + private static boolean hasGoblinKey = false; + private static boolean hasSkeletonKey = false; + private static boolean hasVampireKey = false; + private static int currentLocationIndex = 0; + private static List locations = new ArrayList<>(); + private static String[] locationNames = {"Forest", "Cemetery", "Crypt", "Ruins"}; - // TODO: IMPLEMENT GAMEPLAY + + public static void main(String[] args) { + for (int i = 0; i < locationNames.length; i++) { + locations.add(new Location(new ArrayList<>(), new ArrayList<>())); + } + + System.out.println("Welcome to Java Knight"); + System.out.println("Choose your class:"); + System.out.println("1. Knight"); + System.out.println("2. Assassin"); + System.out.println("3. Wizard"); + int choice = readInt("Choice: ", 1, 3); + + switch (choice) { + case 1: + player = new Knight("Arthur", 60, 40, 60, 40, + 12, 24, 8, 20, 10); + break; + case 2: + player = new Assassin("Layla", 45, 55, 45, 55, + 8, 18, 8, 15, 10); + break; + case 3: + player = new Wizard("Merlin", 70, 50, 70, 50, + 6, 14, 8, 25, 10); + break; + } + + System.out.println(player.getName() + " starts the journey."); + System.out.println("Collect three keys (Goblin, Skeleton, Vampire) then face the Dragon.\n"); + + while (player.isAlive()) { + System.out.println("\nYou are in " + locationNames[currentLocationIndex] + "."); + Enemy currentEnemy = spawnRandomEnemyForLocation(); + System.out.println("A " + currentEnemy.getClass().getSimpleName() + " appears!"); + + // Menu for the location + boolean actionDone = false; + while (!actionDone && player.isAlive()) { + System.out.println("\nWhat do you want to do?"); + System.out.println("1. Fight the enemy"); + System.out.println("2. Move to another location"); + if (hasGoblinKey && hasSkeletonKey && hasVampireKey) { + System.out.println("3. Go to the Castle to fight the Dragon"); + } + int action = readInt("Choose: ", 1, (hasGoblinKey && hasSkeletonKey && hasVampireKey) ? 3 : 2); + + if (action == 1) { + // Fight + boolean enemyDefeated = false; + while (!enemyDefeated && player.isAlive()) { + printStatus(currentEnemy); + int combatAction = showCombatMenu(); + executePlayerAction(combatAction, currentEnemy); + if (!currentEnemy.isAlive()) { + enemyDefeated = true; + break; + } + if (!player.isAlive()) break; + enemyTurn(currentEnemy); + } + if (!player.isAlive()) { + System.out.println("You died. Game over."); + return; + } + // Victory handling + handleVictory(currentEnemy); + actionDone = true; + // Full restore after fight + player.fillMana(player.getMaxMP()); + player.heal(player.getMaxHP() - player.getHp()); + System.out.println("Your health and mana are fully restored."); + } else if (action == 2) { + // Move to random different location + int newIndex = currentLocationIndex; + while (newIndex == currentLocationIndex) { + newIndex = new Random().nextInt(locations.size()); + } + currentLocationIndex = newIndex; + System.out.println("You move to " + locationNames[currentLocationIndex] + "."); + actionDone = true; // enemy respawns in new location automatically in next loop iteration + } else if (action == 3) { + // Go to castle + fightDragon(); + if (!player.isAlive()) { + System.out.println("You died. Game over."); + return; + } + System.out.println("You defeated the Dragon! The curse is lifted. Victory!"); + return; + } + } + } + } + + private static Enemy spawnRandomEnemyForLocation() { + Random rand = new Random(); + int type = rand.nextInt(3); + switch (type) { + case 0: return new Goblin(40, 20, 14); + case 1: return new Skeleton(50, 20, 12); + default: return new Vampire(55, 25, 16); + } + } + + private static void printStatus(Enemy enemy) { + System.out.println("\n" + player.getName() + ": " + player.getHp() + "/" + player.getMaxHP() + + " HP, " + player.getMp() + "/" + player.getMaxMP() + " Mana"); + System.out.println(enemy.getClass().getSimpleName() + ": " + enemy.getHp() + " HP"); + } + + private static int showCombatMenu() { + System.out.println("\nYour turn:"); + System.out.println("1. Light Attack (0 mana)"); + System.out.println("2. Heavy Attack (8 mana)"); + System.out.println("3. Defend (6 mana)"); + System.out.println("4. Heal (10 mana)"); + System.out.println("5. Special Ability (15 mana)"); + return readInt("Choose: ", 1, 5); + } + + private static void executePlayerAction(int action, Entity target) { + switch (action) { + case 1: + player.LightAttack(target, 0); + System.out.println("Light attack performed."); + break; + case 2: + player.HeavyAttack(target, 0); + System.out.println("Heavy attack performed."); + break; + case 3: + System.out.println(player.defend()); + break; + case 4: + player.heal(0); + System.out.println("Heal attempted."); + break; + case 5: + player.SpecialAbility(target); + System.out.println("Special ability used."); + break; + } + } + + private static void enemyTurn(Enemy enemy) { + System.out.println(enemy.getClass().getSimpleName() + "'s turn:"); + Random rand = new Random(); + int dmg = 0; + if (enemy instanceof Goblin) dmg = ((Goblin) enemy).getAttackDamage(); + else if (enemy instanceof Skeleton) dmg = ((Skeleton) enemy).getAttackDamage(); + else if (enemy instanceof Vampire) dmg = ((Vampire) enemy).getAttackDamage(); + + if (rand.nextDouble() < 0.7) { + enemy.LightAttack(player, dmg); + System.out.println(enemy.getClass().getSimpleName() + " attacks!"); + } else { + enemy.SpecialAbility(player); + System.out.println(enemy.getClass().getSimpleName() + " uses special ability!"); + } + } + + private static void handleVictory(Enemy enemy) { + System.out.println(enemy.getClass().getSimpleName() + " defeated!"); + Random rand = new Random(); + int chance = rand.nextInt(100); + if (enemy instanceof Goblin && !hasGoblinKey && chance < 20) { + hasGoblinKey = true; + System.out.println("You obtained the Goblin Key!"); + } else if (enemy instanceof Skeleton && !hasSkeletonKey && chance < 20) { + hasSkeletonKey = true; + System.out.println("You obtained the Skeleton Key!"); + } else if (enemy instanceof Vampire && !hasVampireKey && chance < 20) { + hasVampireKey = true; + System.out.println("You obtained the Vampire Key!"); + } + System.out.println("Keys status: Goblin=" + hasGoblinKey + " Skeleton=" + hasSkeletonKey + " Vampire=" + hasVampireKey); + } + + private static void fightDragon() { + Dragon dragon = new Dragon(180, 100, 45); + System.out.println("Dragon appears! Final battle begins."); + while (player.isAlive() && dragon.isAlive()) { + printStatus(dragon); + int action = showCombatMenu(); + executePlayerAction(action, dragon); + if (!dragon.isAlive()) break; + if (!player.isAlive()) break; + System.out.println("Dragon uses fiery breath!"); + dragon.SpecialAbility(player); + System.out.println("Dragon deals " + dragon.getAttackDamage() * 2 + " damage ignoring defense."); + } + } + + private static int readInt(String prompt, int min, int max) { + int value; + while (true) { + System.out.print(prompt); + if (scanner.hasNextInt()) { + value = scanner.nextInt(); + if (value >= min && value <= max) return value; + else System.out.println("Enter number between " + min + " and " + max); + } else { + System.out.println("Invalid input. Enter a number."); + scanner.next(); + } + } + } } -} \ No newline at end of file diff --git a/Java-Knight/src/main/java/org/project/entity/Entity.java b/Java-Knight/src/main/java/org/project/entity/Entity.java index 2a060f9..ca98b74 100644 --- a/Java-Knight/src/main/java/org/project/entity/Entity.java +++ b/Java-Knight/src/main/java/org/project/entity/Entity.java @@ -1,9 +1,8 @@ package org.project.entity; public interface Entity { - void attack(Entity target); - void defend(); + String defend(); void heal(int health); @@ -15,7 +14,11 @@ public interface Entity { int getMaxMP(); - /* - TODO: ADD OTHER REQUIRED AND BONUS METHODS - */ + void LightAttack(Entity target, int damage); + + void HeavyAttack(Entity target, int damage); + boolean isAlive(); + int getHp(); + int getMp(); + } diff --git a/Java-Knight/src/main/java/org/project/entity/enemies/Dragon.java b/Java-Knight/src/main/java/org/project/entity/enemies/Dragon.java new file mode 100644 index 0000000..9a2509a --- /dev/null +++ b/Java-Knight/src/main/java/org/project/entity/enemies/Dragon.java @@ -0,0 +1,26 @@ +package org.project.entity.enemies; + +import org.project.entity.Entity; + + +public class Dragon extends Enemy{ + private final int attackDamage; + + public Dragon(int hp, int mp, int attackDamage){ + super(hp, mp); + this.attackDamage = attackDamage; + } + public int getAttackDamage(){ + return attackDamage; + } + + @Override + public void SpecialAbility(Entity target) { + target.takeDamage(attackDamage*2); + + } + @Override + public String defend() { + return "dragon ignores defense"; + } +} diff --git a/Java-Knight/src/main/java/org/project/entity/enemies/Enemy.java b/Java-Knight/src/main/java/org/project/entity/enemies/Enemy.java index e019acb..17ce6ed 100644 --- a/Java-Knight/src/main/java/org/project/entity/enemies/Enemy.java +++ b/Java-Knight/src/main/java/org/project/entity/enemies/Enemy.java @@ -1,23 +1,59 @@ package org.project.entity.enemies; -import org.project.item.weapons.Weapon; +import org.project.entity.Entity; -// TODO: UPDATE IMPLEMENTATION -public abstract class Enemy { - Weapon weapon; - private int hp; - private int mp; - public Enemy(int hp, int mp, Weapon weapon) { +public abstract class Enemy implements Entity { + + protected int hp; + protected int mp; + protected int maxHp; + protected int maxMp; + + public Enemy(int hp, int mp) { this.hp = hp; this.mp = mp; + this.maxHp = hp; + this.maxMp = mp; - this.weapon = weapon; } @Override public void takeDamage(int damage) { hp -= damage; + if (hp < 0) hp = 0; + } + + @Override + public void LightAttack(Entity target, int damage) { + target.takeDamage(damage); + } + + @Override + public void HeavyAttack(Entity target, int damage) { + target.takeDamage(damage); + } + + public abstract void SpecialAbility(Entity target); + + @Override + public void heal(int health) { + hp += health; + } + + @Override + public void fillMana(int mana) { + mp += mana; + } + + @Override + public String defend() { + return "enemy defends"; + } + + @Override + public boolean isAlive() { + return hp > 0; } public int getHp() { @@ -28,7 +64,16 @@ public abstract class Enemy { return mp; } - public Weapon getWeapon() { - return weapon; + @Override + public int getMaxHP() { + return maxHp; } + + + @Override + public int getMaxMP() { + return maxMp; + } + + } diff --git a/Java-Knight/src/main/java/org/project/entity/enemies/Goblin.java b/Java-Knight/src/main/java/org/project/entity/enemies/Goblin.java new file mode 100644 index 0000000..03d36c1 --- /dev/null +++ b/Java-Knight/src/main/java/org/project/entity/enemies/Goblin.java @@ -0,0 +1,37 @@ + package org.project.entity.enemies; + + import org.project.entity.Entity; + + import java.util.Random; + + public class Goblin extends Enemy { + private final int attackDamage; + private Random random; + + public Goblin(int hp, int mp, int attackDamage) { + super(hp, mp); + this.attackDamage = attackDamage; + this.random = new Random(); + } + + public int getAttackDamage() { + return attackDamage; + } + + @Override + public void LightAttack(Entity target, int damage) { + int chance = random.nextInt(10) + 1; + if (chance <= 3) { + target.takeDamage(2 * attackDamage); + } else { + target.takeDamage(attackDamage); + } + } + + @Override + public void SpecialAbility(Entity target) { + + } + + + } diff --git a/Java-Knight/src/main/java/org/project/entity/enemies/Skeleton.java b/Java-Knight/src/main/java/org/project/entity/enemies/Skeleton.java index 8a6a555..f7c0820 100644 --- a/Java-Knight/src/main/java/org/project/entity/enemies/Skeleton.java +++ b/Java-Knight/src/main/java/org/project/entity/enemies/Skeleton.java @@ -1,6 +1,39 @@ package org.project.entity.enemies; -// TODO: UPDATE IMPLEMENTATION -public class Skeleton { - // TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR + +import org.project.entity.Entity; + + +public class Skeleton extends Enemy { + private final int attackDamage; + private boolean hasRevived; + + public Skeleton(int hp, int mp, int attackDamage) { + super(hp, mp); + this.attackDamage = attackDamage; + this.hasRevived = false; + } + + public int getAttackDamage() { + return attackDamage; + } + + @Override + public void takeDamage(int damage) { + super.takeDamage(damage); + if (!hasRevived && hp <= 0) { + hp = maxHp / 2; + hasRevived = true; + } + } + + @Override + public void SpecialAbility(Entity target) { + // Skeleton's revive is handled in takeDamage + } + + @Override + public boolean isAlive() { + return hp > 0; + } } diff --git a/Java-Knight/src/main/java/org/project/entity/enemies/Vampire.java b/Java-Knight/src/main/java/org/project/entity/enemies/Vampire.java new file mode 100644 index 0000000..e6f5572 --- /dev/null +++ b/Java-Knight/src/main/java/org/project/entity/enemies/Vampire.java @@ -0,0 +1,23 @@ +package org.project.entity.enemies; +import org.project.entity.Entity; + + +public class Vampire extends Enemy { + private final int attackDamage; + + public Vampire(int hp, int mp, int attackDamage) { + super(hp, mp); + this.attackDamage = attackDamage; + } + + public int getAttackDamage() { + return attackDamage; + } + + @Override + public void SpecialAbility(Entity target) { + int healAmount = (int)(0.3 * attackDamage); + heal(healAmount); + target.takeDamage(attackDamage); + } +} diff --git a/Java-Knight/src/main/java/org/project/entity/players/Assassin.java b/Java-Knight/src/main/java/org/project/entity/players/Assassin.java new file mode 100644 index 0000000..571a512 --- /dev/null +++ b/Java-Knight/src/main/java/org/project/entity/players/Assassin.java @@ -0,0 +1,74 @@ +package org.project.entity.players; + +import org.project.entity.Entity; + + +public class Assassin extends Player{ + + private final int lightAttackDamage; + private final int heavyAttackDamage; + private final int heavyAttackMana; + private final int healNumber; + private final int healMana; + private boolean invisible; + + public Assassin(String name, int hp, int mp,int maxHP,int maxMP, int lightAttackDamage, int heavyAttackDamage, int heavyAttackMana, int healNumber, int healMana){ + super(name, hp, mp, maxHP,maxMP); + this.lightAttackDamage = lightAttackDamage ; + this.heavyAttackDamage = heavyAttackDamage; + this.heavyAttackMana=heavyAttackMana ; + this.healNumber =healNumber ; + this.healMana=healMana ; + this.invisible = false; + } + + @Override + public void SpecialAbility(Entity target) { + if (mp >= heavyAttackMana + 10) { + invisible = true; + mp -= (heavyAttackMana + 10); + } + } + + @Override + public void LightAttack(Entity target, int damage) { + int dmg = invisible ? lightAttackDamage * 2 : lightAttackDamage; + target.takeDamage(dmg); + invisible = false; + } + + @Override + public void HeavyAttack(Entity target, int damage) { + if (mp >= heavyAttackMana) { + int dmg = invisible ? heavyAttackDamage * 2 : heavyAttackDamage; + target.takeDamage(dmg); + mp -= heavyAttackMana; + invisible = false; + } + } + + @Override + public void heal(int health) { + if (mp >= healMana) { + super.heal(healNumber); + mp -= healMana; + } + } + + public int getLightAttackDamage(){ + return lightAttackDamage; + } + public int getHeavyAttackDamage(){ + return heavyAttackDamage; + } + public int getHeavyAttackMana(){ + return heavyAttackMana; + } + public int getHealNumber(){ + return healNumber; + } + public int getHealMana(){ + return healMana; + } +} + diff --git a/Java-Knight/src/main/java/org/project/entity/players/Knight.java b/Java-Knight/src/main/java/org/project/entity/players/Knight.java index 14d8fa2..e5a7afb 100644 --- a/Java-Knight/src/main/java/org/project/entity/players/Knight.java +++ b/Java-Knight/src/main/java/org/project/entity/players/Knight.java @@ -1,6 +1,69 @@ package org.project.entity.players; -// TODO: UPDATE IMPLEMENTATION -public class Knight { - // TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR + +import org.project.entity.Entity; + + + +public class Knight extends Player { + private final int lightAttackDamage; + private final int heavyAttackDamage; + private final int heavyAttackMana; + private final int healNumber; + private final int healMana; + + public Knight(String name, int hp, int mp ,int maxHP,int maxMP,int lightAttackDamage,int heavyAttackDamage,int haeavyAttackMana,int healNumber,int healMana){ + super(name, hp, mp, maxHP,maxMP); + this.lightAttackDamage = lightAttackDamage ; + this.heavyAttackDamage = heavyAttackDamage; + this.heavyAttackMana=haeavyAttackMana ; + this.healNumber =healNumber ; + this.healMana=healMana ; + } + + @Override + public void SpecialAbility(Entity target) { + if (mp >= heavyAttackMana + 10) { + target.takeDamage(heavyAttackDamage); + mp -= (heavyAttackMana + 10); + } + } + + @Override + public void LightAttack(Entity target, int damage) { + target.takeDamage(lightAttackDamage); + } + + @Override + public void HeavyAttack(Entity target, int damage) { + if (mp >= heavyAttackMana) { + target.takeDamage(heavyAttackDamage); + mp -= heavyAttackMana; + } + } + + + @Override + public void heal(int health) { + if (mp >= healMana) { + super.heal(healNumber); + mp -= healMana; + } + } + + public int getLightAttackDamage(){ + return lightAttackDamage; + } + public int getHeavyAttackDamage(){ + return heavyAttackDamage; + } + public int getHeavyAttackMana(){ + return heavyAttackMana; + } + public int getHealNumber(){ + return healNumber; + } + public int getHealMana(){ + return healMana; + } } diff --git a/Java-Knight/src/main/java/org/project/entity/players/Player.java b/Java-Knight/src/main/java/org/project/entity/players/Player.java index ff5385c..5f66e7e 100644 --- a/Java-Knight/src/main/java/org/project/entity/players/Player.java +++ b/Java-Knight/src/main/java/org/project/entity/players/Player.java @@ -1,42 +1,43 @@ package org.project.entity.players; import org.project.entity.Entity; -import org.project.item.armors.Armor; -import org.project.item.weapons.Weapon; -// TODO: UPDATE IMPLEMENTATION -public abstract class Player { +public abstract class Player implements Entity { protected String name; - Weapon weapon; - Armor armor; - private int hp; - private int maxHP; - private int mp; - private int maxMP; + protected int hp; + protected int maxHP; + protected int mp; + protected int maxMP; + protected boolean isDefending; - public Player(String name, int hp, int mp, Weapon weapon, Armor armor) { + public Player(String name, int hp, int mp, int maxHP,int maxMP) { this.name = name; this.hp = hp; this.mp = mp; - - this.weapon = weapon; - this.armor = armor; + this.maxMP = maxMP; + this.maxHP = maxHP; + this.isDefending = false; } + @Override - public void attack(Entity target) { - target.takeDamage(weapon.getDamage()); + public String defend() { + if (mp >= 6) { + mp -= 6; + isDefending = true; + return name + " assumes defensive stance"; + } + return "not enough mana to defend"; } - @Override - public void defend() { - // TODO - } - - @Override public void takeDamage(int damage) { - hp -= damage - armor.getDefense(); + if (isDefending) { + damage = damage / 2; + isDefending = false; + } + hp -= damage; + if (hp < 0) hp = 0; } @Override @@ -55,6 +56,27 @@ public abstract class Player { } } + @Override + public void LightAttack(Entity target, int damage) { + target.takeDamage(damage); + } + + @Override + public void HeavyAttack(Entity target, int damage) { + if (mp >= 8) { + target.takeDamage(damage); + mp -= 8; + } + } + + + public abstract void SpecialAbility(Entity target); + + @Override + public boolean isAlive() { + return hp > 0; + } + public String getName() { return name; @@ -78,12 +100,4 @@ public abstract class Player { return maxMP; } - public Weapon getWeapon() { - return weapon; - } - - public Armor getArmor() { - return armor; - } - } diff --git a/Java-Knight/src/main/java/org/project/entity/players/Wizard.java b/Java-Knight/src/main/java/org/project/entity/players/Wizard.java new file mode 100644 index 0000000..1a91bbf --- /dev/null +++ b/Java-Knight/src/main/java/org/project/entity/players/Wizard.java @@ -0,0 +1,69 @@ +package org.project.entity.players; + +import org.project.entity.Entity; + + +public class Wizard extends Player { + private final int lightAttackDamage; + private final int heavyAttackDamage; + private final int heavyAttackMana; + private final int healNumber; + private final int healMana; + + public Wizard(String name, int hp, int mp,int maxHP,int maxMP, int lightAttackDamage, int heavyAttackDamage, int heavyAttackMana, int healNumber, int healMana){ + super(name, hp, mp, maxHP,maxMP); + this.lightAttackDamage = lightAttackDamage ; + this.heavyAttackDamage = heavyAttackDamage; + this.heavyAttackMana=heavyAttackMana ; + this.healNumber =healNumber ; + this.healMana=healMana ; + } + + @Override + public void SpecialAbility(Entity target) { + if (mp >= heavyAttackMana + 10) { + target.takeDamage(heavyAttackDamage + 10); + heal(healNumber); + mp -= (heavyAttackMana + 10); + } + } + + @Override + public void LightAttack(Entity target, int damage) { + target.takeDamage(lightAttackDamage); + } + + @Override + public void HeavyAttack(Entity target, int damage) { + if (mp >= heavyAttackMana) { + target.takeDamage(heavyAttackDamage); + mp -= heavyAttackMana; + } + } + + + @Override + public void heal(int health) { + if (mp >= healMana) { + super.heal(healNumber); + mp -= healMana; + } + } + + public int getLightAttackDamage(){ + return lightAttackDamage; + } + public int getHeavyAttackDamage(){ + return heavyAttackDamage; + } + public int getHeavyAttackMana(){ + return heavyAttackMana; + } + public int getHealNumber(){ + return healNumber; + } + public int getHealMana(){ + return healMana; + } +} + diff --git a/Java-Knight/src/main/java/org/project/item/Item.java b/Java-Knight/src/main/java/org/project/item/Item.java deleted file mode 100644 index 6d6b5ad..0000000 --- a/Java-Knight/src/main/java/org/project/item/Item.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.project.item; - -import org.project.entity.Entity; - -public interface Item { - void use(Entity target); - - /* - TODO: ADD OTHER REQUIRED AND BONUS METHODS - */ -} diff --git a/Java-Knight/src/main/java/org/project/item/armors/Armor.java b/Java-Knight/src/main/java/org/project/item/armors/Armor.java deleted file mode 100644 index 7ca8774..0000000 --- a/Java-Knight/src/main/java/org/project/item/armors/Armor.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.project.item.armors; - -// TODO: UPDATE IMPLEMENTATION -public abstract class Armor { - private int defense; - private int maxDefense; - private int durability; - private int maxDurability; - - private boolean isBroke; - - public Armor(int defense, int durability) { - this.defense = defense; - this.durability = durability; - } - - public void checkBreak() { - if (durability <= 0) { - isBroke = true; - defense = 0; - } - } - - // TODO: (BONUS) UPDATE THE REPAIR METHOD - public void repair() { - isBroke = false; - defense = maxDefense; - durability = maxDurability; - } - - public int getDefense() { - return defense; - } - - public int getDurability() { - return durability; - } - - public boolean isBroke() { - return isBroke; - } -} diff --git a/Java-Knight/src/main/java/org/project/item/armors/KnightArmor.java b/Java-Knight/src/main/java/org/project/item/armors/KnightArmor.java deleted file mode 100644 index eb59a46..0000000 --- a/Java-Knight/src/main/java/org/project/item/armors/KnightArmor.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.project.item.armors; - -// TODO: UPDATE IMPLEMENTATION -public class KnightArmor { - // TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR -} \ No newline at end of file diff --git a/Java-Knight/src/main/java/org/project/item/consumables/Consumable.java b/Java-Knight/src/main/java/org/project/item/consumables/Consumable.java deleted file mode 100644 index 028e13d..0000000 --- a/Java-Knight/src/main/java/org/project/item/consumables/Consumable.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.project.item.consumables; - -// TODO: UPDATE IMPLEMENTATION -public abstract class Consumable { - /* - TODO: ADD OTHER REQUIRED AND BONUS METHODS - */ -} diff --git a/Java-Knight/src/main/java/org/project/item/consumables/Flask.java b/Java-Knight/src/main/java/org/project/item/consumables/Flask.java deleted file mode 100644 index c0e7a6d..0000000 --- a/Java-Knight/src/main/java/org/project/item/consumables/Flask.java +++ /dev/null @@ -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); - } -} diff --git a/Java-Knight/src/main/java/org/project/item/weapons/Sword.java b/Java-Knight/src/main/java/org/project/item/weapons/Sword.java deleted file mode 100644 index 96226ee..0000000 --- a/Java-Knight/src/main/java/org/project/item/weapons/Sword.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.project.item.weapons; - -import org.project.entity.Entity; - -import java.util.ArrayList; - -// TODO: UPDATE IMPLEMENTATION -public class Sword { - /* - THIS IS AN EXAMPLE OF A WEAPON DESIGN. - */ - - int abilityCharge; - - public Sword() { - // TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR - } - - // TODO: (BONUS) UPDATE THE UNIQUE ABILITY - public void uniqueAbility(ArrayList targets) { - abilityCharge += 2; - for (Entity target : targets) { - target.takeDamage(getDamage()); - } - } -} diff --git a/Java-Knight/src/main/java/org/project/item/weapons/Weapon.java b/Java-Knight/src/main/java/org/project/item/weapons/Weapon.java deleted file mode 100644 index cb9fcf2..0000000 --- a/Java-Knight/src/main/java/org/project/item/weapons/Weapon.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.project.item.weapons; - -import org.project.entity.Entity; - -// TODO: UPDATE IMPLEMENTATION -public abstract class Weapon { - private int damage; - private int manaCost; - - /* - TODO: ADD OTHER REQUIRED AND BONUS ATTRIBUTES - */ - - public Weapon(int damage, int manaCost) { - this.damage = damage; - this.manaCost = manaCost; - } - - @Override - public void use(Entity target) { - target.takeDamage(damage); - } - - public int getDamage() { - return damage; - } - - public int getManaCost() { - return manaCost; - } - - /* - TODO: ADD OTHER REQUIRED AND BONUS METHODS - */ -} diff --git a/Java-Knight/src/main/java/org/project/location/Location.java b/Java-Knight/src/main/java/org/project/location/Location.java index b0b4b98..440f27d 100644 --- a/Java-Knight/src/main/java/org/project/location/Location.java +++ b/Java-Knight/src/main/java/org/project/location/Location.java @@ -6,6 +6,7 @@ import java.util.ArrayList; public class Location { private String name; + private ArrayList locations; private ArrayList enemies; diff --git a/Java-Knight/target/classes/org/project/Main.class b/Java-Knight/target/classes/org/project/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..158ff170abc67acbbc5bc15ae1d6b9b9250f3cb8 GIT binary patch literal 8134 zcmai33w%`7ng4&2$;>d^gvo^P3XdB=NFpYJib!~cU?4&e2@M8c++=Q&fq8Xi0t~2C z)b&{()wV*drMlbHYFi98!K7NOrDglnzHGa#b#1r1+wDH;Zg*D}W&h{gJISzSX@0+Z z&z*C=bI$ktf8ROz_WQ#x1GrKi4Z?#WKfDHt;S+>*S$nMdn3d?Mzq)gm-IW#iRzwrg z>?%P~bxr#O1Tevmpn-`nNS;jh)Th!(MOoi!MH7OOShCB?Mw5xnR@}}A%CFlrwq{#4 z9ZmE!s8vc0OhQO7Ax}@*kVD#+jmGLXMKjq3Kf;1pg`4E5>o>XE_%WHA=q>cT#&p`s zsmVc2@l!?>L_?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v*nMz`oRvM%i*+{-pX3}!5_?f}sfbXrqZ-5tIZjL>deGgk~8yvlb!xFHnNdwWfNTqfU;;4(@Wqm1y!u*4t&zbhEF7YYBVUUv`T4G$^n0 z8O0CmSo?xD3T?lPGnt~@c--sBr91^m%zo;R?;eYY%8BL`n=tneQ0 e+x~}mu%vuyW5B6zeEd(%_Frn8Yc&ro>d|ldTBJt+ literal 0 HcmV?d00001 diff --git a/Java-Knight/target/classes/org/project/entity/enemies/Enemy.class b/Java-Knight/target/classes/org/project/entity/enemies/Enemy.class new file mode 100644 index 0000000000000000000000000000000000000000..f86614e742784361228570b3e14a63eaa64db148 GIT binary patch literal 1683 zcma)5TTc^F5dKcPz0h_mf`VAoinq2Z^?rjGQ8A#cnqWvYK6q%?c4d1>S&94?27rRBF>f@f+G4g4|e9K~veP1q~GZmidJKP1W4+*aFP@a0zFP$`Nm zm}btjnDq6a$`bC>x={pTqdkbr>$EQ#@_^&!fiMFFXwk^hQE2N*h zo>$jhO_4grBm?yn_LR!C-`la`58Q5x6Q|sb1<&22c-)UC)R0JFaM-F$*&*C9K0-j~Emez~Yaq#$~l+d5q=O7|UIuwV9W|L7s;g zt;;^sPE|fbRSKVws!V@^E#9bj;~)4jh9b}XNbPG8E#P1(GmokWI(CP*r!CIaZN z)Fh6wfWk3@QWJEK<3w2LE|X=%^vUTjn26!`MDk|_4j@H2gf^HUJ)}*egfdx(H3ejX z%763DkoU;{@mdNeaf)>mP7f8j6)Kbs6nYk_5~NdcP6>WGa$LLjl>Q~BuWKHd;s5s5VLEyTvYXCcXoDW&N(yl%jv^9ov7_(7wP=-U8Kcm2txI2&$!4XP{ zVE2(2ie5+{-^Ms$Vn@6d-oBCp@41M!<6#LEOlV${gj_R4I`7~DE;5P4gb>`$|7oi_ zZ_2?XOcU%Ve53qG5%Nuc$uFah85<1;S1?PMK85Ut5ltv5u^S#!)X7_n%8HGVe;98w z^J+&%;j{f=H%wlL?tndRCl175OC(aiGiP4)=T3!j-eIb;C-V@qQA7kEQNSIn}tV2ZniG8;e)af~yzDSUg$2^WfFO9G~<2 z+C`2%z*MU~a|CKN4q>;xq4M$w)kC-+P2vKdt_gEcs+}dj%~-cN*_|kT zMlJtptxZk_o(Oq+dQ=4w?BV<{{dhVYh@H*m0-JYP!w1Us3aT;xH3s( z@9>oz$UP+>+6HC9MFlqn%KLKkP95uG)#uf&QCM|x3%7Zd$U}9}WjAyBnu|MzyRaV_ zoEaChCUpk#!<&eLsgo}S?3ZDmY?UoNRNF^`u8QBwZoo=)E9}W&N5pvW=lYBs`%AQI#{<3B@SKE}(&z*W5uF)db8=nTfmp@sQT^5%$o4RFJ+pHuWH zypNb+nEHgO&p7P_XPENs+<}!s*Jv12=U|#pGpx;0&s<7X%iu0uG;l9m#$!mODusVR@o{ztA{zni!=v3BlW1uus) Qf*cgapBubKsgTFN0i^J%`v3p{ literal 0 HcmV?d00001 diff --git a/Java-Knight/target/classes/org/project/entity/enemies/Vampire.class b/Java-Knight/target/classes/org/project/entity/enemies/Vampire.class new file mode 100644 index 0000000000000000000000000000000000000000..1b189f715996f10e8f39ffeff7715374574a1c16 GIT binary patch literal 808 zcmaJ<%Wl&^6g`uNO&pVyG%b{*B|w2BNMymXJQP8YB1LS9vSKp{qhuO8j$8++U%-wp zVS~g&u;2sO@;`_(V;6)J)spAlJ9FaS4}Da^d+X!xy-90l-*>D;+BVUnYs1 zE}qL!&KQcJ^Yqt4`*}p$@^J+m)KJm_Xx#L^f+?)DNTelBwQt zw2r6hg*JWpnZ5@n@~y;8&NasyXTRp2=;i4bagFO9qt}cJw0^hI{0hG8&A!X+E0RXT(Yz@E6v*LC>(+H({AtRFE?DXiZkJ`w8v`Iw^%?H!Bu8 zg(+sxd{elc6)Tb&DUCWVoBDT)_m8{HFR0!((Kl@8@K1HkD%_^tI<~OGPIfJPD~0&0 Uyn#d9Awij0cdc@PdsbNc4=1mlsQ>@~ literal 0 HcmV?d00001 diff --git a/Java-Knight/target/classes/org/project/entity/players/Assassin.class b/Java-Knight/target/classes/org/project/entity/players/Assassin.class new file mode 100644 index 0000000000000000000000000000000000000000..a427acca31b042adc87c325cdf1c7646986a61c7 GIT binary patch literal 2058 zcmaJ>U2hs!5IvVq1B;EZA#ofMW9$U4+icT1X<|~h)OHd}xQgT`Qu@?2Ucowi2{u;! z*q_nI^rbI-sZzyA5-PXLE_mP82QI3fn3 zh$$4i{f5=+ch8-=XE`0u^)9Vm%f58_1M7vB3b7|{$MyCUR?4+=`@*(bcBf&Tczw6i zs2uUL^(uimB;rUKNWoAjeIRRfFt7&$x1+GwavM#r>Unnk&4Jyv8;*iHl2r2s79`JN z)3Glur%#A?(Lh$b3sc@>yJL%Q*+5QwN%~sfyltO4eKB7%a9zxEVjiEpVPF+E6%uae z!X3D$Evf&l9KU7Ywj2+&dnpvL9!JT*1~y4SKxc=VHrDj)H_o_`NSU+<*>??;B{CwV z6>j|xhr%Nxcy7OYMj#6{x8sZ&cxh{B*;==5w_e$OSKfVN#A~_(h0R(3uJIhlj8~Yv zW4D<+``zI7_ZyC{O0k~*KJq3{x^Me+=cy|zlpgbaPc94BXO3F{#JIG)9MrP1 z+*)#twdBfb$sMH($y!n-!8u@yPm^zdGee5fGPiFQa*Ml%G%E-!xuHmCO&XRqcksY(v&~#m zVZ;0l1^zOb0yN7KZee)d*HGPvWGj67fkd`BAP(FB^D>&sph_ zj#MS8kFo2Q{(*<3k#&|``4I+1Jlg!31XJ1DF8q$Q5GJHf7ZwUPSbCGwzM~79qfC>+ z>waMwLxoL;7?H*kYGDl~icn^se?RzQ0_P{X1kNtYYbM^|{uQ$H7+HFPY|M^OGXwL6 zo`%WEZexuA?-JM!=lhtG6`lm{8diKjtT_R`I|07y0~hXM2(Rv|72@T8n@`_4@yg_i zKHj{Hjr!7i+!;?UA2hZd!g|25JtTxjQ)4SmKoqe@rY2)sqxvPj^6OfZvYk=ZivL0- zq*o%QjTN0wVtK&Nr%(+HPR|DK1qOc|7@V06t_BA02L>*w1|Mo> Gp8g9%09uFu literal 0 HcmV?d00001 diff --git a/Java-Knight/target/classes/org/project/entity/players/Knight.class b/Java-Knight/target/classes/org/project/entity/players/Knight.class new file mode 100644 index 0000000000000000000000000000000000000000..563c334fcd477be9ee3ae5ff72ca49dbf425c0c9 GIT binary patch literal 1931 zcmaJ>+fExv5It>t0ecL_UpxLguGEk9iLSMEw^=*zJ-6H3-s4a8 z?F^sanx}%$pg4&Znvliwg%6!YwC#RD)#5->x zFW$Kc@4oJ8@hw^?h%ZfF`}N1pq2tN%1q(}ZJT1q=yDJth%3-Y2&tMJfDO|F!ff8v( zX!6`h!^pmV?+nY0S4dq1EnB!O$hag>SpSAjq7@Omx7#}+-MPBkb%HW~)rW1Ktx7LiRwqy|4QrvrK(F0}7Wa-vJxl zl1Jg7WL}PIW_FR?Zz(LYhKZ2FK224sdx3KTHgx8RnK%v<$Oebu3@K#7ec(+W^genG z=Y=aR%LLNj6unX6w8i+)5}Z-K1X_8SWwUZ>&B_TiD@T%R8f*ow@OzcJe~}~(uvqXBTD$Sg;G}0g8X{b`00}T}O)F9P#t~&Eo||%R+9-kjtAgRxr!r zmas}P>xNJ<2sk2C#Sgg4boUHWRcPMFgE0R-FAJ}XWK5ZiWBKGA1Dhp zTxEn3qU!H7f_Y4u!v`jwVC7W=bEoh)5}Z8`ei#XU5(&hWunY;I%bMD=!d{ z&Z=XgC7)HdROFp3&b^MT>qtI}0wx9eEpOF)Vmfug6YkLnn>?RI5f=o;TXN4_ah;m< zA6kBsJI|Mn?+MJ7PHUS#9ZF+b;GE<7MbmNj8_i-%Iaghc=P2f@a+cT1x8B|EeqtfeOcS9%615ztiP7sG^NdYwfIee^b^ar ztDFess=@GOY+8+`zvL?bf%By(J;6j4beBnAb{Zxfmw!tpVb@K0aQGT_V7qPBENL(8 zS~lG$F!eSbHO!RdE!oxqr$<9S;+dRxwM7%$t<#2#Z?GYrs`A@^{#Y#Mz}+(|!8a55cTLuOx5H+C=rv847?7?@r*50x%%>(*Gviw8S>k}o`Y=INdF~3BW|q>I4G=?pALtq} z%^)wckoJ%;O6DBVCw@dWpRjN0X(;wwp5!?`$^C@1issae0^SMT`!rIVhPow(Fh>O? z%o190pABHUvzfz(%n?v348(@Uxc{gtqY=uO3TVF%X-Pf)EBec7eS>{O&+!T}#2@4I zCppJs)~PP*6s~nyIp0Z=UXLan&XaVQMCx}mBpqewxaENK8cDB{^ae>k`5)37CrLkM zYGBDboQrZp`f}kf%*1f)I`v;0_>2=>)Ud@MuiHx+pJIV1tkttrpUBNFuFGtNTTm?w zrJrLgBnWJjRyI1>$}(NELaD3t%~}sD^iRdlfi7Z}?EFM2u{5Z1sc4YDJ$>Q%Ki`OEHM^6^lBZ}krLN~XL4X$Z+ TzscV_xX)9DyKQ`phdB2ilWEYT literal 0 HcmV?d00001 diff --git a/Java-Knight/target/classes/org/project/entity/players/Wizard.class b/Java-Knight/target/classes/org/project/entity/players/Wizard.class new file mode 100644 index 0000000000000000000000000000000000000000..667ff6eead8b2a0aa690f1901649a7b0b223162e GIT binary patch literal 1932 zcmaJ>T~8ZF6g^}70qX^f!44mRV4NmqX|qY8X;WxYlBNohi6T*@>RSi1vX}Tvn++;` z>rdgmFO}j(?L&V+pZbfco;$lXF5SkGcka&2x%ZqiclOV}fByr(Q#`Sd!bA>f8yRF3 zD!riT_JiK3*9cv&8~Wk7+i&Z0FL>>~Frz|t&+q!-LxrVU{ZyZ6x2?NP_b3efZgcm5 zzs;9Zn8Z{LmW@2@_h1#F?WqMMkhkKW8tjJ`l)6ZiSYdPGo zv5pF5CV2AHSi{Vre&r46rfZaLu|UBUEMK>{&QT^+v+Q1I{JraFQV~~ zx#qQ<@rJ-YHoFlz-vw6l#2~A;;$o@w1pi0oV9k zW&JAVv55u#fqs-74z~ElI`|MDv9?5a$Va$4auYCNB9~FxM0XiwOeDIpCK6>*(~&z! znSRKi}_!%;e2@jvt8wXA-Ud1F%M;5xB?F@&=1{)CqH*^fJ{Y=NPGaDa!Cf}ZJ$?YU z$84>P7*y~%C68=fXSj>KxUS1lIw~Ws{>&h1&#aleZ}JINE=hDu3ST6Gr>}w^B!V9% if(uu{dx_vjiQxIG;75tzFB8G#tKi3p;Cz;T-~{s)SHkMP(6`y%Vf3m19@V1Sx+75)~2) zK7fxxoEgW3L=IsybLaS;bI+Z*{`u?s4*;iVmyki$Le54W1%cYR`^j~DH<&o@M(5sG z2^5ZHAk~RLw%r*PaScTaB^%da3+#u{#JPw~~x zX^&Ut58X)W^AgOdkCOLxu%!usroQk$?8QZ*5T*Ltek*AWtg<#-iEh%GcHFf4?O01#ZiPI#|`yZVR9SM{M;XE39Z>4^y za$@|s9%kI;2NRY>1-n0FmhR(kvb9cbrI2F>M-+UJDpFn- P+1n`ckRp$a-^afJdZQiV literal 0 HcmV?d00001 -- 2.54.0 From b310290e43296f5bf340be423b6b21ac26e77449 Mon Sep 17 00:00:00 2001 From: navid Date: Wed, 13 May 2026 14:51:05 +0330 Subject: [PATCH 2/2] readme --- README.md | 239 ++++++++++++++++++++---------------------------------- 1 file changed, 87 insertions(+), 152 deletions(-) diff --git a/README.md b/README.md index 1e2c975..6c30b14 100644 --- a/README.md +++ b/README.md @@ -1,175 +1,110 @@ -# Fourth Assignment - Java Knight ⚔️ -A turn-based RPG with Roguelike elements which can be run in the terminal. +# Java Knight - Turn-Based 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!* +## Introduction -### **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**. +Java Knight is a turn-based RPG that runs in the terminal. The land of Javanest is cursed by a Dragon. People have turned into Goblins, Skeletons, and Vampires. You must defeat these monsters, collect their three keys, and finally kill the Dragon to break the curse. -⚠️ **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. +## How to Compile and Run -🎯 **Your goal is not just to complete the assignment but to learn and apply OOP effectively!** +### Prerequisites -### **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. +- Java Development Kit (JDK) 8 or later -### **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. +### Compilation ---- +Open a terminal in the root folder of the project (where the `org` folder is located). Run this command: -## Tasks 📝 - -### 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 - -![structure](Readme_Pictures/structure.png) - -### 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] - ---- - -Your Turn: -1. Light Attack | 2. Heavy Attack (-8 Mana) | 3. Defend (-6 Mana) | 4. Heal (-12 Mana) | 5. Shield Bash (-15 Mana) -``` - -```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 -``` -``` -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). +javac org/project/**/.java org/project/.java -### 4️⃣ Step 4: Implement the Game Loop & Progression 🎮 +### Execution -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**. +After compilation, run: -🔹 Example game loop structure: +java org.project.Main -```java -while (player.isAlive() && enemy.isAlive()) - player.attack(enemy); - if (enemy.isAlive()) { - enemy.attack(player); - } -} -``` +## OOP Principles and Design +The project uses the following object-oriented principles: -### 5️⃣ Step 5: Extra Features & Bonus Tasks ⭐ -*(Optional for extra credit)* +- **Encapsulation** – Fields like `hp`, `mp`, `damage` are private or protected. Access is done through getter methods. +- **Inheritance** – `Player` (abstract) is extended by `Knight`, `Assassin`, `Wizard`. `Enemy` (abstract) is extended by `Goblin`, `Skeleton`, `Vampire`, `Dragon`. +- **Polymorphism** – The `Entity` interface allows the game to treat players and enemies the same way. The `SpecialAbility()` method works differently for each class. +- **Abstraction** – `Player` and `Enemy` have abstract methods that subclasses must implement, like `SpecialAbility()`. +- **Method Overriding** – Every subclass overrides `SpecialAbility()`, `LightAttack()`, `heal()`, etc. -✅ **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. +### Design Patterns -### 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). +- **Template Method Pattern** – The combat loop in `Main` defines the basic turn structure, while specific actions are handled by overridden methods. +- **Factory Method Pattern** – The method `spawnRandomEnemyForLocation()` creates different enemy types without exposing the creation logic. +- **Strategy Pattern** – The five player actions (Light Attack, Heavy Attack, Defend, Heal, Special Ability) are interchangeable strategies chosen at runtime. ---- +### Key Classes -## Evaluation Criteria ⚖ +| Class | Description | +|-------|-------------| +| `Entity` (interface) | Defines combat methods: `LightAttack`, `HeavyAttack`, `defend`, `heal`, etc. | +| `Player` (abstract) | Manages HP, mana, defense stance, and common actions. | +| `Knight` | High base damage. Special: shield bash (stuns enemy). | +| `Assassin` | Highest mana. Special: invisible (dodge next attack + guaranteed critical hit). | +| `Wizard` | Highest HP. Special: spell that damages enemy and heals self. | +| `Enemy` (abstract) | Base for all monsters. | +| `Goblin` | 30% critical hit chance on light attacks. | +| `Skeleton` | Revives once with 50% HP. | +| `Vampire` | Lifesteals 30% of damage dealt. | +| `Dragon` | Final boss. Fiery breath ignores defense and deals double damage. | +| `Main` | Game loop, location navigation, key collection, victory/loss logic. | -| **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** | +## How to Play -## 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. +### Starting the Game -## 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. +Run `Main.java`. You will see a menu to choose your class: -![cover](Readme_Pictures/image.png) -###### - Born of God and Void. You shall seal the blinding light that plagues their dreams. You are the Vessel. You are the Java Knight. \ No newline at end of file +1. **Knight** – High damage, good HP, stunning special ability. +2. **Assassin** – High mana pool, can turn invisible to dodge and land critical hits. +3. **Wizard** – Highest HP, special ability damages enemy and heals self. + +### Location and Exploration + +You begin in a random location (Forest, Cemetery, Crypt, or Ruins). An enemy appears automatically. At each location, you have these options: + +- **1. Fight the enemy** – Start turn-based combat. +- **2. Move to another location** – Skip the current enemy and go to a different location (a new random enemy will appear). +- **3. Go to the Castle** – This option only appears after you collect all three keys. It starts the final boss fight against the Dragon. + +### Combat Actions (Your Turn) + +During combat, you have five actions. Mana costs are shown in the menu: + +| Action | Mana Cost | Effect | +|--------|-----------|--------| +| 1. Light Attack | 0 | Moderate damage | +| 2. Heavy Attack | 8 | High damage | +| 3. Defend | 6 | Reduces next enemy attack by 50% | +| 4. Heal | 10 | Restores a portion of your HP | +| 5. Special Ability | 15 | Class-unique move (see below) | + +#### Special Abilities + +- **Knight – Shield Bash** – Deals heavy damage and stuns the enemy. The enemy skips its next turn. +- **Assassin – Invisibility** – Dodges the next enemy attack completely. Your next hit becomes a critical hit (double damage). +- **Wizard – Devastating Spell** – Damages the enemy and heals the caster. + +### After Winning a Fight + +- Your HP and mana are fully restored. +- The defeated enemy has a 20% chance to drop its unique key (Goblin Key, Skeleton Key, or Vampire Key). +- Each key can be obtained only once. Killing more Goblins will not give another Goblin Key. + +### Winning the Game + +- Collect all three keys. Then the option "Go to the Castle" appears. +- Fight the Dragon. The Dragon has 180 HP. Its normal attack deals 45 damage. Its fiery breath deals double damage and ignores your defense. +- Defeat the Dragon to break the curse and save Javanest. + +### Losing the Game + +- If your HP reaches zero during any fight, the game ends with "Game Over". + +Good luck, hero. \ No newline at end of file -- 2.54.0