Compare commits
10
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b8ea5902bc | ||
|
|
7522e875bb | ||
|
|
50aa4c31a2 | ||
|
|
a9937d2668 | ||
|
|
d3fcf4ae1f | ||
|
|
3f9ec31bba | ||
|
|
92e5c2575f | ||
|
|
c1073ecbc7 | ||
|
|
c0c32b2dce | ||
|
|
a8ec615e1b |
@@ -1,15 +1,338 @@
|
||||
package org.project;
|
||||
|
||||
import org.project.location.Location;
|
||||
import org.project.entity.players.*;
|
||||
import org.project.entity.enemies.*;
|
||||
import org.project.location.*;
|
||||
import org.project.item.weapons.*;
|
||||
import org.project.item.consumables.*;
|
||||
import org.project.item.armors.*;
|
||||
|
||||
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<Location> locations = new ArrayList<>();
|
||||
private static Scanner scanner = new Scanner(System.in);
|
||||
private static Random random = new Random();
|
||||
|
||||
// TODO: IMPLEMENT GAMEPLAY
|
||||
private static Player player;
|
||||
|
||||
//Collected keys
|
||||
private static boolean hasGoblinKey = false;
|
||||
private static boolean hasSkeletonKey = false;
|
||||
private static boolean hasVampireKey = false;
|
||||
|
||||
private static boolean castleUnlocked = false;
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️");
|
||||
NarrativeConsole.printNormal(" JAVA KNIGHT - THE DRAGON'S CURSE");
|
||||
System.out.println("⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️⚔️");
|
||||
NarrativeConsole.printNormal("\nFor centuries, the land of Javanest lived in peace...");
|
||||
NarrativeConsole.printNormal("Until a magical Dragon attacked, plunging the realm into darkness!");
|
||||
NarrativeConsole.printNormal("You are the last hope. Gather the 3 keys and slay the Dragon!\n");
|
||||
|
||||
//Choosing a role
|
||||
createPlayer();
|
||||
|
||||
gameLoop();
|
||||
}
|
||||
|
||||
private static void createPlayer() {
|
||||
System.out.println("=".repeat(20));
|
||||
System.out.println("CHOOSE YOUR HERO:");
|
||||
System.out.println("1. Knight ⚔️ - High damage, strong armor");
|
||||
System.out.println("2. Wizard 🧙♂️ - High HP, healing spells");
|
||||
System.out.println("3. Assassin 🗡️ - High mana, critical strikes");
|
||||
System.out.print("\nEnter choice (1-3): ");
|
||||
|
||||
int choice = getIntInput();
|
||||
scanner.nextLine();
|
||||
|
||||
System.out.print("Enter your hero's name: ");
|
||||
String name = scanner.nextLine();
|
||||
|
||||
switch (choice) {
|
||||
case 1:
|
||||
player = new Knight(name);
|
||||
break;
|
||||
case 2:
|
||||
player = new Wizard(name);
|
||||
break;
|
||||
case 3:
|
||||
player = new Assassin(name);
|
||||
break;
|
||||
default:
|
||||
System.out.println("Invalid choice! Defaulting to Knight.");
|
||||
player = new Knight(name);
|
||||
}
|
||||
|
||||
System.out.println("\n✨ " + player.getName() + " the " +
|
||||
player.getClass().getSimpleName() + " has entered Javanest!");
|
||||
NarrativeConsole.printHeal("💚 HP: " + player.getHp() + "/" + player.getMaxHP());
|
||||
NarrativeConsole.printMana("💙 MP: " + player.getMp() + "/" + player.getMaxMP());
|
||||
System.out.println("\nPress Enter to begin your journey...");
|
||||
scanner.nextLine();
|
||||
}
|
||||
|
||||
private static void gameLoop() {
|
||||
boolean gameRunning = true;
|
||||
boolean firstLocation = true;
|
||||
|
||||
while (gameRunning && player.isAlive()) {
|
||||
//Entering a new location
|
||||
if (!firstLocation) {
|
||||
System.out.println("\n" + "=".repeat(30));
|
||||
System.out.println("You move to a new location...");
|
||||
}
|
||||
firstLocation = false;
|
||||
|
||||
Enemy currentEnemy = spawnRandomEnemy();
|
||||
NarrativeConsole.printWarning("\n⭕⭕⭕ A " +
|
||||
currentEnemy.getName(currentEnemy).toUpperCase() + " appears before you! ⭕⭕⭕");
|
||||
NarrativeConsole.printWarning("❤️ " + currentEnemy.getName(currentEnemy) + " HP: " +
|
||||
currentEnemy.getHp() + "/" + currentEnemy.getMaxHP());
|
||||
|
||||
//Pre-battle menu
|
||||
boolean locationExited = false;
|
||||
|
||||
while (!locationExited && player.isAlive() && gameRunning) {
|
||||
displayMainMenu();
|
||||
int choice = getIntInput();
|
||||
|
||||
if (choice == 1) {
|
||||
//Option 1: Starting the battle
|
||||
boolean victory = startBattle(currentEnemy);
|
||||
|
||||
if (victory) {
|
||||
handleVictory(currentEnemy);
|
||||
locationExited = true; //Moving on the next location
|
||||
} else {
|
||||
gameRunning = false; //Player's death
|
||||
}
|
||||
|
||||
} else if (choice == 2) {
|
||||
//Option 2: Move to another location1
|
||||
System.out.println("\n🚶 You flee to another location...");
|
||||
currentEnemy = spawnRandomEnemy();
|
||||
NarrativeConsole.printWarning("⭕ A " + currentEnemy.getName(currentEnemy) +
|
||||
" appears in this new location!");
|
||||
|
||||
} else if (choice == 3 && castleUnlocked) {
|
||||
//Option 3: Going to the castle and fight the dragon (only with 3 keys)
|
||||
System.out.println("\n🏰🏰🏰 YOU STAND BEFORE THE DRAGON'S CASTLE! 🏰🏰🏰");
|
||||
System.out.println("The gates slowly open... A massive shadow emerges...\n");
|
||||
|
||||
boolean victory = startBattle(new Dragon());
|
||||
if (victory) {
|
||||
System.out.println("\n🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉");
|
||||
NarrativeConsole.printSuccess(" THE DRAGON IS DEFEATED! YOU SAVED JAVANEST!");
|
||||
System.out.println("🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉🎉");
|
||||
gameRunning = false;
|
||||
} else {
|
||||
NarrativeConsole.printError("\n💀 The Dragon's flames consume you... GAME OVER!");
|
||||
gameRunning = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
//Checking the condition for opening the castle
|
||||
if (hasAllKeys() && !castleUnlocked) {
|
||||
castleUnlocked = true;
|
||||
System.out.println("\n🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑");
|
||||
NarrativeConsole.printSuccess(" YOU HAVE COLLECTED ALL 3 KEYS!");
|
||||
NarrativeConsole.printSuccess("🏰 THE PATH TO THE DRAGON'S CASTLE IS NOW OPEN! 🏰");
|
||||
System.out.println("🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑🔑");
|
||||
}
|
||||
|
||||
displayKeyProgress();
|
||||
|
||||
//End game
|
||||
if (!player.isAlive()) {
|
||||
NarrativeConsole.printError("\n💀💀💀 GAME OVER! 💀💀💀");
|
||||
NarrativeConsole.printError("Your journey ends here. The curse of Javanest remains unbroken...");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void displayMainMenu() {
|
||||
System.out.println("\n" + "-".repeat(30));
|
||||
System.out.println("WHAT WILL YOU DO?");
|
||||
System.out.println("1. ⚔️ FIGHT the enemy");
|
||||
System.out.println("2. 🚶 MOVE to another location");
|
||||
|
||||
if (castleUnlocked) {
|
||||
System.out.println("3. 🏰 GO TO THE CASTLE (Fight the Dragon!)");
|
||||
}
|
||||
System.out.print("\nChoose: ");
|
||||
}
|
||||
|
||||
private static boolean startBattle(Enemy enemy) {
|
||||
System.out.println("\n" + "🔥".repeat(30));
|
||||
System.out.println(" BATTLE BEGINS!");
|
||||
System.out.println("🔥".repeat(30));
|
||||
|
||||
while (player.isAlive() && enemy.isAlive()) {
|
||||
displayBattleStatus(enemy);
|
||||
|
||||
playerTurn(enemy);
|
||||
if (!enemy.isAlive()) {
|
||||
break;
|
||||
}
|
||||
|
||||
enemyTurn(enemy);
|
||||
}
|
||||
|
||||
return player.isAlive();
|
||||
}
|
||||
|
||||
private static void playerTurn(Enemy enemy) {
|
||||
System.out.println("\n" + "-".repeat(30));
|
||||
System.out.println("YOUR 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 (-12 Mana)");
|
||||
System.out.println("5. ⭐ Special Ability (-15 Mana)");
|
||||
System.out.print("Choose action: ");
|
||||
|
||||
int choice = getIntInput();
|
||||
|
||||
switch (choice) {
|
||||
case 1:
|
||||
player.lightAttack(enemy);
|
||||
break;
|
||||
case 2:
|
||||
player.heavyAttack(enemy);
|
||||
break;
|
||||
case 3:
|
||||
player.defend();
|
||||
break;
|
||||
case 4:
|
||||
player.heal(12);
|
||||
break;
|
||||
case 5:
|
||||
player.specialAbility(enemy);
|
||||
break;
|
||||
default:
|
||||
NarrativeConsole.printWarning("❌ Invalid choice! You hesitate and lose your turn!");
|
||||
}
|
||||
|
||||
//Checking the death of enemy
|
||||
if (!enemy.isAlive()) {
|
||||
NarrativeConsole.printSuccess("\n💀 " +
|
||||
enemy.getName(enemy).toUpperCase() + " HAS BEEN DEFEATED! 💀");
|
||||
}
|
||||
}
|
||||
|
||||
private static void enemyTurn(Enemy enemy) {
|
||||
System.out.println("\n" + "-".repeat(30));
|
||||
System.out.println("ENEMY TURN");
|
||||
enemy.attack(player);
|
||||
}
|
||||
|
||||
private static void displayBattleStatus(Enemy enemy) {
|
||||
System.out.println("\n" + "═".repeat(45));
|
||||
System.out.printf("❤️ %s: %d/%d HP | 💙 Mana: %d/%d%n",
|
||||
player.getName(), player.getHp(), player.getMaxHP(),
|
||||
player.getMp(), player.getMaxMP());
|
||||
System.out.printf("👾 %s: %d/%d HP%n",
|
||||
enemy.getName(enemy), enemy.getHp(), enemy.getMaxHP());
|
||||
System.out.println("═".repeat(45));
|
||||
}
|
||||
|
||||
private static Enemy spawnRandomEnemy() {
|
||||
int roll = random.nextInt(3); // 0, 1, 2
|
||||
|
||||
switch (roll) {
|
||||
case 0:
|
||||
return new Goblin();
|
||||
case 1:
|
||||
return new Skeleton();
|
||||
default:
|
||||
return new Vampire();
|
||||
}
|
||||
}
|
||||
|
||||
private static void handleVictory(Enemy defeatedEnemy) {
|
||||
NarrativeConsole.printSuccess("\n✨✨✨ VICTORY! ✨✨✨");
|
||||
NarrativeConsole.printSuccess(defeatedEnemy.getName(defeatedEnemy).toUpperCase() +
|
||||
" has been defeated!");
|
||||
|
||||
//Getting Higher Max HP and MP
|
||||
player.setMaxHP(player.getMaxHP() + getXpReward(defeatedEnemy)/5);
|
||||
player.setMaxMP(player.getMaxMP() + getXpReward(defeatedEnemy)/5);
|
||||
|
||||
//Full HP and Mana Recovery (Post-Combat Recovery)
|
||||
player.setHp(player.getMaxHP());
|
||||
player.setMp(player.getMaxMP());
|
||||
NarrativeConsole.printHeal("💚 HP and Mana fully restored in higher levels!");
|
||||
|
||||
//Key Drop (20% chance)
|
||||
attemptKeyDrop(defeatedEnemy);
|
||||
}
|
||||
|
||||
private static int getXpReward(Enemy enemy) {
|
||||
if (enemy instanceof Goblin) return 50;
|
||||
if (enemy instanceof Skeleton) return 65;
|
||||
if (enemy instanceof Vampire) return 85;
|
||||
if (enemy instanceof Dragon) return 300;
|
||||
return 40;
|
||||
}
|
||||
|
||||
private static void attemptKeyDrop(Enemy enemy) {
|
||||
//Checking if we already have this key or not
|
||||
if (enemy instanceof Goblin && hasGoblinKey) {
|
||||
return;
|
||||
}
|
||||
if (enemy instanceof Skeleton && hasSkeletonKey) {
|
||||
return;
|
||||
}
|
||||
if (enemy instanceof Vampire && hasVampireKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Dropping the key (20% Chance)
|
||||
int dropChance = random.nextInt(100);
|
||||
if (dropChance > 80) {
|
||||
if (enemy instanceof Goblin) {
|
||||
hasGoblinKey = true;
|
||||
NarrativeConsole.printSuccess("\n🔑🔑🔑 YOU FOUND THE GOBLIN KEY! (1/3) 🔑🔑🔑");
|
||||
} else if (enemy instanceof Skeleton) {
|
||||
hasSkeletonKey = true;
|
||||
NarrativeConsole.printSuccess("\n🔑🔑🔑 YOU FOUND THE SKELETON KEY! (2/3) 🔑🔑🔑");
|
||||
} else if (enemy instanceof Vampire) {
|
||||
hasVampireKey = true;
|
||||
NarrativeConsole.printSuccess("\n🔑🔑🔑 YOU FOUND THE VAMPIRE KEY! (3/3) 🔑🔑🔑");
|
||||
}
|
||||
} else {
|
||||
System.out.println("🔑 No key dropped this time... Keep fighting!");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean hasAllKeys() {
|
||||
return hasGoblinKey && hasSkeletonKey && hasVampireKey;
|
||||
}
|
||||
|
||||
private static void displayKeyProgress() {
|
||||
System.out.println("\n" + "-".repeat(40));
|
||||
System.out.println("KEY PROGRESS:");
|
||||
System.out.println(" " + (hasGoblinKey ? "👹" : "⬜") + " Goblin Key " + (hasGoblinKey ? "(Obtained)" : "(Missing)"));
|
||||
System.out.println(" " + (hasSkeletonKey ? "💀" : "⬜") + " Skeleton Key " + (hasSkeletonKey ? "(Obtained)" : "(Missing)"));
|
||||
System.out.println(" " + (hasVampireKey ? "🦇" : "⬜") + " Vampire Key " + (hasVampireKey ? "(Obtained)" : "(Missing)"));
|
||||
System.out.println("-".repeat(40));
|
||||
}
|
||||
|
||||
private static int getIntInput() {
|
||||
while (true) {
|
||||
try {
|
||||
int input = Integer.parseInt(scanner.nextLine().trim());
|
||||
return input;
|
||||
} catch (NumberFormatException e) {
|
||||
NarrativeConsole.printWarning("❌ Invalid input! Please enter a number: ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,6 @@ package org.project.entity;
|
||||
|
||||
public interface Entity {
|
||||
|
||||
void attack(Entity target);
|
||||
|
||||
void defend();
|
||||
|
||||
void heal(int health);
|
||||
@@ -15,4 +13,8 @@ public interface Entity {
|
||||
int getMaxHP();
|
||||
|
||||
int getMaxMP();
|
||||
|
||||
int getHp();
|
||||
|
||||
int getMp();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.entity.players.Player;
|
||||
import org.project.item.weapons.BoneDagger;
|
||||
import org.project.item.weapons.DragonClaw;
|
||||
import org.project.location.NarrativeConsole;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Dragon extends Enemy {
|
||||
private Random random;
|
||||
|
||||
public Dragon() {
|
||||
super("Dragon", 150, 100, new DragonClaw());
|
||||
this.random = new Random();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Entity target) {
|
||||
int chance = random.nextInt(100);
|
||||
|
||||
if (chance > 40) { //Fire breath chance 60%
|
||||
//Fire breath attack
|
||||
fireBreath(target);
|
||||
} else {
|
||||
//Normal claw attack
|
||||
normalAttack(target);
|
||||
}
|
||||
}
|
||||
|
||||
private void normalAttack(Entity target) {
|
||||
int damage = 25;
|
||||
|
||||
if (target instanceof Player) {
|
||||
Player player = (Player) target;
|
||||
if (player.isDefending()) {
|
||||
NarrativeConsole.printCombat("🐉 Dragon ignores your pathetic shield!");
|
||||
//Complete damage is done
|
||||
}
|
||||
}
|
||||
|
||||
target.takeDamage(damage);
|
||||
NarrativeConsole.printCombat("🐉 Dragon strikes with its claw!");
|
||||
NarrativeConsole.printDamage("💥 " + damage + " damage dealt to " + getName(target) + "!");
|
||||
}
|
||||
|
||||
private void fireBreath(Entity target) {
|
||||
int damage = 45;
|
||||
|
||||
NarrativeConsole.printSpecial("🐉🐉🐉 DRAGON BREATHES FIRE! 🐉🐉🐉");
|
||||
NarrativeConsole.printSpecial("🔥🔥🔥 FIERY BREATH ENGULFS EVERYTHING! 🔥🔥🔥");
|
||||
|
||||
if (target instanceof Player) {
|
||||
Player player = (Player) target;
|
||||
if (player.isDefending()) {
|
||||
NarrativeConsole.printSpecial("🛡️ Your shield MELTS under the dragon's breath!");
|
||||
NarrativeConsole.printSpecial("🔥 Defense is USELESS against this attack!");
|
||||
player.setDefending(false); //The defense is invalid
|
||||
}
|
||||
}
|
||||
|
||||
target.takeDamage(damage);
|
||||
NarrativeConsole.printDamage("💥 " + getName(target) + " takes " + damage + " MASSIVE damage!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHP() {
|
||||
return 150;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxMP() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.Sword;
|
||||
import org.project.item.weapons.Weapon;
|
||||
import org.project.location.NarrativeConsole;
|
||||
|
||||
public abstract class Enemy implements Entity {
|
||||
Weapon weapon;
|
||||
@@ -9,14 +11,20 @@ public abstract class Enemy implements Entity {
|
||||
private int mp;
|
||||
private boolean isStunned = false;
|
||||
private int stunTurns = 0;
|
||||
private String name;
|
||||
private final int defendCost = 6;
|
||||
private boolean isDefending = false;
|
||||
private final int healCost = 12;
|
||||
|
||||
public Enemy(int hp, int mp, Weapon weapon) {
|
||||
public Enemy(String name, int hp, int mp, Weapon weapon) {
|
||||
this.name = name;
|
||||
this.hp = hp;
|
||||
this.mp = mp;
|
||||
|
||||
this.weapon = weapon;
|
||||
}
|
||||
|
||||
public abstract void attack(Entity target);
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
hp -= damage;
|
||||
@@ -39,6 +47,28 @@ public abstract class Enemy implements Entity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillMana(int mana) {
|
||||
int oldMana = mp;
|
||||
mp += mana;
|
||||
|
||||
mp += mana;
|
||||
if (mp > getMaxMP()) {
|
||||
mp = getMaxMP();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
//checking mana
|
||||
|
||||
//reducing mana
|
||||
mp -= defendCost;
|
||||
|
||||
//activating defense mode
|
||||
isDefending = true;
|
||||
}
|
||||
|
||||
public boolean isStunned() {
|
||||
return isStunned;
|
||||
}
|
||||
@@ -47,6 +77,24 @@ public abstract class Enemy implements Entity {
|
||||
return hp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int health) {
|
||||
//checking mana
|
||||
if (mp < healCost) {
|
||||
NarrativeConsole.printWarning("❌ Not enough mana to heal!");
|
||||
return;
|
||||
}
|
||||
|
||||
//reducing mana
|
||||
mp -= healCost;
|
||||
|
||||
//increasing health
|
||||
hp += health;
|
||||
if (hp > getMaxHP()) {
|
||||
hp = getMaxHP();
|
||||
}
|
||||
}
|
||||
|
||||
public int getMp() {
|
||||
return mp;
|
||||
}
|
||||
@@ -54,4 +102,25 @@ public abstract class Enemy implements Entity {
|
||||
public Weapon getWeapon() {
|
||||
return weapon;
|
||||
}
|
||||
|
||||
public String getName(Entity target) {
|
||||
if (target instanceof Skeleton) {
|
||||
return "Skeleton";
|
||||
}
|
||||
else if (target instanceof Goblin) {
|
||||
return "Goblin";
|
||||
}
|
||||
else if (target instanceof Vampire) {
|
||||
return "Vampire";
|
||||
}
|
||||
return "Dragon";
|
||||
}
|
||||
|
||||
public void setHp(int newHp) {
|
||||
hp = newHp;
|
||||
}
|
||||
|
||||
public boolean isAlive() {
|
||||
return (getHp() > 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.BoneDagger;
|
||||
import org.project.item.weapons.ToothedHook;
|
||||
import org.project.location.NarrativeConsole;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Goblin extends Enemy {
|
||||
private Random random;
|
||||
|
||||
public Goblin() {
|
||||
super("Goblin", 30, 20, new ToothedHook());
|
||||
this.random = new Random();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Entity target) {
|
||||
int damage = 10;
|
||||
boolean isCritical = false;
|
||||
|
||||
//Checking Critical Chance
|
||||
int chance = random.nextInt(100);
|
||||
if (chance > 30) { //Critical Chance = 70%
|
||||
damage *= 2;
|
||||
isCritical = true;
|
||||
}
|
||||
|
||||
target.takeDamage(damage);
|
||||
|
||||
if (isCritical) {
|
||||
NarrativeConsole.printSpecial("💣 Goblin used CRITICAL STRIKE! ");
|
||||
NarrativeConsole.printDamage("💥 Goblin dealt " + damage + " damage to " + getName(target) + "!");
|
||||
} else {
|
||||
NarrativeConsole.printCombat("👹 Goblin attacked " + getName(target) + "!");
|
||||
NarrativeConsole.printDamage("💥 Goblin dealt " + damage + " damage to " + getName(target) + "!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHP() {
|
||||
return 30;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxMP() {
|
||||
return 20;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,69 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Skeleton {
|
||||
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.BoneDagger;
|
||||
import org.project.location.NarrativeConsole;
|
||||
|
||||
public class Skeleton extends Enemy {
|
||||
private boolean hasResurrected = false;
|
||||
|
||||
public Skeleton() {
|
||||
super("Skeleton", 45, 25, new BoneDagger());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Entity target) {
|
||||
int damage = 10;
|
||||
|
||||
target.takeDamage(damage);
|
||||
|
||||
NarrativeConsole.printWarning("💀 Skeleton attacked " + getName(target) + "!");
|
||||
NarrativeConsole.printDamage("💥 Skeleton dealt " + damage + " damage to "
|
||||
+ getName(target) + "!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
int newHp = getHp() - damage;
|
||||
|
||||
if (newHp <= 0 && !hasResurrected) {
|
||||
//Resurrecting
|
||||
int resurrectedHp = getMaxHP() * 50 / 100;
|
||||
setHp(resurrectedHp);
|
||||
hasResurrected = true;
|
||||
|
||||
NarrativeConsole.printSuccess("💀 Skeleton has been defeated...");
|
||||
NarrativeConsole.printSpecial("☠️ But Skeleton rises again! Resurrected with "
|
||||
+ resurrectedHp + " HP!");
|
||||
return;
|
||||
}
|
||||
|
||||
setHp(newHp);
|
||||
if (getHp() < 0) setHp(0);
|
||||
|
||||
NarrativeConsole.printDamage("💥 Skeleton took " + damage + " damage! HP: "
|
||||
+ getHp() + "/" + getMaxHP());
|
||||
|
||||
if (getHp() <= 0) {
|
||||
NarrativeConsole.printSuccess("☠️ Skeleton has been destroyed for good!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHP() {
|
||||
return 45;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxMP() {
|
||||
return 25;
|
||||
}
|
||||
|
||||
public boolean hasResurrected() {
|
||||
return hasResurrected;
|
||||
}
|
||||
|
||||
public void setHasResurrected(boolean hasResurrected) {
|
||||
this.hasResurrected = hasResurrected;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.ToothedHook;
|
||||
import org.project.location.NarrativeConsole;
|
||||
|
||||
public class Vampire extends Enemy {
|
||||
public Vampire() {
|
||||
super("Vampire", 50, 40, new ToothedHook());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Entity target) {
|
||||
int damage = 12;
|
||||
|
||||
target.takeDamage(damage);
|
||||
|
||||
//Adding to Vampire HP
|
||||
int healAmount = damage * 30 / 100;
|
||||
int newHp = getHp() + healAmount;
|
||||
if (newHp > getMaxHP()) {
|
||||
newHp = getMaxHP();
|
||||
}
|
||||
setHp(newHp);
|
||||
|
||||
NarrativeConsole.printCombat("🦇 Vampire attacks " + getName(target) + "!");
|
||||
NarrativeConsole.printDamage("💥 Dealt " + damage + " damage!");
|
||||
NarrativeConsole.printSpecial("🩸 Life steal: Vampire drains " + healAmount + " HP and regenerates!");
|
||||
NarrativeConsole.printSpecial("💚 Vampire HP: " + getHp() + "/" + getMaxHP());
|
||||
|
||||
if (getHp() == getMaxHP()) {
|
||||
NarrativeConsole.printInfo("🦇 Vampire is fully satiated!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHP() {
|
||||
return 50;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxMP() {
|
||||
return 40;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,95 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.entity.enemies.Enemy;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.armors.AssassinMask;
|
||||
import org.project.item.weapons.Dagger;
|
||||
import org.project.item.weapons.Weapon;
|
||||
import org.project.location.NarrativeConsole;
|
||||
|
||||
public class Assassin extends Player implements Entity {
|
||||
public Assassin(String name, Weapon weapon, Armor armor) {
|
||||
super(name, 45, 60, weapon, armor);
|
||||
public class Assassin extends Player implements Entity, ICombatActions {
|
||||
public Assassin(String name) {
|
||||
super(name, 45, 60, new Dagger(), new AssassinMask());
|
||||
setHp(getMaxHP());
|
||||
setMp(getMaxMP());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void specialAbility(Enemy target) {
|
||||
//Checking if the mana is enough of not
|
||||
if (getMp() < 15) {
|
||||
NarrativeConsole.printWarning("❌ Not enough mana for Devastating Spell!");
|
||||
return;
|
||||
}
|
||||
|
||||
//Consuming mana
|
||||
setMp(getMp()-15);
|
||||
|
||||
setInvisible(true);
|
||||
setNextAttackCritical(true);
|
||||
|
||||
NarrativeConsole.printSpecial("💜 " + getName() + " turns INVISIBLE!");
|
||||
NarrativeConsole.printSpecial("⚡ Next attack will be CRITICAL (2x damage)!");
|
||||
NarrativeConsole.printSpecial("🛡️ Will dodge the next incoming attack completely!");
|
||||
NarrativeConsole.printMana("💙 Mana left: " + getMp());
|
||||
}
|
||||
|
||||
public void lightAttack(Enemy target) {
|
||||
int damage = 10;
|
||||
|
||||
//Critical Action (if enabled)
|
||||
if (isNextAttackCritical()) {
|
||||
damage *= 2;
|
||||
NarrativeConsole.printSpecial("⚡ CRITICAL HIT! Damage doubled to " + damage + "!");
|
||||
setNextAttackCritical(false);
|
||||
}
|
||||
|
||||
target.takeDamage(damage);
|
||||
NarrativeConsole.printDamage("⚔️ " + getName() + " used Light Attack! Dealt " + damage + " damage.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heavyAttack(Enemy target) {
|
||||
if (getMp() < 8) {
|
||||
NarrativeConsole.printWarning("❌ Not enough mana for Heavy Attack!");
|
||||
return;
|
||||
}
|
||||
setMp(getMp() - 8);
|
||||
int damage = 20;
|
||||
|
||||
//Critical Action (if enabled)
|
||||
if (isNextAttackCritical()) {
|
||||
damage *= 2;
|
||||
NarrativeConsole.printSpecial("⚡ CRITICAL HIT! Damage doubled to " + damage + "!");
|
||||
setNextAttackCritical(false);
|
||||
}
|
||||
|
||||
target.takeDamage(damage);
|
||||
NarrativeConsole.printDamage("💥 " + getName() + " used Heavy Attack! Dealt " + damage + " damage.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
if (getMp() < 6) {
|
||||
NarrativeConsole.printWarning("❌ Not enough mana to defend!");
|
||||
return;
|
||||
}
|
||||
setMp(getMp() - 6);
|
||||
setDefending(true);
|
||||
NarrativeConsole.printCombat("🛡️ " + getName() + " is defending! Next attack will be halved.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal() {
|
||||
if (getMp() < 12) {
|
||||
NarrativeConsole.printWarning("❌ Not enough mana to heal!");
|
||||
return;
|
||||
}
|
||||
setMp(getMp() - 12);
|
||||
int healAmount = 20;
|
||||
setHp(getHp() + healAmount);
|
||||
if (getHp() > getMaxHP()) setHp(getMaxHP());
|
||||
NarrativeConsole.printHeal("💚 " + getName() + " healed " + healAmount + " HP!");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.entity.enemies.Enemy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public interface ICombatActions {
|
||||
|
||||
void lightAttack(Enemy target);
|
||||
|
||||
void heavyAttack(Enemy target);
|
||||
|
||||
void defend();
|
||||
|
||||
void heal();
|
||||
|
||||
void specialAbility(Enemy target);
|
||||
}
|
||||
@@ -6,20 +6,23 @@ import org.project.item.armors.Armor;
|
||||
import org.project.item.armors.KnightArmor;
|
||||
import org.project.item.weapons.Sword;
|
||||
import org.project.item.weapons.Weapon;
|
||||
import org.project.location.NarrativeConsole;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
public class Knight extends Player {
|
||||
public class Knight extends Player implements ICombatActions {
|
||||
public Knight(String name) {
|
||||
super(name, 45, 45, new Sword(), new KnightArmor());
|
||||
setHp(getMaxHP());
|
||||
setMp(getMaxMP());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void uniqueAbility(Entity target) {
|
||||
public void specialAbility(Enemy target) {
|
||||
//Checking if the mana is enough of not
|
||||
if (getMp() < 15) {
|
||||
System.out.println("Mana is not enough for Shield Bash!");
|
||||
NarrativeConsole.printWarning("❌ Mana is not enough for Shield Bash!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -31,6 +34,48 @@ public class Knight extends Player {
|
||||
((Sword) getWeapon()).uniqueAbility(target);
|
||||
}
|
||||
|
||||
System.out.println("💥 Shield Bash! Enemy is stunned!");
|
||||
NarrativeConsole.printSpecial("💥 Shield Bash! Enemy is stunned!");
|
||||
}
|
||||
|
||||
public void lightAttack(Enemy target) {
|
||||
int damage = 10;
|
||||
target.takeDamage(damage);
|
||||
NarrativeConsole.printCombat("⚔️ " + getName() + " used Light Attack! Dealt " + damage + " damage.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heavyAttack(Enemy target) {
|
||||
if (getMp() < 8) {
|
||||
NarrativeConsole.printWarning("❌ Mana is not enough for Heavy Attack!");
|
||||
return;
|
||||
}
|
||||
setMp(getMp() - 8);
|
||||
int damage = 20;
|
||||
target.takeDamage(damage);
|
||||
NarrativeConsole.printDamage("💥 " + getName() + " used Heavy Attack! Dealt " + damage + " damage.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
if (getMp() < 6) {
|
||||
NarrativeConsole.printWarning("❌ Not enough mana to defend!");
|
||||
return;
|
||||
}
|
||||
setMp(getMp() - 6);
|
||||
setDefending(true);
|
||||
NarrativeConsole.printCombat("🛡️ " + getName() + " is defending! Next attack will be halved.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal() {
|
||||
if (getMp() < 12) {
|
||||
NarrativeConsole.printWarning("❌ Not enough mana to heal!");
|
||||
return;
|
||||
}
|
||||
setMp(getMp() - 12);
|
||||
int healAmount = 20;
|
||||
setHp(getHp() + healAmount);
|
||||
if (getHp() > getMaxHP()) setHp(getMaxHP());
|
||||
NarrativeConsole.printHeal("💚 " + getName() + " healed " + healAmount + " HP!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.entity.enemies.Enemy;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.weapons.Weapon;
|
||||
import org.project.location.NarrativeConsole;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -18,26 +20,28 @@ public abstract class Player implements Entity {
|
||||
private final int defendCost = 6;
|
||||
private boolean isDefending = false;
|
||||
private final int healCost = 12;
|
||||
private boolean isInvisible = false;
|
||||
private boolean nextAttackCritical = false;
|
||||
|
||||
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
|
||||
public Player(String name, int maxHP, int maxMP, Weapon weapon, Armor armor) {
|
||||
this.name = name;
|
||||
this.hp = hp;
|
||||
this.mp = mp;
|
||||
|
||||
this.maxMP = maxMP;
|
||||
this.maxHP = maxHP;
|
||||
this.weapon = weapon;
|
||||
this.armor = armor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Entity target) {
|
||||
target.takeDamage(weapon.getDamage());
|
||||
}
|
||||
public abstract void specialAbility(Enemy enemy);
|
||||
|
||||
public abstract void lightAttack(Enemy enemy);
|
||||
|
||||
public abstract void heavyAttack(Enemy enemy);
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
//checking mana
|
||||
if (mp < defendCost) {
|
||||
System.out.println("Not enough mana to defend!");
|
||||
NarrativeConsole.printWarning("❌ Not enough mana to defend!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -47,7 +51,7 @@ public abstract class Player implements Entity {
|
||||
//activating defense mode
|
||||
isDefending = true;
|
||||
|
||||
System.out.println("🛡️ " + name + " raises shield, preparing to block next attack!");
|
||||
NarrativeConsole.printCombat("🛡️ " + name + " raises shield, preparing to block next attack!");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,7 +61,7 @@ public abstract class Player implements Entity {
|
||||
//reducing damage if the player is in defend mode
|
||||
if (isDefending()) {
|
||||
actualDamage = damage / 2;
|
||||
System.out.println("🛡️ Defense reduced damage from " + damage + " to " + actualDamage);
|
||||
NarrativeConsole.printCombat("🛡️ Defense reduced damage from " + damage + " to " + actualDamage);
|
||||
setDefending(false);
|
||||
}
|
||||
|
||||
@@ -67,16 +71,17 @@ public abstract class Player implements Entity {
|
||||
if (actualDamage < 0) actualDamage = 0;
|
||||
|
||||
armor.reduceDurability(1);
|
||||
System.out.println("🛡️ Armor blocked " + defense +
|
||||
NarrativeConsole.printCombat("🛡️ Armor blocked " + defense +
|
||||
" damage! Remaining durability: " + armor.getDurability());
|
||||
}
|
||||
|
||||
setHp(getHp() - actualDamage);
|
||||
System.out.println("💥 " + getName() + " took " + actualDamage + " damage! HP: " + getHp());
|
||||
NarrativeConsole.printDamage("💥 " + getName() + " took "
|
||||
+ actualDamage + " damage! HP: " + getHp());
|
||||
|
||||
if (getHp() < 0) {
|
||||
setHp(0);
|
||||
System.out.println("💀 " + getName() + " has been defeated!");
|
||||
NarrativeConsole.printDamage("💀 " + getName() + " has been defeated!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +89,7 @@ public abstract class Player implements Entity {
|
||||
public void heal(int health) {
|
||||
//checking mana
|
||||
if (mp < healCost) {
|
||||
System.out.println("Not enough mana to heal!");
|
||||
NarrativeConsole.printWarning("❌ Not enough mana to heal!");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -109,14 +114,12 @@ public abstract class Player implements Entity {
|
||||
}
|
||||
|
||||
if (mp == maxMP) {
|
||||
System.out.println("Mana is now full! (" + mp + "/" + maxMP + ")");
|
||||
NarrativeConsole.printMana("🩵 Mana is now full! (" + mp + "/" + maxMP + ")");
|
||||
} else {
|
||||
System.out.println("Mana increased from " + oldMana + " to " + mp);
|
||||
NarrativeConsole.printMana("🩵 Mana increased from " + oldMana + " to " + mp);
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void uniqueAbility(Entity target);
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -151,6 +154,18 @@ public abstract class Player implements Entity {
|
||||
return isDefending;
|
||||
}
|
||||
|
||||
public boolean isInvisible() { return isInvisible; }
|
||||
|
||||
public boolean isNextAttackCritical() { return nextAttackCritical; }
|
||||
|
||||
public boolean isAlive() {
|
||||
return (getHp() != 0);
|
||||
}
|
||||
|
||||
public void setInvisible(boolean invisible) { this.isInvisible = invisible; }
|
||||
|
||||
public void setNextAttackCritical(boolean critical) { this.nextAttackCritical = critical; }
|
||||
|
||||
public void setHp(int hp) {
|
||||
this.hp = hp;
|
||||
}
|
||||
@@ -162,4 +177,12 @@ public abstract class Player implements Entity {
|
||||
public void setDefending(boolean defending) {
|
||||
isDefending = defending;
|
||||
}
|
||||
|
||||
public void setMaxHP(int maxHP) {
|
||||
this.maxHP = maxHP;
|
||||
}
|
||||
|
||||
public void setMaxMP(int maxMP) {
|
||||
this.maxMP = maxMP;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,85 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.entity.enemies.Enemy;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.armors.AssassinMask;
|
||||
import org.project.item.armors.WizardRobe;
|
||||
import org.project.item.weapons.Sword;
|
||||
import org.project.item.weapons.Wand;
|
||||
import org.project.item.weapons.Weapon;
|
||||
import org.project.location.NarrativeConsole;
|
||||
|
||||
public class Wizard extends Player implements Entity {
|
||||
public Wizard (String name, Weapon weapon, Armor armor) {
|
||||
super(name, 60, 45, weapon, armor);
|
||||
public class Wizard extends Player implements Entity,ICombatActions {
|
||||
public Wizard (String name) {
|
||||
super(name, 60, 45, new Wand(), new WizardRobe());
|
||||
setHp(getMaxHP());
|
||||
setMp(getMaxMP());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void specialAbility(Enemy target) {
|
||||
//Checking if the mana is enough of not
|
||||
if (getMp() < 15) {
|
||||
NarrativeConsole.printWarning("❌ Not enough mana for Devastating Spell!");
|
||||
return;
|
||||
}
|
||||
|
||||
//Consuming mana
|
||||
setMp(getMp()-15);
|
||||
|
||||
target.takeDamage(30);
|
||||
NarrativeConsole.printSpecial("🔮 " + getName() + "used DEVASTATING SPELL Dealt" + 30 + " damage!");
|
||||
|
||||
int newHp = getHp() + 10;
|
||||
if (newHp > getMaxHP()) newHp = getMaxHP();
|
||||
setHp(newHp);
|
||||
|
||||
NarrativeConsole.printSpecial("💚 " + getName() + " healed " + 10 + " HP! (Now: " +
|
||||
getHp() + "/" + getMaxHP() + ")");
|
||||
NarrativeConsole.printMana("💙 Mana left: " + getMp());
|
||||
}
|
||||
|
||||
public void lightAttack(Enemy target) {
|
||||
int damage = 10;
|
||||
target.takeDamage(damage);
|
||||
NarrativeConsole.printCombat("⚔️ " + getName() + " used Light Attack! Dealt " + damage + " damage.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heavyAttack(Enemy target) {
|
||||
if (getMp() < 8) {
|
||||
NarrativeConsole.printWarning("❌ Not enough mana for Heavy Attack!");
|
||||
return;
|
||||
}
|
||||
setMp(getMp() - 8);
|
||||
int damage = 20;
|
||||
target.takeDamage(damage);
|
||||
NarrativeConsole.printDamage("💥 " + getName() + " used Heavy Attack! Dealt " + damage + " damage.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
if (getMp() < 6) {
|
||||
NarrativeConsole.printWarning("❌ Not enough mana to defend!");
|
||||
return;
|
||||
}
|
||||
setMp(getMp() - 6);
|
||||
setDefending(true);
|
||||
NarrativeConsole.printCombat("🛡️ " + getName() + " is defending! Next attack will be halved.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal() {
|
||||
if (getMp() < 12) {
|
||||
NarrativeConsole.printWarning("❌ Not enough mana to heal!");
|
||||
return;
|
||||
}
|
||||
setMp(getMp() - 12);
|
||||
int healAmount = 20;
|
||||
setHp(getHp() + healAmount);
|
||||
if (getHp() > getMaxHP()) setHp(getMaxHP());
|
||||
NarrativeConsole.printHeal("💚 " + getName() + " healed " + healAmount + " HP!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,28 @@
|
||||
package org.project.item.consumables;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Consumable {
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
import org.project.item.Item;
|
||||
|
||||
public abstract class Consumable implements Item {
|
||||
protected String name;
|
||||
protected int healingPercent;
|
||||
|
||||
public Consumable(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Consumable(String name, int healingPercent) {
|
||||
this(name);
|
||||
this.healingPercent = healingPercent;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getHealingPercent() {
|
||||
return healingPercent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void use(org.project.entity.Entity target);
|
||||
}
|
||||
|
||||
@@ -1,16 +1,38 @@
|
||||
package org.project.item.consumables;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.location.NarrativeConsole;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Flask {
|
||||
/*
|
||||
THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN.
|
||||
*/
|
||||
public class Flask extends Consumable {
|
||||
public Flask(String name, int healingPercent) {
|
||||
super(name , healingPercent);
|
||||
}
|
||||
|
||||
// TODO: UPDATE USE METHOD
|
||||
@Override
|
||||
public void use(Entity target) {
|
||||
target.heal(target.getMaxHP() / 10);
|
||||
//Checking if the target is alive
|
||||
if (target == null || target.getHp() <= 0) {
|
||||
NarrativeConsole.printWarning("❌ Target is dead already!");
|
||||
return;
|
||||
}
|
||||
|
||||
int healAmount = target.getMaxHP() * healingPercent / 100;
|
||||
if (healAmount < 10) {
|
||||
healAmount = 10;
|
||||
}
|
||||
|
||||
int oldHp = target.getHp();
|
||||
target.heal(healAmount);
|
||||
int actualHeal = target.getHp() - oldHp;
|
||||
|
||||
NarrativeConsole.printHeal("🧪🧪🧪 ============== 🧪🧪🧪");
|
||||
NarrativeConsole.printHeal("💚 " + getName() + " drinks the Healing Flask!");
|
||||
NarrativeConsole.printHeal("✨ Restored " + actualHeal + " HP!");
|
||||
NarrativeConsole.printHeal("💚 HP: " + target.getHp() + "/" + target.getMaxHP());
|
||||
|
||||
if (target.getHp() == target.getMaxHP()) {
|
||||
NarrativeConsole.printHeal("💪 " + getName() + " is fully healed!");
|
||||
}
|
||||
NarrativeConsole.printHeal("🧪🧪🧪 ============== 🧪🧪🧪");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.project.item.consumables;
|
||||
|
||||
public class GreatFlask extends Flask {
|
||||
public GreatFlask() {
|
||||
super("Great Flask", 50); //50% healing
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.project.item.consumables;
|
||||
|
||||
public class HealthFlask extends Flask {
|
||||
public HealthFlask() {
|
||||
super("Health Flask",25); //25% healing
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.project.item.consumables;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.entity.players.Player;
|
||||
import org.project.location.NarrativeConsole;
|
||||
|
||||
public class ManaFlask extends Flask {
|
||||
public ManaFlask() {
|
||||
super("Mana Flask",30); //30% mana increasing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void use(Entity target) {
|
||||
if (target instanceof Player) {
|
||||
Player player = (Player) target;
|
||||
int manaAmount = player.getMaxMP() / 3;
|
||||
player.setMp(Math.min(player.getMp() + manaAmount, player.getMaxMP()));
|
||||
NarrativeConsole.printMana("💙 Restored " + manaAmount + " Mana!");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,8 @@
|
||||
package org.project.item.weapons;
|
||||
|
||||
import org.project.item.Item;
|
||||
|
||||
//The skeleton's weapon
|
||||
public class BoneDagger extends Weapon implements Item {
|
||||
int abilityCharge;
|
||||
|
||||
public BoneDagger(int damage, int manaCost) {
|
||||
super(damage, manaCost);
|
||||
public class BoneDagger extends Weapon {
|
||||
public BoneDagger() {
|
||||
super(10, 5);
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,10 @@ package org.project.item.weapons;
|
||||
import org.project.item.Item;
|
||||
|
||||
//The assassin's weapon
|
||||
public class Dagger extends Weapon implements Item {
|
||||
public class Dagger extends Weapon {
|
||||
int abilityCharge;
|
||||
|
||||
public Dagger(int damage, int manaCost) {
|
||||
super(damage, manaCost);
|
||||
public Dagger() {
|
||||
super(15, 10);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.project.item.weapons;
|
||||
|
||||
//The dragon's weapon
|
||||
public class DragonClaw extends Weapon {
|
||||
public DragonClaw() {
|
||||
super(25, 20);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,8 @@
|
||||
package org.project.item.weapons;
|
||||
|
||||
import org.project.item.Item;
|
||||
|
||||
//The vampire's weapon
|
||||
public class Rapier extends Weapon implements Item {
|
||||
int abilityCharge;
|
||||
|
||||
public Rapier(int damage, int manaCost) {
|
||||
super(damage, manaCost);
|
||||
public class Rapier extends Weapon {
|
||||
public Rapier() {
|
||||
super(20, 10);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,8 @@
|
||||
package org.project.item.weapons;
|
||||
|
||||
import org.project.item.Item;
|
||||
|
||||
//The goblin's weapon
|
||||
public class ToothedHook extends Weapon implements Item {
|
||||
int abilityCharge;
|
||||
|
||||
public ToothedHook(int damage, int manaCost) {
|
||||
super(damage, manaCost);
|
||||
public class ToothedHook extends Weapon {
|
||||
public ToothedHook() {
|
||||
super(15, 6);
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,10 @@
|
||||
package org.project.item.weapons;
|
||||
|
||||
import org.project.item.Item;
|
||||
|
||||
//The wizard's weapon
|
||||
public class Wand extends Weapon implements Item {
|
||||
public class Wand extends Weapon{
|
||||
int abilityCharge;
|
||||
|
||||
public Wand(int damage, int manaCost) {
|
||||
super(damage, manaCost);
|
||||
public Wand() {
|
||||
super(12, 6);
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,6 @@ public abstract class Weapon implements Item {
|
||||
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;
|
||||
@@ -36,8 +32,4 @@ public abstract class Weapon implements Item {
|
||||
public void setManaCost(int manaCost) {
|
||||
this.manaCost = manaCost;
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.project.location;
|
||||
|
||||
public class AnsiColors {
|
||||
// Reset
|
||||
public static final String RESET = "\u001B[0m";
|
||||
|
||||
// Regular Colors
|
||||
public static final String BLACK = "\u001B[30m";
|
||||
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 BLUE = "\u001B[34m";
|
||||
public static final String PURPLE = "\u001B[35m";
|
||||
public static final String CYAN = "\u001B[36m";
|
||||
public static final String WHITE = "\u001B[37m";
|
||||
|
||||
// Bold Colors
|
||||
public static final String BOLD_RED = "\u001B[1;31m";
|
||||
public static final String BOLD_GREEN = "\u001B[1;32m";
|
||||
public static final String BOLD_YELLOW = "\u001B[1;33m";
|
||||
public static final String BOLD_BLUE = "\u001B[1;34m";
|
||||
public static final String BOLD_PURPLE = "\u001B[1;35m";
|
||||
public static final String BOLD_CYAN = "\u001B[1;36m";
|
||||
|
||||
// Background Colors
|
||||
public static final String BG_RED = "\u001B[41m";
|
||||
public static final String BG_GREEN = "\u001B[42m";
|
||||
public static final String BG_YELLOW = "\u001B[43m";
|
||||
public static final String BG_BLUE = "\u001B[44m";
|
||||
}
|
||||
@@ -1,28 +1,72 @@
|
||||
package org.project.location;
|
||||
|
||||
import org.project.entity.enemies.Enemy;
|
||||
|
||||
import org.project.entity.enemies.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class Location {
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
private ArrayList<Enemy> possibleEnemies;
|
||||
private Enemy currentEnemy;
|
||||
private Random random;
|
||||
|
||||
private ArrayList<Enemy> enemies;
|
||||
|
||||
public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) {
|
||||
this.locations = locations;
|
||||
this.enemies = enemies;
|
||||
public Location(String name, String description) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.possibleEnemies = new ArrayList<>();
|
||||
this.random = new Random();
|
||||
}
|
||||
|
||||
//Adding enemy to location
|
||||
public void addEnemy(Enemy enemy) {
|
||||
possibleEnemies.add(enemy);
|
||||
}
|
||||
|
||||
//Spawning a random enemy from among the enemies in this location
|
||||
public void spawnRandomEnemy() {
|
||||
if (possibleEnemies.isEmpty()) {
|
||||
//If no enemy was defined
|
||||
addDefaultEnemies();
|
||||
}
|
||||
|
||||
int index = random.nextInt(possibleEnemies.size());
|
||||
currentEnemy = copyEnemy(possibleEnemies.get(index));
|
||||
}
|
||||
|
||||
private void addDefaultEnemies() {
|
||||
possibleEnemies.add(new Goblin());
|
||||
possibleEnemies.add(new Skeleton());
|
||||
possibleEnemies.add(new Vampire());
|
||||
}
|
||||
|
||||
//Copying the enemy to have a new instance each time
|
||||
private Enemy copyEnemy(Enemy original) {
|
||||
if (original instanceof Goblin) return new Goblin();
|
||||
if (original instanceof Skeleton) return new Skeleton();
|
||||
if (original instanceof Vampire) return new Vampire();
|
||||
return new Goblin();
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public ArrayList<Location> getLocations() {
|
||||
return locations;
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public ArrayList<Enemy> getEnemies() {
|
||||
return enemies;
|
||||
public Enemy getCurrentEnemy() {
|
||||
return currentEnemy;
|
||||
}
|
||||
}
|
||||
|
||||
public void setCurrentEnemy(Enemy enemy) {
|
||||
this.currentEnemy = enemy;
|
||||
}
|
||||
|
||||
public boolean hasEnemy() {
|
||||
return currentEnemy != null && currentEnemy.isAlive();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package org.project.location;
|
||||
|
||||
import org.project.entity.enemies.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
public class LocationManager {
|
||||
|
||||
private ArrayList<Location> locations;
|
||||
private Location currentLocation;
|
||||
private Random random;
|
||||
|
||||
public LocationManager() {
|
||||
locations = new ArrayList<>();
|
||||
random = new Random();
|
||||
createLocations();
|
||||
}
|
||||
|
||||
private void createLocations() {
|
||||
//Creating different game locations
|
||||
Location forest = new Location("Dark Forest", "A mysterious forest filled with dangerous creatures");
|
||||
forest.addEnemy(new Goblin());
|
||||
forest.addEnemy(new Skeleton());
|
||||
|
||||
Location crypt = new Location("Ancient Crypt", "An old crypt where skeletons roam");
|
||||
crypt.addEnemy(new Skeleton());
|
||||
crypt.addEnemy(new Vampire());
|
||||
|
||||
Location castleGate = new Location("Castle Gate", "The entrance to the Dragon's castle");
|
||||
castleGate.addEnemy(new Goblin());
|
||||
castleGate.addEnemy(new Vampire());
|
||||
|
||||
locations.add(forest);
|
||||
locations.add(crypt);
|
||||
locations.add(castleGate);
|
||||
}
|
||||
|
||||
public void moveToRandomLocation() {
|
||||
int index = random.nextInt(locations.size());
|
||||
currentLocation = locations.get(index);
|
||||
currentLocation.spawnRandomEnemy();
|
||||
}
|
||||
|
||||
public void moveToLocation(int index) {
|
||||
if (index >= 0 && index < locations.size()) {
|
||||
currentLocation = locations.get(index);
|
||||
currentLocation.spawnRandomEnemy();
|
||||
}
|
||||
}
|
||||
|
||||
public Location getCurrentLocation() {
|
||||
return currentLocation;
|
||||
}
|
||||
|
||||
public void displayLocations() {
|
||||
NarrativeConsole.printInfo("\n=== Available Locations ===");
|
||||
for (int i = 0; i < locations.size(); i++) {
|
||||
NarrativeConsole.printInfo((i + 1) + ". " + locations.get(i).getName());
|
||||
NarrativeConsole.printInfo(" " + locations.get(i).getDescription());
|
||||
}
|
||||
}
|
||||
|
||||
public ArrayList<Location> getLocations() {
|
||||
return locations;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package org.project.location;
|
||||
|
||||
public class NarrativeConsole {
|
||||
//Normal
|
||||
public static void printNormal(String message) {
|
||||
System.out.println(AnsiColors.WHITE + "⭐ " + message + AnsiColors.RESET);
|
||||
}
|
||||
|
||||
//Damage
|
||||
public static void printDamage(String message) {
|
||||
System.out.println(AnsiColors.RED + "💥 " + message + AnsiColors.RESET);
|
||||
}
|
||||
|
||||
//Heal
|
||||
public static void printHeal(String message) {
|
||||
System.out.println(AnsiColors.GREEN + "💚 " + message + AnsiColors.RESET);
|
||||
}
|
||||
|
||||
//Mana
|
||||
public static void printMana(String message) {
|
||||
System.out.println(AnsiColors.BLUE + "💙 " + message + AnsiColors.RESET);
|
||||
}
|
||||
|
||||
//Warning
|
||||
public static void printWarning(String message) {
|
||||
System.out.println(AnsiColors.YELLOW + "⚠️ " + message + AnsiColors.RESET);
|
||||
}
|
||||
|
||||
//Success
|
||||
public static void printSuccess(String message) {
|
||||
System.out.println(AnsiColors.BOLD_GREEN + "✨ " + message + AnsiColors.RESET);
|
||||
}
|
||||
|
||||
//Info
|
||||
public static void printInfo(String message) {
|
||||
System.out.println(AnsiColors.CYAN + "ℹ️ " + message + AnsiColors.RESET);
|
||||
}
|
||||
|
||||
//Error
|
||||
public static void printError(String message) {
|
||||
System.out.println(AnsiColors.BOLD_RED + "❌ " + message + AnsiColors.RESET);
|
||||
}
|
||||
|
||||
//Combat
|
||||
public static void printCombat(String message) {
|
||||
System.out.println(AnsiColors.PURPLE + "⚔️ " + message + AnsiColors.RESET);
|
||||
}
|
||||
|
||||
//Special
|
||||
public static void printSpecial(String message) {
|
||||
System.out.println(AnsiColors.BOLD_YELLOW + "⭐ " + message + AnsiColors.RESET);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,175 +1,235 @@
|
||||
# Fourth Assignment - Java Knight ⚔️
|
||||
A turn-based RPG with Roguelike elements which can be run in the terminal.
|
||||
|
||||
### **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**
|
||||
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**.
|
||||
|
||||
⚠️ **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.
|
||||
|
||||
🎯 **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.
|
||||
# ⚔️ Java Knight: A Turn-Based RPG
|
||||
|
||||
---
|
||||
|
||||
## Tasks 📝
|
||||
## 📖 Introduction
|
||||
|
||||
**Java Knight** is a terminal-based, turn-based role-playing game (RPG) developed in Java as a university assignment. The game incorporates Roguelike elements where the player must collect three unique keys by defeating cursed creatures to unlock the final boss fight against a Dragon.
|
||||
|
||||
---
|
||||
|
||||
## 🏹 Storyline
|
||||
|
||||
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 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 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!
|
||||
|
||||
---
|
||||
|
||||
## 🎮 How to Play
|
||||
|
||||
### Controls
|
||||
|
||||
During the game, you will be presented with menus and prompts. Use the number keys (1-5) to select options.
|
||||
|
||||
| Key | Action |
|
||||
|-----|-----------------------------|
|
||||
| 1 | Light Attack (0 Mana) |
|
||||
| 2 | Heavy Attack (-8 Mana) |
|
||||
| 3 | Defend (-6 Mana) |
|
||||
| 4 | Heal (-12 Mana) |
|
||||
| 5 | Special Ability (-15 Mana) |
|
||||
|
||||
### Game Flow
|
||||
|
||||
1. **Choose your warrior:** Knight, Wizard, or Assassin?
|
||||
|
||||
2. **Enter a location:** A random enemy (Goblin, Skeleton, or Vampire) spawns.
|
||||
|
||||
3. **Choose an action:** Fight, move to another location, or (later) go to the Castle!
|
||||
|
||||
4. **Turn-based combat:** Alternate attacks will be between you and the enemy!
|
||||
|
||||
5. **Recovery:** After each victory, your HP and Mana are fully restored!
|
||||
|
||||
6. **Key Collection:** Each defeated enemy has a 20% chance to drop their unique key!
|
||||
|
||||
7. **Level Up:** Defeating enemies grants experience; reaching thresholds increases your max HP and Mana!
|
||||
|
||||
8. **Final Boss:** After collecting all 3 keys, you can enter the Castle to fight the Dragon!
|
||||
|
||||
### Character Classes
|
||||
|
||||
| Class | HP |Mana| Special Ability |
|
||||
|---------------|-----|----|------------------------------------------------------------------|
|
||||
| Knight ⚔️ | 45 | 45 | Shield Bash – Deals heavy damage + stuns enemy |
|
||||
| Wizard 🧙♂️ | 60 | 45 | Devastating Spell – Deals massive damage + heals self |
|
||||
| Assassin 🗡️ | 45 | 60 | Invisibility – Next attack is critical, dodges next enemy attack |
|
||||
|
||||
### Enemies
|
||||
|
||||
|Enemy|HP| Damage | Special Ability |
|
||||
|-----|--|--------|---------------------------------------------------|
|
||||
|Goblin 👹| 30 | 10 | 40% critical hit chance |
|
||||
|Skeleton ☠️ | 45 | 10 | Resurrects once with 50% HP |
|
||||
|Vampire 🦇 | 55 | 12 | Lifesteal (40% of damage heals itself) |
|
||||
|Dragon (Boss) 🐉 | 150 | 25 | Immune to defense, fiery breath bypasses shields |
|
||||
|
||||
---
|
||||
|
||||
## Prerequisites
|
||||
Java Development Kit (JDK) 17 or higher
|
||||
|
||||
- **Git** (optional, for cloning)
|
||||
|
||||
### Step 1: Clone the Repository
|
||||
|
||||
### 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
|
||||
cd HW-04-JAVA-KNIGHT
|
||||
```
|
||||
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.
|
||||
### Step 2: Compile the Project
|
||||
|
||||
- **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) :
|
||||
Navigate to the project root directory (where the src folder is located) and run:
|
||||
|
||||
```bash
|
||||
You chose to FIGHT!
|
||||
javac -d out src/org/project/*.java src/org/project/entity/*.java src/org/project/entity/enemies/*.java src/org/project/entity/players/*.java src/org/project/item/*.java src/org/project/item/weapons/*.java src/org/project/item/armors/*.java src/org/project/item/consumables/*.java
|
||||
```
|
||||
|
||||
[Ser Duncan - 45/45 HP | 40/40 Mana]
|
||||
[Goblin - 30/30 HP]
|
||||
Or simply:
|
||||
|
||||
```bash
|
||||
javac -d out src/org/project/**/*.java src/org/project/*.java
|
||||
```
|
||||
|
||||
### Step 3: Run the Game
|
||||
|
||||
```bash
|
||||
java -cp out org.project.Main
|
||||
```
|
||||
|
||||
### Alternative (if you have an IDE):
|
||||
|
||||
1. Open the project in **IntelliJ IDEA, Eclipse**, or **VS Code**
|
||||
|
||||
2. Locate the `Main.java` file in `src/org/project/`
|
||||
|
||||
3. Click **Run** or press `Shift+F10`
|
||||
|
||||
---
|
||||
|
||||
Your Turn:
|
||||
1. Light Attack | 2. Heavy Attack (-8 Mana) | 3. Defend (-6 Mana) | 4. Heal (-12 Mana) | 5. Shield Bash (-15 Mana)
|
||||
## 🏗️ Project Architecture & OOP Principles
|
||||
|
||||
### Class Hierarchy
|
||||
|
||||
```plaintest
|
||||
Entity (abstract)
|
||||
├── Player (abstract)
|
||||
│ ├── Knight
|
||||
│ ├── Wizard
|
||||
│ └── Assassin
|
||||
└── Enemy (abstract)
|
||||
├── Goblin
|
||||
├── Skeleton
|
||||
├── Vampire
|
||||
└── Dragon
|
||||
|
||||
Item (interface)
|
||||
├── Weapon (abstract)
|
||||
│ ├── Sword
|
||||
│ ├── Staff
|
||||
│ ├── Dagger
|
||||
│ ├── BoneDagger
|
||||
│ ├── Claw
|
||||
│ └── DragonClaw
|
||||
├── Armor (abstract)
|
||||
│ ├── KnightArmor
|
||||
│ ├── WizardRobe
|
||||
│ └── LeatherArmor
|
||||
└── Consumable (abstract)
|
||||
└── Flask
|
||||
|
||||
ICombatActions (interface)
|
||||
└── Implemented by Player and Enemy
|
||||
```
|
||||
|
||||
```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).
|
||||
### OOP Principles Used
|
||||
|
||||
| Principle | Implementation |
|
||||
|---------------|-----------------------------------------------------------------------------------------------------|
|
||||
| Encapsulation | All fields are `private` or `protected` with public getters/setters |
|
||||
| Inheritance | `Player` and `Enemy` extend `Entity`; specific classes extend these |
|
||||
| Polymorphism | `Entity` references can point to any player/enemy object; `ICombatActions` unifies combat behaviors |
|
||||
| Abstraction | `Entity`, `Player`, `Enemy`, `Weapon`, `Armor` are abstract classes |
|
||||
| Interfaces | `ICombatActions` defines the 5 combat actions; `Item` defines consumable/equipment behavior |
|
||||
|
||||
### 4️⃣ Step 4: Implement the Game Loop & Progression 🎮
|
||||
### Design Patterns
|
||||
|
||||
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**.
|
||||
- **Template Method Pattern:** The `attack()` method in `Enemy` is overridden by each enemy type
|
||||
|
||||
🔹 Example game loop structure:
|
||||
- **Factory Pattern:** `spawnRandomEnemy()` creates enemies without exposing instantiation logic
|
||||
|
||||
```java
|
||||
while (player.isAlive() && enemy.isAlive())
|
||||
player.attack(enemy);
|
||||
if (enemy.isAlive()) {
|
||||
enemy.attack(player);
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
### 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).
|
||||
- **Strategy Pattern:** Each player class implements `ICombatActions` differently
|
||||
|
||||
---
|
||||
|
||||
## Evaluation Criteria ⚖
|
||||
## 📁 Package 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** |
|
||||
```plaintext
|
||||
src/org/project/
|
||||
├── Main.java
|
||||
├── entity/
|
||||
│ ├── Entity.java
|
||||
│ ├── players/
|
||||
│ │ ├── Player.java
|
||||
│ │ ├── Knight.java
|
||||
│ │ ├── Wizard.java
|
||||
│ │ └── Assassin.java
|
||||
│ └── enemies/
|
||||
│ ├── Enemy.java
|
||||
│ ├── Goblin.java
|
||||
│ ├── Skeleton.java
|
||||
│ ├── Vampire.java
|
||||
│ └── Dragon.java
|
||||
├── item/
|
||||
│ ├── Item.java
|
||||
│ ├── weapons/
|
||||
│ │ ├── Weapon.java
|
||||
│ │ ├── Sword.java
|
||||
│ │ ├── Staff.java
|
||||
│ │ ├── Dagger.java
|
||||
│ │ └── ...
|
||||
│ ├── armors/
|
||||
│ │ ├── Armor.java
|
||||
│ │ ├── KnightArmor.java
|
||||
│ │ ├── WizardRobe.java
|
||||
│ │ └── LeatherArmor.java
|
||||
│ └── consumables/
|
||||
│ ├── Consumable.java
|
||||
│ └── Flask.java
|
||||
└── location/
|
||||
└── Location.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.
|
||||
## 🎯 Game Features
|
||||
|
||||

|
||||
###### - Born of God and Void. You shall seal the blinding light that plagues their dreams. You are the Vessel. You are the Java Knight.
|
||||
- ✅ Turn-based combat system
|
||||
|
||||
- ✅ 3 playable classes with unique stats and abilities
|
||||
|
||||
- ✅ 4 enemy types including a final boss
|
||||
|
||||
- ✅ Random key drop system (20% chance)
|
||||
|
||||
- ✅ Experience and leveling system (XP scales with enemy strength)
|
||||
|
||||
- ✅ Full HP/Mana recovery after each battle
|
||||
|
||||
- ✅ Progressive unlocking of the Castle (requires 3 keys)
|
||||
|
||||
- ✅ Colorful console output using ANSI escape codes
|
||||
|
||||
---
|
||||
|
||||
## 👥 Contributors
|
||||
|
||||
Zahra Gharagozloo Mazlaghan – Advanced Programming Course
|
||||
|
||||
Instructor: Dr. Kheradpisheh
|
||||
|
||||
University: Shahid Beheshti University
|
||||
|
||||
---
|
||||
|
||||
**Enjoy the game, and may you break the curse of Javanest! ⚔️🐉**
|
||||
Reference in New Issue
Block a user