8 Commits
58 changed files with 1315 additions and 309 deletions
+5
View File
@@ -16,5 +16,10 @@
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://mirror-maven.runflare.com/maven2" />
</remote-repository>
</component>
</project>
@@ -0,0 +1,16 @@
package org.project;
public class ConsoleColors {
public static final String RESET = "\u001B[0m";
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";
public static final String BOLD = "\u001B[1m";
public static final String UNDERLINE = "\u001B[4m";
}
@@ -0,0 +1,87 @@
package org.project;
import java.util.Scanner;
import static org.project.ConsoleColors.*;
public class Help {
private Scanner scanner;
public Help(){
this.scanner = new Scanner(System.in);
}
public void showHelp() {
while(true) {
System.out.println("\n" + CYAN + BOLD + "===== Help Menu =====" + RESET);
System.out.println("What do you need help with, sir?");
System.out.println("1-What is Java-Knight?");
System.out.println("2-How to play");
System.out.println("0-Back");
System.out.println(CYAN + "=======================" + RESET);
int choice = getValidIntInput();
switch (choice) {
case 1: javaKnight(); break;
case 2: howTo(); break;
case 0: return;
default:
System.out.println(RED + "Invalid choice. Please choose a number between 0-2." + RESET);
}
}
}
private void javaKnight() {
System.out.println(WHITE + """
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!
""" + RESET);
System.out.println(GREEN + "\nPress ENTER to go back..." + RESET);
scanner.nextLine();
}
private void howTo() {
System.out.println(CYAN + "=== HOW TO PLAY ===" + RESET);
System.out.println();
System.out.println("Goal Defeat enemies to collect three unique keys (Goblin, Skeleton, Vampire), then storm the castle and slay the Dragon.");
System.out.println();
System.out.println("Choose Your Class Start as one of three heroes:");
System.out.println(" - Knight High damage.");
System.out.println(" - Assassin High stamina.");
System.out.println(" - Wizard High health.");
System.out.println();
System.out.println("Combat (Turn-Based) On your turn, choose one action:");
System.out.println(" 1. Light Attack Moderate damage, costs no mana (your fallback when out of mana).");
System.out.println(" 2. Heavy Attack High damage, costs mana.");
System.out.println(" 3. Special Ability Unique class move (highest mana cost).");
System.out.println(" 4. Defend Reduces or blocks the next enemy attack.");
System.out.println(" 5. Heal Restores HP, costs mana.");
System.out.println();
System.out.println("Progression");
System.out.println(" - After each victory, your HP and mana fully recover.");
System.out.println(" - Defeating enemies grants XP → leveling up increases max HP/mana.");
System.out.println(" - Each enemy has a chance (~20%) to drop its unique key. You only need one key per enemy type.");
System.out.println();
System.out.println("Locked Path The castle option is hidden until you collect all three keys. Only then can you face the final Dragon.");
System.out.println();
System.out.println("Game Over If your HP reaches zero, the game ends.");
System.out.println();
System.out.println("> \"Collect the keys. Break the curse. Save Javanest.\"");
System.out.println(GREEN + "\nPress ENTER to go back..." + RESET);
scanner.nextLine();
}
private int getValidIntInput() {
while (!scanner.hasNextInt()) {
System.out.print(RED + "Please enter a valid number: " + RESET);
scanner.next();
}
int input = scanner.nextInt();
scanner.nextLine(); // Clear buffer
return input;
}
}
@@ -1,15 +1,8 @@
package org.project;
import org.project.location.Location;
import java.util.ArrayList;
import java.util.List;
public class Main {
private static Menu menu = new Menu();
public static void main(String[] args) {
// TODO: ADD LOCATIONS TO YOUR GAME
List<Location> locations = new ArrayList<>();
// TODO: IMPLEMENT GAMEPLAY
menu.start();
}
}
@@ -0,0 +1,86 @@
package org.project;
import org.project.entity.players.Assassin;
import org.project.entity.players.Knight;
import org.project.entity.players.Player;
import org.project.entity.players.Wizard;
import java.util.Scanner;
import static org.project.ConsoleColors.*;
public class Menu {
private Scanner scanner = new Scanner(System.in);
private MenuActions actions = new MenuActions();
private Help helpMenu = new Help();
public void start() { //main menu, where everything starts from
while (true) {
System.out.println("\n" + CYAN + BOLD + "===== Java Knight =====" + RESET);
System.out.println(YELLOW + "Main menu" + RESET);
System.out.println("What would you like to do, sir?");
System.out.println("1-Start a game");
System.out.println("2-Show help and game tips.");
System.out.println("0-Exit");
System.out.println(CYAN + "=======================" + RESET);
int choice = getValidIntInput();
switch(choice) {
case 0: return;
case 1: startMenu(); break;
case 2: helpMenu.showHelp(); break;
default:
System.out.println(RED + "Invalid choice, please choose a number between 0-2" + RESET);
}
}
}
private void startMenu() { //game start menu, player chooses its character then the game itself is called.
Player player = chooseCharacter();
if (player == null) {
System.out.println(YELLOW + "Returning to the main menu..." + RESET);
start();
return;
}
actions.startGame(player);
}
public Player chooseCharacter() {
String name;
Player character = null;
System.out.println(CYAN + "Enter Your name: " + RESET);
name = scanner.nextLine();
System.out.println("\n" + YELLOW + "Choose a character: " + RESET);
System.out.println("1-Knight");
System.out.println("2-Wizard");
System.out.println("3-Assassin");
System.out.println("0-back");
boolean keepAsking = true;
while (keepAsking) {
int choice = getValidIntInput();
switch (choice) {
case 1: character = new Knight(name);
System.out.println(GREEN + "You are a knight!" + RESET);
keepAsking = false; break;
case 2: character = new Wizard(name);
System.out.println(GREEN + "You are a wizard!" + RESET);
keepAsking = false; break;
case 3: character = new Assassin(name);
System.out.println(GREEN + "You are an assassin!" + RESET);
keepAsking = false; break;
case 0: keepAsking = false; break;
default: System.out.println(RED + "Invalid choice, please choose a number between 0-3" + RESET);
}
}
return character;
}
private int getValidIntInput() { //a function to receive user's choices as console input
while (!scanner.hasNextInt()) {
System.out.print(RED + "Please enter a valid number: " + RESET);
scanner.next();
}
int input = scanner.nextInt();
scanner.nextLine(); // Clear buffer
return input;
}
}
@@ -0,0 +1,271 @@
package org.project;
import org.project.entity.Entity;
import org.project.entity.enemies.*;
import org.project.entity.players.Player;
import org.project.location.Location;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
import static org.project.ConsoleColors.*;
public class MenuActions { //this class contains main game logic.
private ArrayList<Location> locations;
Scanner scanner;
public MenuActions() {
this.scanner = new Scanner(System.in);
this.locations = new ArrayList<>();
}
public void startGame(Player player) { // gameplay starts from here
Skeleton.resetKeysRemaining();
Goblin.resetKeysRemaining();
Vampire.resetKeysRemaining();
while (player.getKeysCollectedCount() < 3) { //player keeps fighting until all 3 keys are collected
askInventory(player);
Enemy enemy = chooseEnemy();
Entity winner = fight(player, enemy);
if (winner != player) {
System.out.println(RED + "Game over!\nreturning to main menu..." + RESET);
break;
}
}
if (player.getKeysCollectedCount() == 3) {
bossFight(player);
}
}
private void bossFight(Player player) {
System.out.println(GREEN + "Congratulations! You have successfully collected all 3 keys\n" +
"You may now fight the Dragon" + RESET);
System.out.println(YELLOW + "Make sure to upgrade before entering the castle!" + RESET);
askInventory(player);
System.out.println(CYAN + "Entering the castle..." + RESET);
Entity winner = fight(player, new Dragon());
if (winner != player) {
System.out.println(RED + "You were killed by the dragon. Game over!\nreturning to main menu..." + RESET);
} else {
System.out.println(GREEN + BOLD + "Congratulations! You killed the dragon and saved Javanest!" + RESET);
}
}
private Enemy chooseEnemy() {
while (true) {
Location location = new Location();
Enemy enemy = location.getEnemies().get(0);
String enemyName = enemy.getType();
System.out.println(CYAN + "====================================" + RESET);
System.out.println("You are in the " + YELLOW + location.getName() + RESET +
".\nYou may fight with a " + enemyName);
System.out.println("Which option do you choose?" +"\n1- Fight with the "
+ enemyName + "\n2- Skip to Another Location");
outerLoop:
while (true) {
int choice = getValidIntInput();
switch (choice) {
case 1:
return enemy;
case 2:
System.out.println("You chose not to fight...Skipping to next location...");break outerLoop;
default:
System.out.println(RED + "Invalid choice. Please choose a number (1 or 2)." + RESET);
}
}
}
}
public Entity fight(Player player, Enemy enemy) {
player.heal(player.getMaxHP());
player.fillMana(player.getMaxMP());
Entity winner;
while (true) {
playerTurn(player, enemy);
if (enemy.getHp() == 0) {
winner = player;
System.out.println(GREEN + player.getName() + " won the fight!" + RESET);
if (!(enemy instanceof Dragon)) {
player.setXp(player.getXp()+5);
System.out.println(GREEN + player.getName() + " got 5 XP for winning the fight!" + RESET);
}
if (enemy instanceof Skeleton) {
boolean hasKey = ((Skeleton) enemy).generateKey();
if (hasKey) {
player.collectKey((Skeleton) enemy);
player.setXp(player.getXp()+20);
System.out.println(GREEN + player.getName() + " got a Skeleton key and 20 XP!" + RESET);
}
}
if (enemy instanceof Goblin) {
boolean hasKey = ((Goblin) enemy).generateKey();
if (hasKey) {
player.collectKey((Goblin) enemy);
player.setXp(player.getXp()+10);
System.out.println(GREEN + player.getName() + " got a Goblin key and 10 XP!" + RESET);
}
}
if (enemy instanceof Vampire) {
boolean hasKey = ((Vampire) enemy).generateKey();
if (hasKey) {
player.collectKey((Vampire) enemy);
player.setXp(player.getXp()+30);
System.out.println(GREEN + player.getName() + " got a Vampire key and 30 XP!" + RESET);
}
}
System.out.println("Keys collected: " + player.getStringKeysCollected());
return winner;
}
enemyTurn(player, enemy);
if (player.getHp() == 0) {
winner = enemy;
System.out.println(RED + winner.getType() + " won the fight!" + RESET);
return winner;
}
}
}
private void enemyTurn(Player player, Enemy enemy) {
System.out.println(CYAN + "====================================" + RESET);
System.out.println(YELLOW + "Enemy turn. Let's see what it does!" + RESET);
System.out.println("Your hp: " + player.getHp() + "/" + player.getMaxHP());
System.out.println("Enemy hp: " + enemy.getHp() + "/" + enemy.getMaxHP());
while (true) {
Random random = new Random();
int choice = random.nextInt(3) + 1;
switch (choice) {
case 1: enemy.getWeapon().lightAttack(player);
System.out.println(enemy.getType() + " attacked(light)!"); return;
case 2: if(enemy.getMp() >= enemy.getWeapon().getManaCost()) {
enemy.getWeapon().heavyAttack(enemy, player);
System.out.println(enemy.getType() + " attacked(Heavy)!"); return;
} break;
case 3: if (enemy.getMp() >= enemy.getWeapon().getSpecialMana()){
enemy.getWeapon().useSpecialAbility(enemy, player);
System.out.println(enemy.getType() + " used special ability!"); return;
} break;
default:
System.out.println(RED + "Invalid choice" + RESET);
}
}
}
private void playerTurn(Player player, Enemy enemy) {
System.out.println(CYAN + "====================================" + RESET);
System.out.println(YELLOW + "Player turn. What do you want to do?" + RESET);
System.out.println("Your hp: " + player.getHp() + "/" + player.getMaxHP() +
"\t Your mana: " + player.getMp() + "/" + player.getMaxMP());
System.out.println("Enemy hp: " + enemy.getHp() + "/" + enemy.getMaxHP());
System.out.println("1-Light attack, mana cost: 0");
System.out.println("2-Heavy attack, mana cost: " + player.getWeapon().getManaCost());
System.out.println("3-Special Ability, mana cost: " + player.getWeapon().getSpecialMana());
System.out.println("4-Defend, mana cost: " + player.getDefendManaCost());
System.out.println("5-Heal, mana cost: " + player.getHealManaCost());
while (true) {
int choice = getValidIntInput();
switch (choice) {
case 1: player.getWeapon().lightAttack(enemy);
System.out.println("You chose light attack.");return;
case 2: if(player.getMp() >= player.getWeapon().getManaCost()) {
player.getWeapon().heavyAttack(player, enemy);
System.out.println("You chose heavy attack.");return;
} else {
System.out.println(RED + "Not enough mana. Choose Again: " + RESET); break;
}
case 3: if (player.getMp() >= player.getWeapon().getSpecialMana()){
player.getWeapon().useSpecialAbility(player, enemy);
System.out.println("You chose special ability.");return;
} else {
System.out.println(RED + "Not enough mana. Choose Again: " + RESET); break;
}
case 4: if (player.getMp() >= player.getDefendManaCost()) {
player.defend();
System.out.println("You chose to defend."); return;
} else {
System.out.println(RED + "Not enough mana. Choose Again: " + RESET); break;
}
case 5: if (player.getMp() >= player.getHealManaCost()) {
player.heal(20); return;
} else {
System.out.println(RED + "Not enough mana. Choose Again:" + RESET);
System.out.println("You chose to heal yourself.");break;
}
default:
System.out.println(RED + "Invalid choice" + RESET);
}
}
}
private void askInventory(Player player) {
whileLoop:
while (true) {
System.out.println("Choose an option: ");
System.out.println("1- Go to the inventory");
System.out.println("2- Continue to next fight");
int choice = getValidIntInput();
switch (choice) {
case 1: shop(player); break;
case 2: return;
default:
System.out.println(RED + "Invalid choice, please choose a number (1 or 2)." + RESET); break;
}
}
}
private void shop(Player player) {
while (true) {
System.out.println(CYAN + "=====Shop=====" + RESET); // exactly original string
System.out.println("You have " + YELLOW + player.getXp() + " XP" + RESET);
System.out.println("Each experience point can be converted into either 1 mana or 1 hp");
System.out.println("Which option do you choose?");
System.out.println("1- Buy hp");
System.out.println("2- Buy mana");
System.out.println("0- Back");
switchLoop:
while(true) {
int choice = getValidIntInput();
switch (choice) {
case 1:
while (true) {
System.out.println("Enter amount: " + "\tShould be less than or equal to " + player.getXp());
int amount = getValidIntInput();
if (amount <= player.getXp()) {
player.buyHp(amount);
System.out.println(GREEN + "Successfully bought " + amount + " hp." + RESET);
System.out.println("Current hp and mana: " + "\thp: " + player.getMaxHP() +"\tmana: " + player.getMaxMP());
break switchLoop;
} else if (amount > player.getXp()) {
System.out.println(RED + "Not enough XP" + RESET);
}
}
case 2:
while (true) {
System.out.println("Enter amount: " + "\tShould be less than or equal to " + player.getXp());
int amount = getValidIntInput();
if (amount <= player.getXp()) {
player.buyMp(amount);
System.out.println(GREEN + "Successfully bought " + amount + " mana." + RESET);
System.out.println("Current maximum hp and mana: " + "\thp: " + player.getMaxHP() +"\tmana: " + player.getMaxMP());
break switchLoop;
} else if (amount > player.getXp()) {
System.out.println(RED + "Not enough XP" + RESET);
}
}
case 0: return;
default:
System.out.println(RED + "Invalid choice. Please choose a number from 0-2." + RESET);
}
}
}
}
private int getValidIntInput() {
while (!scanner.hasNextInt()) {
System.out.print(RED + "Please enter a valid number: " + RESET);
scanner.next();
}
int input = scanner.nextInt();
scanner.nextLine(); // Clear buffer
return input;
}
}
@@ -1,8 +1,6 @@
package org.project.entity;
public interface Entity {
void attack(Entity target);
void defend();
void heal(int health);
@@ -11,11 +9,17 @@ public interface Entity {
void takeDamage(int damage);
void reduceMana(int mana);
int getMaxHP();
int getMaxMP();
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
String getType();
int getHealManaCost();
int getDefendManaCost();
// void skipNextTurn(); /disabled
// void skipTurn(); /disabled
}
@@ -0,0 +1,28 @@
package org.project.entity.enemies;
import org.project.item.weapons.BoneHarpoon;
import org.project.item.weapons.TailScythe;
import org.project.item.weapons.Weapon;
public class Dragon extends Enemy{
private static int DEFAULT_HP = 200;
private static int DEFAULT_MP = 200;
private static TailScythe DEFAULT_WEAPON = new TailScythe();
private static int DEFAULT_HEAL_MANA_COST = 20;
private static int DEFAULT_DEFEND_MANA_COST = 20;
public Dragon() {
super(DEFAULT_HP, DEFAULT_MP, DEFAULT_WEAPON,
DEFAULT_HEAL_MANA_COST, DEFAULT_DEFEND_MANA_COST);
}
public Dragon(String name, int hp, int mp, Weapon weapon,
int healManaCost, int defendManaCost) {
super(hp, mp, weapon, healManaCost, defendManaCost);
}
@Override
public String getType() {
return "Dragon";
}
}
@@ -1,33 +1,107 @@
package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.item.weapons.Weapon;
// TODO: UPDATE IMPLEMENTATION
public abstract class Enemy {
public abstract class Enemy implements Entity {
Weapon weapon;
private int hp;
private int maxHP;
private int mp;
public Enemy(int hp, int mp, Weapon weapon) {
private int maxMP;
// private boolean canPlayThisTurn = true;
private boolean isDefendingThisTurn = false;
private int healManaCost;
private int defendManaCost;
public Enemy(int hp, int mp, Weapon weapon,
int healManaCost, int defendManaCost) {
this.hp = hp;
this.mp = mp;
this.maxHP = hp;
this.maxMP = mp;
this.weapon = weapon;
this.healManaCost = healManaCost;
this.defendManaCost = defendManaCost;
}
@Override
public void defend() {
isDefendingThisTurn = true;
}
@Override
public void takeDamage(int damage) {
hp -= damage;
if (!isDefendingThisTurn) {
hp -= damage;
if (hp < 0) {
hp = 0;
}
} else {
isDefendingThisTurn = false;
}
}
@Override
public void heal(int health) {
hp += health;
if (hp > maxHP) {
hp = maxHP;
}
}
@Override
public void fillMana(int mana) {
mp += mana;
if (mp > maxMP) {
mp = maxMP;
}
}
@Override
public void reduceMana(int mana) {
mp -= mana;
if (mp < 0) {
mp = 0;
}
}
// @Override //disabled
// public void skipNextTurn() {
// this.canPlayThisTurn = false;
// }
// @Override //disabled
// public void skipTurn() {
// this.canPlayThisTurn = true;
// }
@Override
public String getType() {
return "Enemy";
}
public int getHp() {
return hp;
}
@Override
public int getMaxHP() {
return maxHP;
}
public int getMp() {
return mp;
}
@Override
public int getMaxMP() {
return maxMP;
}
public int getHealManaCost() {
return healManaCost;
}
public int getDefendManaCost() {
return defendManaCost;
}
public Weapon getWeapon() {
return weapon;
}
@@ -0,0 +1,63 @@
package org.project.entity.enemies;
import org.project.item.weapons.BoneHarpoon;
import org.project.item.weapons.GoblinSickle;
import org.project.item.weapons.Weapon;
import java.util.Random;
public class Goblin extends Enemy implements Key{
private static int DEFAULT_HP = 80;
private static int DEFAULT_MP = 120;
private static GoblinSickle DEFAULT_WEAPON = new GoblinSickle();
private static int DEFAULT_HEAL_MANA_COST = 30;
private static int DEFAULT_DEFEND_MANA_COST = 20;
private static int keysRemaining = 1;
public Goblin() {
super(DEFAULT_HP, DEFAULT_MP, DEFAULT_WEAPON,
DEFAULT_HEAL_MANA_COST, DEFAULT_DEFEND_MANA_COST);
}
public Goblin(String name, int hp, int mp, Weapon weapon,
int healManaCost, int defendManaCost) {
super(hp, mp, weapon, healManaCost, defendManaCost);
}
@Override
public String getType() {
return "Goblin" ;
}
@Override
public boolean generateKey() {
if (keysRemaining > 0) {
Random random = new Random();
int dice = random.nextInt(1);
if (dice == 0) {
decreaseKey();
return true;
}
}
return false;
}
@Override
public void decreaseKey() {
keysRemaining -= 1;
}
@Override
public int getKeysRemaining() {
return keysRemaining;
}
@Override
public String getKeyType() {
return "Goblin";
}
public static void resetKeysRemaining() {
keysRemaining = 1;
}
}
@@ -0,0 +1,9 @@
package org.project.entity.enemies;
public interface Key {
boolean generateKey();
void decreaseKey();
int getKeysRemaining();
String getKeyType();
}
@@ -1,6 +1,63 @@
package org.project.entity.enemies;
// TODO: UPDATE IMPLEMENTATION
public class Skeleton {
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
import org.project.item.weapons.BoneHarpoon;
import org.project.item.weapons.Weapon;
import java.util.Random;
public class Skeleton extends Enemy implements Key {
private static int DEFAULT_HP = 100;
private static int DEFAULT_MP = 100;
private static BoneHarpoon DEFAULT_WEAPON = new BoneHarpoon();
private static int DEFAULT_HEAL_MANA_COST = 30;
private static int DEFAULT_DEFEND_MANA_COST = 20;
private static int keysRemaining = 1;
public Skeleton() {
super(DEFAULT_HP, DEFAULT_MP, DEFAULT_WEAPON,
DEFAULT_HEAL_MANA_COST, DEFAULT_DEFEND_MANA_COST);
}
public Skeleton(String name, int hp, int mp, Weapon weapon,
int healManaCost, int defendManaCost) {
super(hp, mp, weapon, healManaCost, defendManaCost);
}
@Override
public String getType() {
return "Skeleton" ;
}
@Override
public boolean generateKey() {
if (keysRemaining > 0) {
Random random = new Random();
int dice = random.nextInt(1);
if (dice == 0) {
decreaseKey();
return true;
}
}
return false;
}
@Override
public void decreaseKey() {
keysRemaining -= 1;
}
@Override
public int getKeysRemaining() {
return keysRemaining;
}
@Override
public String getKeyType() {
return "Skeleton";
}
public static void resetKeysRemaining() {
keysRemaining = 1;
}
}
@@ -0,0 +1,63 @@
package org.project.entity.enemies;
import org.project.item.weapons.GoblinSickle;
import org.project.item.weapons.MirrorClaws;
import org.project.item.weapons.Weapon;
import java.util.Random;
public class Vampire extends Enemy implements Key{
private static int DEFAULT_HP = 150;
private static int DEFAULT_MP = 150;
private static MirrorClaws DEFAULT_WEAPON = new MirrorClaws();
private static int DEFAULT_HEAL_MANA_COST = 30;
private static int DEFAULT_DEFEND_MANA_COST = 20;
private static int keysRemaining = 1;
public Vampire() {
super(DEFAULT_HP, DEFAULT_MP, DEFAULT_WEAPON,
DEFAULT_HEAL_MANA_COST, DEFAULT_DEFEND_MANA_COST);
}
public Vampire(String name, int hp, int mp, Weapon weapon,
int healManaCost, int defendManaCost) {
super(hp, mp, weapon, healManaCost, defendManaCost);
}
@Override
public String getType() {
return "Vampire" ;
}
@Override
public boolean generateKey() {
if (keysRemaining > 0) {
Random random = new Random();
int dice = random.nextInt(1);
if (dice == 0) {
decreaseKey();
return true;
}
}
return false;
}
@Override
public void decreaseKey() {
keysRemaining -= 1;
}
@Override
public int getKeysRemaining() {
return keysRemaining;
}
@Override
public String getKeyType() {
return "Vampire";
}
public static void resetKeysRemaining() {
keysRemaining = 1;
}
}
@@ -0,0 +1,36 @@
package org.project.entity.players;
import org.project.item.weapons.Sword;
import org.project.item.weapons.Weapon;
public class Assassin extends Player {
private static int DEFAULT_HP = 80;
private static int DEFAULT_MP = 100;
private static Sword DEFAULT_WEAPON = new Sword();
private static String DEFAULT_NAME = "Hasan";
private static int DEFAULT_HEAL_MANA_COST = 20;
private static int DEFAULT_DEFEND_MANA_COST = 15;
public Assassin() {
super(DEFAULT_NAME, DEFAULT_HP, DEFAULT_MP, DEFAULT_WEAPON,
DEFAULT_HEAL_MANA_COST, DEFAULT_DEFEND_MANA_COST);
}
public Assassin(String name) {
super(name, DEFAULT_HP, DEFAULT_MP, DEFAULT_WEAPON,
DEFAULT_HEAL_MANA_COST, DEFAULT_DEFEND_MANA_COST);
}
public Assassin(String name, int hp, int mp, Weapon weapon,
int healManaCost, int defendManaCost) {
super(name, hp, mp, weapon, healManaCost, defendManaCost);
}
@Override
public String getType() {
return "Assassin" ;
}
}
@@ -1,6 +1,37 @@
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.item.weapons.Sword;
import org.project.item.weapons.Weapon;
public class Knight extends Player {
private static int DEFAULT_HP = 100;
private static int DEFAULT_MP = 80;
private static Sword DEFAULT_WEAPON = new Sword();
private static String DEFAULT_NAME = "Ser Duncan";
private static int DEFAULT_HEAL_MANA_COST = 30;
private static int DEFAULT_DEFEND_MANA_COST = 20;
public Knight() {
super(DEFAULT_NAME, DEFAULT_HP, DEFAULT_MP, DEFAULT_WEAPON,
DEFAULT_HEAL_MANA_COST, DEFAULT_DEFEND_MANA_COST);
}
public Knight(String name) {
super(name, DEFAULT_HP, DEFAULT_MP, DEFAULT_WEAPON,
DEFAULT_HEAL_MANA_COST, DEFAULT_DEFEND_MANA_COST);
}
public Knight(String name, int hp, int mp, Weapon weapon,
int healManaCost, int defendManaCost) {
super(name, hp, mp, weapon, healManaCost, defendManaCost);
}
@Override
public String getType() {
return "Knight" ;
}
}
@@ -1,49 +1,71 @@
package org.project.entity.players;
import org.project.entity.Entity;
import org.project.item.armors.Armor;
import org.project.entity.enemies.Key;
import org.project.item.weapons.Weapon;
// TODO: UPDATE IMPLEMENTATION
public abstract class Player {
import java.util.ArrayList;
public abstract class Player implements Entity{
protected String name;
Weapon weapon;
Armor armor;
private int hp;
private int maxHP;
private int mp;
private int maxMP;
private boolean canPlayThisTurn = true;
private boolean isDefendingThisTurn = false;
private int healManaCost;
private int defendManaCost;
private int keysCollectedCount;
private int xp = 0;
private ArrayList<String> keysByType = new ArrayList<>();
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
public Player(String name, int hp, int mp, Weapon weapon,
int healManaCost, int defendManaCost) {
this.name = name;
this.hp = hp;
this.mp = mp;
this.maxHP = hp;
this.maxMP = mp;
this.weapon = weapon;
this.armor = armor;
this.keysCollectedCount = 0;
this.healManaCost = healManaCost;
this.defendManaCost = defendManaCost;
}
@Override
public void attack(Entity target) {
target.takeDamage(weapon.getDamage());
public void collectKey(Key enemy) {
addKey(enemy.getKeyType());
keysCollectedCount += 1;
}
@Override
public void defend() {
// TODO
isDefendingThisTurn = true;
this.reduceMana(this.getDefendManaCost());
}
@Override
public void takeDamage(int damage) {
hp -= damage - armor.getDefense();
if (!isDefendingThisTurn) {
hp -= damage;
if (hp < 0) {
hp = 0;
}
} else {
isDefendingThisTurn = false;
}
}
@Override
public void heal(int health) {
hp += health;
if (hp > maxHP) {
hp = maxHP;
if (hp < maxHP) {
hp += health;
if (hp > maxHP) {
hp = maxHP;
}
this.reduceMana(this.getHealManaCost());
}
}
@@ -55,7 +77,22 @@ public abstract class Player {
}
}
@Override
public void reduceMana(int mana) {
mp -= mana;
if (mp < 0) {
mp = 0;
}
}
// @Override
// public void skipNextTurn() {
// this.canPlayThisTurn = false;
// }
// @Override
// public void skipTurn() {
// this.canPlayThisTurn = true;
// }
public String getName() {
return name;
}
@@ -69,6 +106,10 @@ public abstract class Player {
return maxHP;
}
public void setMaxHP(int maxHP) {
this.maxHP = maxHP;
}
public int getMp() {
return mp;
}
@@ -77,13 +118,57 @@ public abstract class Player {
public int getMaxMP() {
return maxMP;
}
public void setMaxMP(int maxMP) {
this.maxMP = maxMP;
}
public Weapon getWeapon() {
return weapon;
}
public Armor getArmor() {
return armor;
public int getKeysCollectedCount() {
return keysCollectedCount;
}
@Override
public String getType() {
return "Player";
}
public int getHealManaCost() {
return healManaCost;
}
public int getXp() {
return xp;
}
public void setXp(int xp) {
this.xp = xp;
}
public void buyHp(int amount) {
if (amount <= this.getXp()) {
this.setXp(this.getXp() - amount);
this.setMaxHP(this.getMaxHP() + amount);
}
}
public void buyMp(int amount) {
if (amount <= this.getXp()) {
this.setXp(this.getXp() - amount);
this.setMaxMP(this.getMaxMP() + amount);
}
}
public int getDefendManaCost() {
return defendManaCost;
}
public void addKey(String type) {
keysByType.add(type);
}
public String getStringKeysCollected() {
String result = "Count: " + keysCollectedCount + " ";
for (String key: keysByType) {
result += " " + key + " key";
}
return result;
}
}
@@ -0,0 +1,36 @@
package org.project.entity.players;
import org.project.item.weapons.Fireball;
import org.project.item.weapons.Weapon;
public class Wizard extends Player{
private static int DEFAULT_HP = 90;
private static int DEFAULT_MP = 90;
private static Fireball DEFAULT_WEAPON = new Fireball();
private static String DEFAULT_NAME = "Merlin";
private static int DEFAULT_HEAL_MANA_COST = 25;
private static int DEFAULT_DEFEND_MANA_COST = 25;
public Wizard() {
super(DEFAULT_NAME, DEFAULT_HP, DEFAULT_MP, DEFAULT_WEAPON,
DEFAULT_HEAL_MANA_COST, DEFAULT_DEFEND_MANA_COST);
}
public Wizard(String name) {
super(name, DEFAULT_HP, DEFAULT_MP, DEFAULT_WEAPON,
DEFAULT_HEAL_MANA_COST, DEFAULT_DEFEND_MANA_COST);
}
public Wizard(String name, int hp, int mp, Weapon weapon,
int healManaCost, int defendManaCost) {
super(name, hp, mp, weapon, healManaCost, defendManaCost);
}
@Override
public String getType() {
return "Wizard" ;
}
}
@@ -3,9 +3,7 @@ package org.project.item;
import org.project.entity.Entity;
public interface Item {
void use(Entity target);
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
String getType();
String getExplanation();
}
@@ -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;
}
}
@@ -1,6 +0,0 @@
package org.project.item.armors;
// TODO: UPDATE IMPLEMENTATION
public class KnightArmor {
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
}
@@ -1,8 +0,0 @@
package org.project.item.consumables;
// TODO: UPDATE IMPLEMENTATION
public abstract class Consumable {
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
}
@@ -1,16 +0,0 @@
package org.project.item.consumables;
import org.project.entity.Entity;
// TODO: UPDATE IMPLEMENTATION
public class Flask {
/*
THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN.
*/
// TODO: UPDATE USE METHOD
@Override
public void use(Entity target) {
target.heal(target.getMaxHP() / 10);
}
}
@@ -0,0 +1,28 @@
package org.project.item.weapons;
import org.project.entity.Entity;
public class BoneHarpoon extends Weapon{
private static int DEFAULT_DAMAGE = 15;
private static int DEFAULT_MANACOST = 10;
private static int DEFAULT_SPECIAL_MANA = 20;
public BoneHarpoon() {
super(DEFAULT_DAMAGE, DEFAULT_MANACOST, DEFAULT_SPECIAL_MANA);
}
@Override
public void useSpecialAbility(Entity attacker, Entity target) {
target.takeDamage(this.getDamage() + 10);
attacker.reduceMana(this.getSpecialMana());
}
@Override
public String getType() {
return "Bone Harpoon(Skeletons)";
}
@Override
public String getExplanation() {
return "Melee slashing tool for skeletons.\n"+
"Damage: "+ this.getDamage() +" Mana cost: " + this.getManaCost();
}
}
@@ -0,0 +1,29 @@
package org.project.item.weapons;
import org.project.entity.Entity;
public class Dagger extends Weapon{
private static int DEFAULT_DAMAGE = 15;
private static int DEFAULT_MANACOST = 15;
private static int DEFAULT_SPECIAL_MANA = 30;
public Dagger() {
super(DEFAULT_DAMAGE, DEFAULT_MANACOST, DEFAULT_SPECIAL_MANA);
}
@Override
public void useSpecialAbility(Entity attacker, Entity target) {
target.takeDamage(50);
attacker.reduceMana(this.getSpecialMana());
}
@Override
public String getType() {
return "Dagger(Assassins)";
}
@Override
public String getExplanation() {
return "Melee piercing for Assassins.\n"+
"Damage: "+ this.getDamage() +" Mana cost: " + this.getManaCost();
}
}
@@ -0,0 +1,28 @@
package org.project.item.weapons;
import org.project.entity.Entity;
public class Fireball extends Weapon{
private static int DEFAULT_DAMAGE = 15;
private static int DEFAULT_MANACOST = 20;
private static int DEFAULT_SPECIAL_MANA = 25;
public Fireball() {
super(DEFAULT_DAMAGE, DEFAULT_MANACOST, DEFAULT_SPECIAL_MANA);
}
@Override
public void useSpecialAbility(Entity attacker, Entity target) {
target.takeDamage(this.getDamage() * 3);
attacker.reduceMana(this.getSpecialMana());
}
@Override
public String getType() {
return "Dagger(Assassins)";
}
@Override
public String getExplanation() {
return "Magical balls of fire for Wizards.\n"+
"Damage: "+ this.getDamage() +" Mana cost: " + this.getManaCost();
}
}
@@ -0,0 +1,30 @@
package org.project.item.weapons;
import org.project.entity.Entity;
public class GoblinSickle extends Weapon {
private static int DEFAULT_DAMAGE = 10;
private static int DEFAULT_MANACOST = 10;
private static int DEFAULT_SPECIAL_MANA = 20;
public GoblinSickle() {
super(DEFAULT_DAMAGE, DEFAULT_MANACOST, DEFAULT_SPECIAL_MANA);
}
@Override
public void useSpecialAbility(Entity attacker, Entity target) {
target.takeDamage(this.getDamage()*2);
attacker.reduceMana(this.getSpecialMana());
}
@Override
public String getType() {
return "Goblin Sickle(Goblins)";
}
@Override
public String getExplanation() {
return "Melee slashing tool for goblins. Causes bleeding over time.\n" +
"Damage: "+ this.getDamage() +" Mana cost: " + this.getManaCost();
}
}
@@ -0,0 +1,30 @@
package org.project.item.weapons;
import org.project.entity.Entity;
public class MirrorClaws extends Weapon{
private static int DEFAULT_DAMAGE = 25;
private static int DEFAULT_MANACOST = 15;
private static int DEFAULT_SPECIAL_MANA = 20;
public MirrorClaws() {
super(DEFAULT_DAMAGE, DEFAULT_MANACOST, DEFAULT_SPECIAL_MANA);
}
@Override
public void useSpecialAbility(Entity attacker, Entity target) {
target.takeDamage(this.getDamage());
target.reduceMana(30);
attacker.reduceMana(this.getSpecialMana());
}
@Override
public String getType() {
return "Mirror Claws(Vampires)";
}
@Override
public String getExplanation() {
return "Melee slashing weapon for vampires. Inflicts \"reflection\" debuff.\n" +
"Damage: "+ this.getDamage() +" Mana cost: " + this.getManaCost();
}
}
@@ -5,22 +5,27 @@ import org.project.entity.Entity;
import java.util.ArrayList;
// TODO: UPDATE IMPLEMENTATION
public class Sword {
/*
THIS IS AN EXAMPLE OF A WEAPON DESIGN.
*/
public class Sword extends Weapon {
private static int DEFAULT_DAMAGE = 20;
private static int DEFAULT_MANACOST = 20;
private static int DEFAULT_SPECIAL_MANA = 30;
int abilityCharge;
public Sword() {
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
super(DEFAULT_DAMAGE, DEFAULT_MANACOST, DEFAULT_SPECIAL_MANA);
}
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
public void uniqueAbility(ArrayList<Entity> targets) {
abilityCharge += 2;
for (Entity target : targets) {
target.takeDamage(getDamage());
}
@Override
public void useSpecialAbility(Entity attacker, Entity target) {
target.takeDamage(this.getDamage()* 2 + 5);
attacker.reduceMana(this.getSpecialMana());
}
@Override
public String getType() {
return "Sword(Knights)";
}
@Override
public String getExplanation() {
return "Melee piercing/bludgeoning for knights.";
}
}
@@ -0,0 +1,30 @@
package org.project.item.weapons;
import org.project.entity.Entity;
public class TailScythe extends Weapon{
private static int DEFAULT_DAMAGE = 40;
private static int DEFAULT_MANACOST = 20;
private static int DEFAULT_SPECIAL_MANA = 20;
public TailScythe() {
super(DEFAULT_DAMAGE, DEFAULT_MANACOST, DEFAULT_SPECIAL_MANA);
}
@Override
public void useSpecialAbility(Entity attacker, Entity target) {
target.takeDamage(this.getDamage() + 20);
attacker.reduceMana(this.getManaCost() + 5);
// target.skipNextTurn(); disabled
}
@Override
public String getType() {
return "Tail Scythe(Dragons)";
}
@Override
public String getExplanation() {
return "Melee sweeping attack for Dragons. Hitting targets with its tail.\n" +
"Damage: "+ this.getDamage() +" Mana cost: " + this.getManaCost();
}
}
@@ -1,24 +1,25 @@
package org.project.item.weapons;
import org.project.entity.Entity;
import org.project.item.Item;
// TODO: UPDATE IMPLEMENTATION
public abstract class Weapon {
public abstract class Weapon implements Item {
private int damage;
private int manaCost;
private int specialMana;
/*
TODO: ADD OTHER REQUIRED AND BONUS ATTRIBUTES
*/
public Weapon(int damage, int manaCost) {
public Weapon(int damage, int manaCost, int specialMana) {
this.damage = damage;
this.manaCost = manaCost;
this.specialMana = specialMana;
}
public void setManaCost(int manaCost) {
this.manaCost = manaCost;
}
@Override
public void use(Entity target) {
target.takeDamage(damage);
public void setDamage(int damage) {
this.damage = damage;
}
public int getDamage() {
@@ -29,7 +30,21 @@ public abstract class Weapon {
return manaCost;
}
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
public int getSpecialMana() {
return specialMana;
}
public void setSpecialMana(int specialMana) {
this.specialMana = specialMana;
}
public void lightAttack(Entity target) {
target.takeDamage(this.getDamage());
}
public void heavyAttack(Entity attacker, Entity target){
target.takeDamage(this.getDamage() * 2);
attacker.reduceMana(this.getManaCost());
}
public abstract void useSpecialAbility(Entity attacker, Entity target);
}
@@ -1,27 +1,77 @@
package org.project.location;
import org.project.entity.enemies.Enemy;
import org.project.entity.enemies.Goblin;
import org.project.entity.enemies.Skeleton;
import org.project.entity.enemies.Vampire;
import org.project.item.weapons.BoneHarpoon;
import org.project.item.weapons.Sword;
import org.project.item.weapons.Weapon;
import java.util.ArrayList;
import java.util.Random;
public class Location {
private String name;
private ArrayList<Enemy> enemies;
public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) {
this.locations = locations;
this.enemies = enemies;
public Location() {
this.name = pickName();
this.enemies = new ArrayList<>();
addEnemy();
}
public Location(String name, ArrayList<Enemy> enemies) {
this.name = name;
this.enemies = enemies;
addEnemy();
}
public Location(String name) {
this.name = name;
this.enemies = new ArrayList<>();
addEnemy();
}
private void addEnemy() {
Random random = new Random();
int enemyId = random.nextInt(3);
Enemy e = null;
switch (enemyId) {
case 0: e = new Skeleton(); break;
case 1: e = new Goblin(); break;
case 2: e = new Vampire(); break;
}
this.enemies.add(e);
}
private void addSkeleton() {
Enemy e = new Skeleton();
this.enemies.add(e);
}
private void addGoblin() {
Enemy e = new Goblin();
this.enemies.add(e);
}
private void addVampire() {
Enemy e = new Vampire();
this.enemies.add(e);
}
public static String pickName() {
String[] locations = {
"Tomb", "Yard", "Road", "Jungle", "Pit", "Swamp", "Hill",
"Den", "Ditch", "Cave", "Bog", "Woods", "Cliff", "Edge",
"Crack", "Brush", "Mound"
};
Random rand = new Random();
String chosen = locations[rand.nextInt(locations.length)];
return chosen;
}
public String getName() {
return name;
}
public ArrayList<Location> getLocations() {
return locations;
}
public ArrayList<Enemy> getEnemies() {
return enemies;
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
+47 -156
View File
@@ -1,175 +1,66 @@
# Fourth Assignment - Java Knight ⚔️
A turn-based RPG with Roguelike elements which can be run in the terminal.
# ⚔️ Java Knight: The Legend of Javanest
### **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 is a turn-based, console-based RPG built in Java. Players take on the role of a hero tasked with saving the land of Javanest by defeating monsters, collecting mystical keys, and ultimately slaying the Dragon.
---
## Tasks 📝
## 🚀 Quick Start
### 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 🌲
**Prerequisites:** Java JDK 8 or higher.
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]
1. **Navigate to the source root:**
```bash
cd your-project-folder/src
```
2. **Compile the project:**
```bash
javac org/project/Main.java
```
3. **Run the game:**
```bash
java org.project.Main
```
---
Your Turn:
1. Light Attack | 2. Heavy Attack (-8 Mana) | 3. Defend (-6 Mana) | 4. Heal (-12 Mana) | 5. Shield Bash (-15 Mana)
```
## ⚙️ Game Mechanics
```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).
### 4️⃣ Step 4: Implement the Game Loop & Progression 🎮
1. **The Core Loop:** The game starts with the player entering a location. A random standard enemy (`Goblin`, `Skeleton`, or `Vampire`) spawns immediately.
2. **Player Choices:** Before engaging, the player is presented with the following options:
- **1. Fight the enemy:** Enter the turn-based combat sequence.
- **2. Move to another location:** Skip the current enemy and spawn a new random one.
- **3. Go to the Castle to fight the Dragon:** *(Note: This option must remain strictly hidden or locked until the player has successfully collected all 3 keys).*
3. **The Key Drop Logic (RNG Gatekeeping):**
- When the player defeats an enemy, there is a **specific percentage chance (e.g., 20%)** that it will drop the unique key associated with its species (Goblin Key, Skeleton Key, Vampire Key).
- **One Key Per Species:** Once a player obtains a specific key (e.g., Goblin Key), subsequent enemies of that same type (other Goblins) will **never** drop a key again.
- The player **must collect all 3 distinct keys** to unlock Option 3 and enter the Castle.
4. **Post-Combat Recovery:** After each successful battle, the player's HP and Mana bars must automatically replenish (either fully or partially) to their base amounts so they are ready for the next encounter.
5. **Experience & Leveling System:**
- Defeating an enemy grants **XP**. The amount of XP must scale proportionally to the enemy's power level.
- Upon reaching an XP threshold, the player levels up. **Leveling up must automatically increase the player's Max HP and Max Stamina/Mana**, making them strong enough to eventually face the Dragon.
6. **Final Boss Fight:** Once the 3 Keys are obtained and the player chooses to go to the Castle, they will face the Dragon. Defeating the Dragon breaks the curse, resulting in **Victory**. Dying at any point results in **Game Over**.
🔹 Example game loop structure:
```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).
- **Progression & XP:** After each victory, your HP and Mana are fully recovered. Defeating enemies grants Experience Points (XP).
- **The Shop:** Between fights, you can visit the inventory to convert XP into permanent stat upgrades. 1 XP can be exchanged for either 1 Max HP or 1 Max MP.
- **The Hunt for Keys:** To reach the end-game, you must collect three unique keys (Goblin, Skeleton, and Vampire). These have a chance to drop after defeating the respective enemy type.
- **The Castle:** The path to the final boss is locked until all three keys are in your possession. Only then can you enter the castle to face the Dragon.
---
## Evaluation Criteria ⚖
## 🎮 How to Play
| **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** |
### Hero Classes
- **Knight:** Balanced stats with high-damage melee capabilities.
- **Assassin:** High stamina/mana efficiency with lower costs for defending.
- **Wizard:** High mana pool and powerful magical abilities.
## 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.
### Combat Actions
On your turn, choose one of the following:
1. **Light Attack:** Moderate damage; costs **0 Mana**.
2. **Heavy Attack:** High damage; costs Mana.
3. **Special Ability:** Unique class-based move; highest Mana cost.
4. **Defend:** Reduces or blocks the next enemy attack; costs Mana.
5. **Heal:** Restores HP during combat; costs Mana.
## 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.
---
## 🛠 Technical Architecture & OOP Principles
This project demonstrates core Object-Oriented Programming principles:
- **Inheritance:** Uses hierarchies for `Player` (Knight/Wizard/Assassin) and `Enemy` (Goblin/Skeleton/Vampire/Dragon) to share common logic while allowing unique overrides.
- **Polymorphism:** The combat engine handles any `Entity` implementation. The `Weapon` system allows different damage behaviors to be executed through a single interface.
- **Encapsulation:** Core stats like HP, Mana, and XP are protected. Data integrity is maintained through getters, setters, and specialized methods like `takeDamage()` and `reduceMana()`.
- **Abstraction:** The `Weapon`, `Enemy`, and `Player` classes are abstract, ensuring that specific game entities must follow a strict template while hiding the complexity of underlying calculations.
- **Interfaces:** The `Entity`, `Item`, and `Key` interfaces decouple behaviors from the class hierarchy, allowing for flexible interaction between different game objects.
<br/>
![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.