13 Commits
Author SHA1 Message Date
Meraj c2b2e125fa Merge pull request 'develop' (#1) from develop into main
Well done! This was a challenging assignment and you handled it successfully. The console output and one logical issue were the main problems in your project, but overall you did a good job. Keep up the great work!(100/110 + 0/50)
2026-05-18 22:10:14 +00:00
ArefeRoosta d0e2472739 add README 2026-05-09 23:42:24 +03:30
ArefeRoosta 95076fce9b update classes and fixed bugs 2026-05-09 15:13:37 +03:30
ArefeRoosta 8d3bddbe0a add game class 2026-05-07 19:21:47 +03:30
ArefeRoosta 6188c8ec1c complete location package 2026-05-07 09:26:10 +03:30
ArefeRoosta a70b14538b complete item package 2026-05-07 09:25:13 +03:30
ArefeRoosta 2ea1bced4f complete consumables package 2026-05-07 09:24:07 +03:30
ArefeRoosta 6ab1cb375c complete weapons package 2026-05-07 09:22:43 +03:30
ArefeRoosta 541a475bad complete armors package 2026-05-07 09:20:20 +03:30
ArefeRoosta d033105e33 complete entity packge 2026-05-07 09:16:55 +03:30
ArefeRoosta 9804cf7237 complete enemies package 2026-05-07 09:15:14 +03:30
ArefeRoosta 21e6ad0e31 complete players package 2026-05-07 09:10:42 +03:30
ArefeRoosta 84988b3fa1 add required classes 2026-05-06 20:55:17 +03:30
48 changed files with 1475 additions and 261 deletions
+5
View File
@@ -16,5 +16,10 @@
<option name="name" value="JBoss Community repository" /> <option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" /> <option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository> </remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://maven.myket.ir/" />
</remote-repository>
</component> </component>
</project> </project>
@@ -0,0 +1,387 @@
package org.project;
import org.project.entity.Entity;
import org.project.entity.enemies.*;
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 org.project.item.weapons.Dagger;
import org.project.item.weapons.Sword;
import org.project.location.Location;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.Scanner;
import static org.project.entity.enemies.Enemy.GREEN;
import static org.project.entity.players.Player.*;
public class Game {
private Player player;
private Scanner scanner;
private Location currentLocation;
private List<Location> allLocations;
private Enemy currentEnemy;
private Random random = new Random();
private boolean hasGoblinKey = false;
private boolean hasSkeletonKey = false;
private boolean hasVampireKey = false;
private List<Enemy> allEnemiesInGame = new ArrayList<>();
protected static final String GREEN_LIGHT = "\033[92m";
protected static final String PURPLE = "\033[35m";
public Game()
{
this.scanner = new Scanner(System.in);
this.allLocations = setupWorld();
}
public void start()
{
System.out.println("\n🏰 Welcome to Java Knight!");
this.player = createPlayer();
selectStartingLocation();
spawnRandomEnemy();
gameLoop();
}
public Player createPlayer()
{
System.out.println("Enter your name: ");
String name = scanner.nextLine();
System.out.println("1. ⚔️ Knight (High Damage, Balanced HP)");
System.out.println("2. 🧙 Wizard (High HP, Magic Power)");
System.out.println("3. 🗡️ Assassin (High Mana, Critical Hits)");
int choice = getIntInput("Choose your character: ");
Player newPlayer = null;
switch (choice)
{
case 1:
System.out.println("You chose the Knight!");
newPlayer = new Knight(name);
break;
case 2:
System.out.println("You chose the Wizard!");
newPlayer = new Wizard(name);
break;
case 3:
System.out.println("You chose the Assassin!");
newPlayer = new Assassin(name);
break;
default:
System.out.println("Invalid choice. Defaulting to Knight.");
newPlayer = new Knight(name);
break;
}
return newPlayer;
}
public void selectStartingLocation()
{
System.out.println("🗺️ Choose your starting location:");
for (int i = 0; i < allLocations.size(); i++)
{
System.out.println((i+1) + ". " + allLocations.get(i).getName());
}
int choice = getIntInput("Enter your choice: ");
if (choice > 0 && choice <= allLocations.size())
{
this.currentLocation = allLocations.get(choice - 1);
System.out.println("🚶 You have arrived at: " + currentLocation.getName());
}
else
{
System.out.println("Invalid choice. Defaulting to Forest.");
this.currentLocation = allLocations.get(0);
}
}
private List<Location> setupWorld()
{
List<Location> locations = new ArrayList<>();
ArrayList<Enemy> forestEnemies = new ArrayList<>();
forestEnemies.add(new Goblin(new Dagger()));
forestEnemies.add(new Goblin(new Dagger()));
forestEnemies.add(new Goblin(new Dagger()));
forestEnemies.add(new Goblin(new Dagger()));
forestEnemies.add(new Skeleton(new Sword()));
forestEnemies.add(new Vampire(new Dagger()));
forestEnemies.add(new Skeleton(new Sword()));
forestEnemies.add(new Vampire(new Dagger()));
forestEnemies.add(new Skeleton(new Sword()));
Location forest = new Location("Dark Forest", new ArrayList<>(), forestEnemies);
allEnemiesInGame.addAll(forestEnemies);
ArrayList<Enemy> caveEnemies = new ArrayList<>();
caveEnemies.add(new Skeleton(new Sword()));
caveEnemies.add(new Skeleton(new Sword()));
caveEnemies.add(new Skeleton(new Sword()));
caveEnemies.add(new Skeleton(new Sword()));
caveEnemies.add(new Goblin(new Dagger()));
caveEnemies.add(new Vampire(new Dagger()));
caveEnemies.add(new Goblin(new Dagger()));
caveEnemies.add(new Vampire(new Dagger()));
caveEnemies.add(new Vampire(new Dagger()));
Location cave = new Location("Spooky Cave", new ArrayList<>(), caveEnemies);
allEnemiesInGame.addAll(caveEnemies);
ArrayList<Enemy> swampEnemies = new ArrayList<>();
swampEnemies.add(new Vampire(new Dagger()));
swampEnemies.add(new Vampire(new Dagger()));
swampEnemies.add(new Vampire(new Dagger()));
swampEnemies.add(new Vampire(new Dagger()));
swampEnemies.add(new Goblin(new Dagger()));
swampEnemies.add(new Skeleton(new Sword()));
swampEnemies.add(new Goblin(new Dagger()));
swampEnemies.add(new Goblin(new Dagger()));
swampEnemies.add(new Skeleton(new Sword()));
Location swamp = new Location("Swamp", new ArrayList<>(), swampEnemies);
allEnemiesInGame.addAll(swampEnemies);
locations.add(forest);
locations.add(cave);
locations.add(swamp);
return locations;
}
public void spawnRandomEnemy()
{
ArrayList<Enemy> enemies = currentLocation.getEnemies();
if (enemies == null || enemies.isEmpty()) {
System.out.println("🌲 The area is quiet... no enemies nearby. Move to another location.");
this.currentEnemy = null;
return;
}
int index = random.nextInt(enemies.size());
this.currentEnemy = enemies.get(index);
this.currentEnemy = enemies.remove(index);
allEnemiesInGame.remove(this.currentEnemy);
System.out.println("⚠️ A wild " + currentEnemy.getClass().getSimpleName() + " appears in " + currentLocation.getName() + "!");
}
public void gameLoop()
{
while (player.isAlive())
{
System.out.println("\n========================================");
System.out.println("📍 Location: " + currentLocation.getName());
System.out.println("❤️ Player HP: " + player.getHp() + "/" + player.getMaxHP());
System.out.println("💎 Player MP: " + player.getMp() + "/" + player.getMaxMP());
if (currentEnemy != null && currentEnemy.isAlive())
{
System.out.println("Enemy: " + currentEnemy.getClass().getSimpleName() + " (HP: " + currentEnemy.getHp() + ")");
}
System.out.println("---- Actions ----");
System.out.println("1. 🥷 Fight enemy");
System.out.println("2. 🚶 Move to another location");
System.out.println("3. 🔒 Go to Dragon Castle");
System.out.println("4. 🏳️ Quit game");
int choice = getIntInput("Enter your choice: ");
switch (choice)
{
case 1: //fight
if (currentEnemy == null)
{
spawnRandomEnemy();
}
if (currentEnemy != null)
{
System.out.println("⚔️ Battle Started: " + player.getName() + " vs " + currentEnemy.getClass().getSimpleName());
fight(currentEnemy);
postCombat(currentEnemy);
spawnRandomEnemy();
}
else
{
System.out.println("⚠️ No enemy found in this location.");
}
break;
case 2: //move
moveLocation();
spawnRandomEnemy();
break;
case 3:
if (hasGoblinKey && hasSkeletonKey && hasVampireKey)
{
System.out.println(PURPLE+"🐉 Entering Dragon's lair..."+RESET);
startDragonFight();
}
else
{
System.out.println("🔒 Locked! Collect all 3 keys.");
}
break;
case 4:
System.out.println("Byyyeee!");
return;
default:
System.out.println("Invalid."); break;
}
}
System.out.println(RED+"==== 💀 Game Over! ===="+RESET);
}
private void fight(Enemy enemy)
{
while (player.isAlive() && enemy.isAlive())
{
handlePlayerTurn(enemy);
if (enemy.isStunned())
{
System.out.println("Enemy is stunned and skips its turn!");
enemy.unstun();
}
else
{
enemy.attack(player);
}
}
}
private void handlePlayerTurn(Entity target)
{
System.out.println(BLUE+"\n--- Your Turn ---"+RESET);
System.out.println("1. Light Attack | 2. Heavy Attack (-20 Mana) | 3. Defend (-15 Mana) | 4. Heal (-30 Mana) | 5. Special (-50 Mana)");
int action = getIntInput("Choose action: ");
switch (action)
{
case 1: player.lightAttack(target); break;
case 2: player.heavyAttack(target); break;
case 3: player.defend(); break;
case 4: player.heal(20); break;
case 5: player.specialAbility(target); break;
default: System.out.println("Invalid!"); break;
}
}
public void postCombat(Enemy enemy)
{
if (player.isAlive())
{
int xp = enemy.getXpReward();
player.addXp(xp);
checkKeyDrop(enemy);
player.setHp(player.getMaxHP());
player.fillMana(player.getMaxMP() - player.getMp());
System.out.println("💖 HP and MP fully restored!");
}
}
public void checkKeyDrop(Enemy enemy)
{
if (enemy instanceof Goblin && hasGoblinKey) return;
if (enemy instanceof Skeleton && hasSkeletonKey) return;
if (enemy instanceof Vampire && hasVampireKey) return;
String enemyType = enemy.getClass().getSimpleName();
boolean isLastOne = true;
for (Enemy e : allEnemiesInGame)
{
if (e.getClass().getSimpleName().equals(enemyType))
{
isLastOne = false;
break;
}
}
double dropChance;
if (isLastOne)
{
dropChance = 1.0;
System.out.println("✨ This is the last " + enemyType + " in the world!");
}
else
{
dropChance = 0.2; //20% chance
}
if (Math.random() < dropChance)
{
if (enemy instanceof Goblin)
{
hasGoblinKey = true;
System.out.println(GREEN + "🔑 You found the Goblin Key!" + RESET);
}
else if (enemy instanceof Skeleton)
{
hasSkeletonKey = true;
System.out.println(GREEN + "🔑 You found the Skeleton Key!" + RESET);
}
else if (enemy instanceof Vampire)
{
hasVampireKey = true;
System.out.println(GREEN + "🔑 You found the Vampire Key!" + RESET);
}
}
}
private void moveLocation()
{
System.out.println("🗺️ Available destinations:");
for (int i = 0; i < allLocations.size(); i++)
{
System.out.println((i + 1) + ". " + allLocations.get(i).getName());
}
int choice = getIntInput("Choose destination: ");
if (choice > 0 && choice <= allLocations.size())
{
currentLocation = allLocations.get(choice - 1);
System.out.println("🚶 You traveled to " + currentLocation.getName());
}
}
private void startDragonFight() {
System.out.println("🐉 THE DRAGON APPEARS! PREPARE FOR BATTLE!");
Dragon dragon = new Dragon(null);
fight(dragon);
if (player.isAlive())
{
System.out.println(GREEN_LIGHT + "\n== 🏆 VICTORY! You have defeated the Dragon and broken the curse! ==" + RESET);
System.out.println("🎉 You are the Hero of the Realm!");
}
else
{
System.out.println(RED + "\n==== 💀 You have been slain by the Dragon! ====" + RESET);
}
}
private int getIntInput(String prompt) {
System.out.print(prompt);
while (!scanner.hasNextInt()) {
System.out.println("⚠️ Please enter a valid number!");
scanner.next();
System.out.print(prompt);
}
return scanner.nextInt();
}
}
@@ -1,15 +1,24 @@
package org.project; package org.project;
import org.project.entity.players.Player;
import org.project.location.Location; import org.project.location.Location;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
// TODO: ADD LOCATIONS TO YOUR GAME
List<Location> locations = new ArrayList<>();
// TODO: IMPLEMENT GAMEPLAY try
{
Game game = new Game();
game.start();
}
catch (Exception e) {
System.err.println("❌ Error: " + e.getMessage());
e.printStackTrace();
}
} }
} }
@@ -1,7 +1,6 @@
package org.project.entity; package org.project.entity;
public interface Entity { public interface Entity {
void attack(Entity target);
void defend(); void defend();
@@ -15,7 +14,6 @@ public interface Entity {
int getMaxMP(); int getMaxMP();
/* boolean isAlive();
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
} }
@@ -0,0 +1,60 @@
package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.entity.players.Player;
import org.project.item.weapons.Weapon;
import static org.project.entity.players.Player.BLUE;
import static org.project.entity.players.Player.RED;
public class Dragon extends Enemy{
private static final double BREATH_DAMAGE_PENETRATION = 0.5;
public Dragon(Weapon weapon)
{
super(250, 0, weapon);
}
@Override
public void attack(Entity target)
{
if(!this.isAlive()) return;
System.out.println(BLUE+"-- Dragon's Turn --"+RESET);
int damage = 25;
if(super.getWeapon() != null)
{
damage += super.getWeapon().getDamage();
}
if (target instanceof Player)
{
Player player = (Player) target;
if (player.isDefending())
{
System.out.println("🔥 Dragon's fiery breath bypasses the shield!");
System.out.println("💥 " + player.getName() + " takes FULL damage!");
//instead of player.takeDamage (Bypassing Defense in takeDamage method)
player.setHp(player.getHp() - damage);
System.out.println("💥 " + player.getName() + " took " + RED + damage + RESET + " damage!");
System.out.println("❤️ " + player.getName() + " HP remaining: " + player.getHp() + "/" + player.getMaxHP());
player.setDefending(false);
}
else
{
System.out.println("🐉 Dragon used Fire Breath!");
player.takeDamage(damage);
}
}
else
{
target.takeDamage(damage);
}
if (!target.isAlive())
{
Player player = (Player) target;
System.out.println("💀 " + player.getName() + " has been defeated!");
}
}
}
@@ -1,29 +1,84 @@
package org.project.entity.enemies; package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.item.armors.Armor;
import org.project.item.weapons.Weapon; import org.project.item.weapons.Weapon;
// TODO: UPDATE IMPLEMENTATION public abstract class Enemy implements Entity{
public abstract class Enemy {
Weapon weapon; Weapon weapon;
private int hp; private int hp;
private int mp; private int mp;
private int maxHp;
protected boolean isAlive = true;
private int maxMp;
public Enemy(int hp, int mp, Weapon weapon) { private int xpReward;
this.hp = hp; private boolean hasDroppedKey = false;
private boolean keyDroppable = false;
private boolean isStunned = false;
public static final String GREEN = "\u001B[32m";
public static final String RESET = "\u001B[0m";
public static final String ORANGE = "\u001B[33m";
public Enemy(int maxHp, int mp, Weapon weapon) {
this.maxHp = maxHp;
this.hp = maxHp;
this.mp = mp; this.mp = mp;
this.weapon = weapon; this.weapon = weapon;
} }
@Override @Override
public void takeDamage(int damage) { public void takeDamage(int damage) {
if (!isAlive) return;
hp -= damage; hp -= damage;
if (this.hp < 0)
{
this.hp = 0;
}
System.out.println("❤️ " + this.getClass().getSimpleName() + " HP remaining: " + hp + "/" + maxHp);
if (this.hp <= 0) {
this.hp = 0;
this.isAlive = false;
System.out.println("💀 "+ ORANGE+ this.getClass().getSimpleName() + " has been defeated!"+RESET);
}
} }
@Override
public void defend()
{
System.out.println(this.getClass().getSimpleName() + " attempts to defend!");
}
@Override
public void heal(int health)
{
if (!isAlive) return;
this.hp += health;
if (this.hp > maxHp) this.hp = maxHp;
System.out.println("💚 " + this.getClass().getSimpleName() + " healed " + health + " HP!");
}
@Override
public boolean isAlive() {
return this.isAlive;
}
public abstract void attack(Entity target);
public int getHp() { public int getHp() {
return hp; return hp;
} }
public void setHp(int hp)
{
this.hp = hp;
}
public int getMp() { public int getMp() {
return mp; return mp;
} }
@@ -31,4 +86,61 @@ public abstract class Enemy {
public Weapon getWeapon() { public Weapon getWeapon() {
return weapon; return weapon;
} }
public void setStunned(boolean b)
{
this.isStunned = b;
}
public boolean isStunned() {
return isStunned;
}
public int getXpReward()
{
return xpReward;
}
public boolean hasKey()
{
return keyDroppable && !hasDroppedKey;
}
public void dropKey()
{
if (keyDroppable && !hasDroppedKey)
{
hasDroppedKey = true;
System.out.println("🔑 " +GREEN+ this.getClass().getSimpleName() + " dropped a key!"+RESET);
}
}
public void setKeyDroppable(boolean droppable)
{
this.keyDroppable = droppable;
}
public void setXpReward(int xp)
{
this.xpReward = xp;
}
@Override
public void fillMana(int mana)
{
this.mp = 0;
}
public int getMaxHP() {
return maxHp;
}
public int getMaxMP() {
return maxHp;
}
public void unstun()
{
this.isStunned = false;
}
} }
@@ -0,0 +1,47 @@
package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.item.weapons.Weapon;
import static org.project.entity.players.Player.BLUE;
public class Goblin extends Enemy{
public Goblin(Weapon weapon)
{
super(50, 0, weapon);
}
@Override
public void attack(Entity target)
{
if (!this.isAlive()) return;
System.out.println(BLUE+"-- Goblin's Turn --"+RESET);
int baseDamage = 0;
if (super.getWeapon() != null)
{
baseDamage += super.getWeapon().getDamage();
}
else
{
baseDamage = 8;
}
if (Math.random() < 0.4)
{
int criticalDamage = baseDamage*2;
System.out.println("👹 Goblin used Critical Strike!");
target.takeDamage(criticalDamage);
}
else
{
System.out.println("👹 Goblin used Slash!");
target.takeDamage(baseDamage);
}
}
@Override
public int getXpReward()
{
return 25;
}
}
@@ -1,6 +1,63 @@
package org.project.entity.enemies; package org.project.entity.enemies;
// TODO: UPDATE IMPLEMENTATION import org.project.entity.Entity;
public class Skeleton { import org.project.item.weapons.Weapon;
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
import static org.project.entity.players.Player.BLUE;
public class Skeleton extends Enemy{
private boolean hasResurrected = false;
private int resurrectionThreshold;
public Skeleton(Weapon weapon)
{
super(60, 0, weapon);
this.resurrectionThreshold = 30;
}
@Override
public void takeDamage(int damage)
{
super.takeDamage(damage);
if (!this.isAlive() && !hasResurrected)
{
resurrect();
}
}
@Override
public void attack(Entity target)
{
if (!this.isAlive()) return;
System.out.println(BLUE+"-- Skeleton's Turn --"+RESET);
int damage = 0;
if (super.getWeapon() != null)
{
damage = super.getWeapon().getDamage();
}
else
{
damage = 5;
}
target.takeDamage(damage);
}
public void resurrect()
{
this.isAlive = true;
this.hasResurrected = true;
int currentMaxHP = (this instanceof Enemy) ? ((Enemy) this).getMaxHP() : 60;
this.setHp(currentMaxHP / 2);
System.out.println("👻 Skeleton is rising from the grave! HP restored to " + this.getHp());
}
@Override
public int getXpReward()
{
return 40;
}
} }
@@ -0,0 +1,50 @@
package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.item.weapons.Weapon;
import static org.project.entity.players.Player.BLUE;
public class Vampire extends Enemy{
private static final double lifeStealPercent = 0.3;
public Vampire(Weapon weapon)
{
super(80, 0, weapon);
}
@Override
public void attack(Entity target) {
if (!this.isAlive()) return;
System.out.println(BLUE+"-- Vampire's Turn --"+RESET);
int damage = 0;
if (super.getWeapon() != null) {
damage = super.getWeapon().getDamage();
}
else
{
damage = 12;
}
target.takeDamage(damage);
int healAmount = (int) (damage * lifeStealPercent);
if (healAmount > 0)
{
System.out.println("🦇 Vampire used Life Drain!");
super.heal(healAmount);
}
else
{
System.out.println("🦇 Vampire used Bite!");
}
}
@Override
public int getXpReward()
{
return 60;
}
}
@@ -0,0 +1,132 @@
package org.project.entity.players;
import org.project.entity.Entity;
import org.project.item.armors.LeatherArmor;
import org.project.item.weapons.Dagger;
public class Assassin extends Player {
private boolean isHidden = false;
private boolean nextAttackCritical = false;
public Assassin(String name)
{
super(name, 150, 120, new Dagger(), new LeatherArmor());
}
@Override
public int getBaseDamage()
{
return 10;
}
@Override
public void specialAbility(Entity target)
{
isDefending = false;
if (this.getMp() < costSpecial)
{
System.out.println(YELLOW+"Not enough Mana for Vanish!"+RESET);
return;
}
setIsHidden(true);
setNextAttackCritical(true);
this.setMp(this.getMp() - costSpecial);
System.out.println("👻 " +PURPLE+ name + " has turned invisible!"+RESET);
System.out.println("🎯 Next attack is guaranteed to be a Critical Hit!");
}
@Override
public void heavyAttack(Entity target)
{
isDefending = false;
int baseDmg = getBaseDamage() * 2;
int weaponDmg = (weapon != null) ? weapon.getDamage() : 0;
int totalDmg = baseDmg + weaponDmg;
if (getNextAttackCritical()) {
totalDmg *= 2;
System.out.println("⚡ Critical Hit! Damage doubled!");
setNextAttackCritical(false);
}
if (this.getMp() < costHeavy) {
System.out.println(YELLOW+"Not enough Mana for Heavy Attack!"+RESET);
return;
}
this.setMp(this.getMp() - costHeavy);
System.out.println("🔪 " + name + " (Assassin) used Heavy Attack! " + "( " + BLUE + costHeavy + RESET + " Mana)");
System.out.println("💥 " + target.getClass().getSimpleName() + " took " + RED+totalDmg+RESET + " damage!");
target.takeDamage(totalDmg);
}
@Override
public void lightAttack(Entity target)
{
isDefending = false;
int baseDmg = getBaseDamage();
int weaponDmg = (weapon != null) ? weapon.getDamage() : 0;
int totalDmg = baseDmg + weaponDmg;
if (getNextAttackCritical()) {
totalDmg *= 2;
System.out.println("⚡ Critical Hit! Damage doubled!");
setNextAttackCritical(false);
}
System.out.println("️🗡️ " + name + " (Assassin) used Light Attack! " + "( " + BLUE+costLight+RESET + " Mana)");
System.out.println("💥 " + target.getClass().getSimpleName() + " took " + RED+totalDmg+RESET + " damage!");
target.takeDamage(totalDmg);
}
@Override
public void heal(int health)
{
isDefending = false;
if (this.getMp() >= costHeal)
{
setHp(getHp() + health);
if (this.getHp() > getMaxHP()) {
setHp(getMaxHP());
}
this.setMp(getMp() - costHeal);
System.out.println("💚" + name + " (Assassin) healed " + health + " HP!" + " ( " + BLUE+costHeal+RESET + " Mana)");
}
else
{
System.out.println(YELLOW+"Not enough Mana!"+RESET);
}
}
@Override
public void defend()
{
if (this.getMp() >= costDefend)
{
this.setMp(getMp() - costDefend);
this.setDefending(true);
System.out.println("🛡️" + name + " (Assassin) is defending!" + "( " + BLUE+costDefend+RESET + " Mana)");
isDefending = true;
}
else
{
System.out.println(YELLOW+"Not enough Mana!"+RESET);
}
}
public boolean getIsHidden() {
return isHidden;
}
public void setIsHidden(boolean hidden) {
isHidden = hidden;
}
public boolean getNextAttackCritical() {
return nextAttackCritical;
}
public void setNextAttackCritical(boolean nextAttackCritical) {
this.nextAttackCritical = nextAttackCritical;
}
}
@@ -1,6 +1,110 @@
package org.project.entity.players; package org.project.entity.players;
// TODO: UPDATE IMPLEMENTATION import org.project.entity.Entity;
public class Knight { import org.project.entity.enemies.Enemy;
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR import org.project.item.armors.Armor;
import org.project.item.armors.KnightArmor;
import org.project.item.weapons.Sword;
import org.project.item.weapons.Weapon;
public class Knight extends Player{
private boolean isStunned = false;
public Knight(String name)
{
super(name, 120, 60, new Sword(), new KnightArmor());
}
@Override
public int getBaseDamage()
{
return 15;
//Knight has the highest base dmg
}
@Override
public void specialAbility(Entity target)
{
isDefending = false;
if (this.getMp() < costSpecial)
{
System.out.println(YELLOW+"Not enough Mana for shield bash!"+RESET);
return;
}
this.setMp(this.getMp() - costSpecial);
if (target instanceof Enemy) {
Enemy enemyTarget = (Enemy) target;
enemyTarget.setStunned(true);
System.out.println("🛡️ " + PURPLE+getName() + " used Shield Bash!" +RESET+ "( " + BLUE+costSpecial+RESET + " Mana)");
}
int damage = getBaseDamage() + (weapon != null ? weapon.getDamage() : 0) + 10;
System.out.println("💥 " + target.getClass().getSimpleName() + " took " + RED+damage+RESET + " damage!");
target.takeDamage(damage);
}
public void heavyAttack(Entity target)
{
isDefending = false;
int baseDmg = getBaseDamage() * 2;
int weaponDmg = (weapon != null) ? weapon.getDamage() : 0;
int totalDmg = baseDmg + weaponDmg;
if (this.getMp() < costHeavy)
{
System.out.println(YELLOW+"Not enough Mana for Heavy Attack!"+RESET);
return;
}
this.setMp(this.getMp() - costHeavy);
System.out.println("💥 " + name + " (Knight) used Heavy Attack! " + "( " + BLUE+costHeavy+RESET + " Mana)");
System.out.println("💥 " + target.getClass().getSimpleName() + " took " + RED+totalDmg+RESET + " damage!");
target.takeDamage(totalDmg);
}
public void lightAttack(Entity target)
{
isDefending = false;
int baseDmg = getBaseDamage();
int weaponDmg = (weapon != null) ? weapon.getDamage() : 0;
int totalDmg = baseDmg + weaponDmg;
System.out.println("⚔️ " + name + " (Knight) used Light Attack! " + "( " + BLUE+costLight+RESET + " Mana)");
System.out.println("💥 " + target.getClass().getSimpleName() + " took " + RED+totalDmg+RESET + " damage!");
target.takeDamage(totalDmg);
}
@Override
public void heal(int health)
{
isDefending = false;
if (this.getMp() >= costHeal)
{
setHp(getHp() + health);
if (this.getHp() > getMaxHP()) {
setHp(getMaxHP());
}
this.setMp(getMp() - costHeal);
System.out.println("💚 " + name + " (Knight) healed " + health + " HP!" + " ( " + BLUE+costHeal+RESET + " Mana)");
}
else
{
System.out.println(YELLOW+"Not enough Mana!"+RESET);
}
}
@Override
public void defend()
{
if (this.getMp() >= costDefend)
{
this.setMp(getMp() - costDefend);
this.setDefending(true);
System.out.println("🛡️" + name + " (Knight) is defending!" + "( " + BLUE+costDefend+RESET + " Mana)");
isDefending = true;
}
else
{
System.out.println(YELLOW+"Not enough Mana!"+RESET);
}
}
} }
@@ -4,8 +4,7 @@ import org.project.entity.Entity;
import org.project.item.armors.Armor; import org.project.item.armors.Armor;
import org.project.item.weapons.Weapon; import org.project.item.weapons.Weapon;
// TODO: UPDATE IMPLEMENTATION public abstract class Player implements Entity {
public abstract class Player {
protected String name; protected String name;
Weapon weapon; Weapon weapon;
Armor armor; Armor armor;
@@ -13,38 +12,68 @@ public abstract class Player {
private int maxHP; private int maxHP;
private int mp; private int mp;
private int maxMP; private int maxMP;
private int currentXp = 0;
private int level = 1;
private int xpToNextLevel = 100;
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) { protected static final int costLight = 0;
protected static final int costHeavy = 20;
protected static final int costDefend = 15;
protected static final int costHeal = 30;
protected static final int costSpecial = 50;
protected boolean isDefending = false;
public static final String BLUE = "\u001B[34m";
public static final String RED = "\033[31m";
public static final String YELLOW = "\033[33m";
protected static final String PURPLE = "\033[35m";
public static final String RESET = "\u001B[0m";
public Player(String name, int maxHP, int maxMP, Weapon weapon, Armor armor) {
this.name = name; this.name = name;
this.hp = hp; this.maxHP = maxHP;
this.mp = mp; this.maxMP = maxMP;
this.hp = maxHP;
this.mp = maxMP;
this.weapon = weapon; this.weapon = weapon;
this.armor = armor; this.armor = armor;
} }
@Override @Override
public void attack(Entity target) { public void takeDamage(int rawDamage) {
target.takeDamage(weapon.getDamage()); int actualDamage = rawDamage;
} String logMessage = "";
@Override if (isDefending)
public void defend() { {
// TODO int defenseReduction = (int) (actualDamage * 0.5);
} actualDamage -= defenseReduction;
isDefending = false;
logMessage += "🛡️ You braced for impact! (-50% damage) ";
@Override
public void takeDamage(int damage) {
hp -= damage - armor.getDefense();
}
@Override
public void heal(int health) {
hp += health;
if (hp > maxHP) {
hp = maxHP;
} }
int armorDefense = 0;
if (armor != null)
{
armorDefense = armor.getDefense();
int damageAfterArmor = Math.max(0, actualDamage - armorDefense);
actualDamage = damageAfterArmor;
if (armorDefense > 0)
{
logMessage += "🛡️ " + armor.getName() +" blocked "+ armorDefense + " damage! ";
}
}
this.hp -= actualDamage;
if (this.hp < 0)
{
this.hp = 0;
}
System.out.println(logMessage);
System.out.println("💥 " + name + " took " + RED + actualDamage + RESET + " damage!");
System.out.println("❤️ " + name + " HP remaining: " + hp + "/" + maxHP);
} }
@Override @Override
@@ -55,7 +84,6 @@ public abstract class Player {
} }
} }
public String getName() { public String getName() {
return name; return name;
} }
@@ -85,5 +113,93 @@ public abstract class Player {
public Armor getArmor() { public Armor getArmor() {
return armor; return armor;
} }
public void setMp(int mp) {
this.mp = mp;
}
public void setHp(int hp)
{
this.hp = hp;
}
public int getCurrentXp() {
return currentXp;
}
public void setCurrentXp(int currentXp) {
this.currentXp = currentXp;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public int getXpToNextLevel() {
return xpToNextLevel;
}
public void setXpToNextLevel(int xpToNextLevel) {
this.xpToNextLevel = xpToNextLevel;
}
@Override
public boolean isAlive()
{
return getHp() > 0;
}
public abstract int getBaseDamage();
public void setDefending(boolean defending) {
isDefending = defending;
}
public boolean isDefending() {
return isDefending;
}
@Override
public abstract void defend();
@Override
public abstract void heal(int health);
public abstract void lightAttack(Entity target);
public abstract void specialAbility(Entity target);
public abstract void heavyAttack(Entity target);
public void addXp(int amount)
{
this.setCurrentXp(getCurrentXp()+amount);
System.out.println("✨ You earned "+ amount + " XP!");
while (this.getCurrentXp() >= this.getXpToNextLevel())
{
levelUp();
}
}
public void levelUp()
{
this.setCurrentXp(this.getCurrentXp()-this.getXpToNextLevel());
this.setLevel(this.getLevel()+1);
int hpBonus = 10 + (this.getLevel() * 5);
int mpBonus = 5 + (this.getLevel() * 2);
this.maxHP += hpBonus;
this.maxMP += mpBonus;
this.hp = this.maxHP;
this.mp = this.maxMP;
this.setXpToNextLevel((int) (this.getXpToNextLevel()*1.5));
System.out.println("🎉 LEVEL UP! You are now Level " + this.getLevel() + "!");
System.out.println("❤️ Max HP increased to " + this.maxHP);
System.out.println("💎 Max MP increased to " + this.maxMP);
}
} }
@@ -0,0 +1,105 @@
package org.project.entity.players;
import org.project.entity.Entity;
import org.project.item.armors.Robe;
import org.project.item.weapons.Wand;
public class Wizard extends Player{
public Wizard(String name)
{
super(name, 200, 100, new Wand(), new Robe());
//Wizard: Highest Max Health (HP).
}
@Override
public int getBaseDamage()
{
return 8;
}
@Override
public void specialAbility(Entity target)
{
isDefending = false;
if (this.getMp() < costSpecial)
{
System.out.println(YELLOW+"Not enough Mana for Soul Siphon!"+RESET);
return;
}
this.setMp(this.getMp() - costSpecial);
int damage = getBaseDamage() + (weapon != null ? weapon.getDamage() : 0) + 25;
int selfHeal = 15;
System.out.println("🪄 " +PURPLE+ name + " (Wizard) used soul siphon!"+RESET + " (" + BLUE+costSpecial+RESET + " Mana)");
System.out.println("💥 " + target.getClass().getSimpleName() + " took " + RED+damage+RESET + " damage!");
target.takeDamage(damage);
heal(selfHeal);
}
@Override
public void heavyAttack(Entity target)
{
isDefending = false;
int baseDmg = getBaseDamage() * 2;
int weaponDmg = (weapon != null) ? weapon.getDamage() : 0;
int totalDmg = baseDmg + weaponDmg;
if (this.getMp() < costHeavy)
{
System.out.println(YELLOW+"Not enough Mana for Heavy Attack!"+RESET);
return;
}
this.setMp(this.getMp() - costHeavy);
System.out.println("💥 " + name + " (Wizard) used Heavy Attack! " + "( " + BLUE+costHeavy+RESET + " Mana)");
System.out.println("💥 " + target.getClass().getSimpleName() + " took " + RED+totalDmg+RESET + " fire damage!");
target.takeDamage(totalDmg);
}
@Override
public void lightAttack(Entity target)
{
isDefending = false;
int baseDmg = getBaseDamage();
int weaponDmg = (weapon != null) ? weapon.getDamage() : 0;
int totalDmg = baseDmg + weaponDmg;
System.out.println("️🧙 " + name + " (Wizard) used Light Attack! " + "( " + BLUE+costLight+RESET + " Mana)");
System.out.println("💥 " + target.getClass().getSimpleName() + " took " + RED+totalDmg+RESET + " magical damage!");
target.takeDamage(totalDmg);
}
@Override
public void heal(int health)
{
isDefending = false;
if (this.getMp() >= costHeal)
{
setHp(getHp() + health);
if (this.getHp() > getMaxHP()) {
setHp(getMaxHP());
}
this.setMp(getMp() - costHeal);
System.out.println("💚 " + name + " (Wizard) healed " + health + " HP!" + " ( " + BLUE+costHeal+RESET + " Mana)");
}
else
{
System.out.println(YELLOW+"Not enough Mana!"+RESET);
}
}
@Override
public void defend()
{
if (this.getMp() >= costDefend)
{
this.setMp(getMp() - costDefend);
this.setDefending(true);
System.out.println("🛡️" + name + " (Wizard) is defending!" + "( " + BLUE+costDefend+RESET + " Mana)");
isDefending = true;
}
else
{
System.out.println(YELLOW+"Not enough Mana!"+RESET);
}
}
}
@@ -4,8 +4,6 @@ import org.project.entity.Entity;
public interface Item { public interface Item {
void use(Entity target); void use(Entity target);
String getName();
/* int getId();
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
} }
@@ -1,17 +1,26 @@
package org.project.item.armors; package org.project.item.armors;
// TODO: UPDATE IMPLEMENTATION import org.project.entity.Entity;
public abstract class Armor { import org.project.item.Item;
public abstract class Armor implements Item {
private int defense; private int defense;
private int maxDefense; private int maxDefense;
private int durability; private int durability;
private int maxDurability; private int maxDurability;
private boolean isBroke; private boolean isBroke;
private int id;
private String name;
public Armor(int defense, int durability) { public Armor(int id, String name, int defense, int durability) {
this.id = id;
this.name = name;
this.defense = defense; this.defense = defense;
this.durability = durability; this.durability = durability;
this.maxDefense = maxDefense;
this.maxDurability = maxDurability;
this.isBroke = false;
} }
public void checkBreak() { public void checkBreak() {
@@ -21,11 +30,11 @@ public abstract class Armor {
} }
} }
// TODO: (BONUS) UPDATE THE REPAIR METHOD
public void repair() { public void repair() {
isBroke = false; isBroke = false;
defense = maxDefense; defense = maxDefense;
durability = maxDurability; durability = maxDurability;
System.out.println("🔨 " + name + " has been repaired!");
} }
public int getDefense() { public int getDefense() {
@@ -39,4 +48,20 @@ public abstract class Armor {
public boolean isBroke() { public boolean isBroke() {
return isBroke; return isBroke;
} }
@Override
public String getName() {
return name;
}
@Override
public int getId() {
return id;
}
@Override
public void use(Entity target)
{
System.out.println("🛡️ " + name + " is equipped!");
}
} }
@@ -1,6 +1,16 @@
package org.project.item.armors; package org.project.item.armors;
// TODO: UPDATE IMPLEMENTATION import org.project.entity.Entity;
public class KnightArmor {
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR public class KnightArmor extends Armor{
public KnightArmor()
{
super(1, "Plate Armor", 5, 100);
}
@Override
public void use(Entity target) {
System.out.println("🛡️ You equipped the heavy Plate Armor! (High Defense)");
}
} }
@@ -0,0 +1,17 @@
package org.project.item.armors;
import org.project.entity.Entity;
public class LeatherArmor extends Armor{
public LeatherArmor()
{
super(3, "Light Leather", 3, 70);
}
@Override
public void use(Entity target)
{
System.out.println("🗡️ You equipped the Light Leather. (Balanced Stats)");
}
}
@@ -0,0 +1,15 @@
package org.project.item.armors;
import org.project.entity.Entity;
public class Robe extends Armor{
public Robe()
{
super(2, "magic robe", 1, 50);
}
@Override
public void use(Entity target) {
System.out.println("🧙‍♂️ You equipped the Magic Robe. (Low Defense, High Magic Focus)");
}
}
@@ -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,33 @@
package org.project.item.weapons;
import org.project.entity.Entity;
public class Dagger extends Weapon{
private static final double CRIT_CHANCE = 0.3;
public Dagger() {
super(3, "Poison Dagger", 8);
}
public void uniqueAbility(Entity target) {
if (target.isAlive())
{
int damage = this.getDamage();
boolean isCrit = Math.random() < CRIT_CHANCE;
if (isCrit)
{
damage *= 2;
System.out.println("⚡ CRITICAL HIT!");
}
else
{
System.out.println("🗡️ " + this.getName() + " struck for " + damage + " damage.");
}
target.takeDamage(damage);
}
}
}
@@ -4,23 +4,25 @@ import org.project.entity.Entity;
import java.util.ArrayList; import java.util.ArrayList;
// TODO: UPDATE IMPLEMENTATION public class Sword extends Weapon{
public class Sword {
/*
THIS IS AN EXAMPLE OF A WEAPON DESIGN.
*/
int abilityCharge;
public Sword() { public Sword() {
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR super(1, "Iron sword", 10);
} }
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
public void uniqueAbility(ArrayList<Entity> targets) { public void uniqueAbility(ArrayList<Entity> targets) {
abilityCharge += 2; int boostedDamage = this.getDamage() * 2;
for (Entity target : targets) {
target.takeDamage(getDamage()); System.out.println("🗡️ " + this.getName() + " glows with power!");
for (Entity target : targets)
{
if (target.isAlive())
{
target.takeDamage(boostedDamage);
System.out.println("💥 " + target.getClass().getSimpleName() + " took " + boostedDamage + " deep slash damage!");
}
} }
} }
} }
@@ -0,0 +1,20 @@
package org.project.item.weapons;
import org.project.entity.Entity;
import org.project.entity.enemies.Enemy;
import java.util.ArrayList;
public class Wand extends Weapon{
public Wand() {
super(2, "Wooden wand", 5);
}
public void uniqueAbility(ArrayList<Enemy> targets)
{
for (Enemy target : targets)
{
target.takeDamage(2);
}
}
}
@@ -1,35 +1,37 @@
package org.project.item.weapons; package org.project.item.weapons;
import org.project.entity.Entity; import org.project.entity.Entity;
import org.project.item.Item;
// TODO: UPDATE IMPLEMENTATION public abstract class Weapon implements Item {
public abstract class Weapon {
private int damage; private int damage;
private int manaCost; private int id;
private String name;
/* public Weapon(int id, String name, int damage) {
TODO: ADD OTHER REQUIRED AND BONUS ATTRIBUTES this.id = id;
*/ this.name = name;
public Weapon(int damage, int manaCost) {
this.damage = damage; this.damage = damage;
this.manaCost = manaCost;
} }
@Override @Override
public void use(Entity target) { public void use(Entity target) {
target.takeDamage(damage); System.out.println("🏹 " + name + " is equipped!");
} }
public int getDamage() { public int getDamage() {
return damage; return damage;
} }
public int getManaCost() { @Override
return manaCost; public String getName() {
return name;
}
@Override
public int getId() {
return id;
} }
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
} }
@@ -6,12 +6,13 @@ import java.util.ArrayList;
public class Location { public class Location {
private String name; private String name;
private ArrayList<Location> locations;
private ArrayList<Enemy> enemies; private ArrayList<Enemy> enemies;
public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) { public Location(String name, ArrayList<Location> locations, ArrayList<Enemy> enemies) {
this.locations = locations; this.locations = locations;
this.enemies = enemies; this.enemies = enemies;
this.name = name;
} }
public String getName() { public String getName() {
Binary file not shown.
Binary file not shown.
+86 -153
View File
@@ -1,175 +1,108 @@
# Fourth Assignment - Java Knight ⚔️ # Java Knight ⚔️
A turn-based RPG with Roguelike elements which can be run in the terminal.
### **Prologue: 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!* *For centuries, the land of Javanest lived in peace, until a magical Dragon attacked, plunging the realm into absolute darkness. With a wicked curse, the Dragon transformed the innocent people into horrific monsters: Goblins, Skeletons, and Vampires. Retreating to its impenetrable Castle, the Dragon divided the three keys to its lair and hid them among these cursed creatures. Now, it is your duty to step up and save the land. You must battle these monsters, recover the unique key from each monster type, and finally slay the Dragon to break the curse and restore peace to Javanest!*
### **Introduction** ### Introduction
Welcome to **Java knight**, a turn-based RPG inspired by Roguelike games! In this assignment, you will develop a **text-based role-playing game (RPG)**. This project is designed to rigorously test your understanding of **Object-Oriented Programming (OOP) principles**. Java Knight is a text-based Role-Playing Game developed using OOP principles in java. The gameplay is driven by interactive console messages and user input.
⚠️ **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. ___
#### Setup:
1. Install JDK
2. Install IntelliJ IDEA
3. Run the `Main` class in the project
___
🎯 **Your goal is not just to complete the assignment but to learn and apply OOP effectively!** ### How to play:
1. **Create character:** Knight/ Wizard/ Assassin
### **What is a Turn-Based Game?** ```java
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. 🏰 Welcome to Java Knight!
Enter your name:
### **Core Mechanics:** Gru
- **Turn-based combat** Players and monsters take turns attacking each other. 1. Knight (High Damage, Balanced HP)
- **Character classes with Unique Traits** Players can choose from archetypes like **Knight, Assassin, or Wizard**, each starting with distinctly different base stats. 2. 🧙 Wizard (High HP, Magic Power)
- **Unified Mana/Stamina System** All player classes use a unified resource (Mana/Stamina) to perform actions. 3. 🗡 Assassin (High Mana, Critical Hits)
- **Standardized Action Set** Every player character has exactly 5 specific actions available during their turn. Choose your character: 3
- **Experience & Leveling System** Earn XP based on enemy strength to automatically level up and increase your base stats. You chose the Assassin!
- **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.
---
## Tasks 📝
### 1️⃣ Step 1: Fork & Setup 🍴
1. **Fork** this repository and clone it to your local machine.
```bash
git clone https://git.meshcomp.ir/AdvancedProgramming1404/HW-04-JAVA-KNIGHT.git
```
2. Create a new branch named `develop` and switch to it.
```bash
git checkout -b develop
```
### 2️⃣ Step 2: Implement the Class Hierarchy 🌲
A well-structured OOP hierarchy is crucial. Avoid duplicating code by placing shared logic in abstract classes.
- **Entities & Locations:** You have `Entity`, `Item`(Bonus) , and `Location`.
- **Players:** `Player` is an abstract class implementing `Entity`. Subclasses: `Wizard`, `Knight`, `Assassin`.
- **Base Stat Differences:** Each class must have distinct starting stats. For example:
- **Knight:** Highest Base Damage.
- **Wizard:** Highest Max Health (HP).
- **Assassin:** Highest Max Stamina/Mana.
- **Enemies:** `Enemy` is an abstract class implementing `Entity`. Subclasses: `Skeleton`, `Goblin`, `Vampire`, and **`Dragon`**.
- **The Boss:** Even though `Dragon` is the final boss, it **must** be a subclass of `Enemy` to inherit common combat properties, while possessing extremely high stats and unique mechanics.
- **Item (Bonus):** `Consumable`, `Armor`, `Weapon` are abstract classes implementing `Item`. example :
- KnightArmor extends Armor - you can add more subclasses of Armor for extra score
- Sword extends Weapon - you can add more subclasses of Weapon for extra score
- Flask extends Consumable - you can add more subclasses of Consumable for extra score
![structure](Readme_Pictures/structure.png)
### 3️⃣ Step 3: Implement Player & Monster Methods 🏹
**Player Actions (The Rule of Five):**
Every player class **must** implement exactly the following 5 actions (You can use an interface like `ICombatActions`). Every action (except Light Attack) consumes a specific amount of Mana/Stamina. The **Special Ability** must consume the *highest* amount of Mana compared to the others.
1. **Light Attack:** Deals moderate damage and costs **NO Mana**. (Note: If the player runs out of Mana/Stamina, this is the ONLY action they can perform.)
2. **Heavy Attack:** Deals high damage, medium Mana cost.
3. **Defend:** Completely blocks or significantly reduces the damage of the enemy's *next* strike. Medium Mana cost.
4. **Heal:** Restores a portion of the player's HP. Medium-high Mana cost.
5. **Special Ability:** A unique class-based ultimate move (Highest Mana cost):
- **Wizard** 🧙‍♂️: Casts a devastating spell that damages the enemy while simultaneously replenishing some HP.
- **Assassin** 🗡️: Turns invisible, dodging the next incoming attack completely and guaranteeing a *Critical Hit* on their next turn.
- **Knight** ⚔️: Performs a shield bash that stuns the enemy, forcing them to skip their next turn while dealing heavy damage.
**Monster Abilities:**
- **Goblin** 👹: High critical hit chance but low health.
- **Skeleton** ☠️: Can resurrect once per battle with 50% HP.
- **Vampire** 🦇: Lifesteal ability a portion of the damage it deals to the player is added back to its own health.
- **Dragon (Final Boss)** 🐉: Immune to normal defense. Its fiery breath bypasses shields and deals massive damage.
🔹 Make sure each entity **prints messages** when performing actions. example output (while in combat) :
```bash
You chose to FIGHT!
[Ser Duncan - 45/45 HP | 40/40 Mana]
[Goblin - 30/30 HP]
---
Your Turn:
1. Light Attack | 2. Heavy Attack (-8 Mana) | 3. Defend (-6 Mana) | 4. Heal (-12 Mana) | 5. Shield Bash (-15 Mana)
``` ```
```bash 2. **Select location:** Forest/ Cave/ Swamp
→ Chose: Light Attack ```java
⚔️ Ser Duncan (Knight) used Light Attack! (0 Mana) 🗺 Choose your starting location:
Goblin took 10 damage! 1. Dark Forest
Goblin has 20/30 HP remaining. 2. Spooky Cave
Ser Duncan Mana: 40/40 3. Swamp
Enter your choice: 2
🚶 You have arrived at: Spooky Cave
``` ```
```
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).
<br/> When you arrive at the selected location, an enemy (Goblin/ Skeleton/ Vampire) spawns randomly. You can fight, move to another location, or quit.
### 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 ```java
while (player.isAlive() && enemy.isAlive()) A wild Vampire appears in Spooky Cave!
player.attack(enemy); ```
if (enemy.isAlive()) { ```java
enemy.attack(player); 📍 Location: Spooky Cave
} Player HP: 150/150
} 💎 Player MP: 120/120
Enemy: Vampire (HP: 80)
---- Actions ----
1. 🥷 Fight enemy
2. 🚶 Move to another location
3. 🔒 Go to Dragon Castle
4. 🏳 Quit game
``` ```
3. **Fight:** You can use one of these 5 actions:
* Light Attack: Deals moderate damage and costs NO Mana. (Note: If you run out of Mana, this is the ONLY action you can perform.)
* Heavy Attack: Deals high damage, medium Mana cost.
* Defend: Reduces the damage of the enemy's next strike. Medium Mana cost.
* Heal: Restores a portion of the player's HP. Medium-high Mana cost.
* Special Ability: A unique class-based ultimate move (Highest Mana cost).
### 5️⃣ Step 5: Extra Features & Bonus Tasks ⭐ ```java
*(Optional for extra credit)* Battle Started: Gru vs Vampire
**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. --- Your Turn ---
**Multiple Weapons & Inventory:** Players can buy, store, and swap between multiple weapons or use consumables mid-combat. 1. Light Attack | 2. Heavy Attack (-20 Mana) | 3. Defend (-15 Mana) | 4. Heal (-30 Mana) | 5. Special (-50 Mana)
**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 📄 4. You cannot fight the Dragon immediately. You must fight enemies for a chance to drop their specific key, collect all three, and grow stronger first.
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).
---
## Evaluation Criteria ⚖ #### More about the game and characters
* Special abilities:
* 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.
* Monsters:
* Goblin 👹: High critical hit chance(40%) 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.
| **Criteria** | **Points** | Once you obtain a specific key (e.g., Goblin Key), subsequent enemies of that same type (other Goblins) will never drop a key again. You can still fight enemies to earn XP based on enemy strength to automatically level up and increase your base stats (max health and Mana) and become strong enough to face the Dragon.
|-------------------------------------------------------------|------------| ___
| 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** |
## Tips 🚀 ### Object-Oriented Programming concepts implementation
- **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. #### 1. Encapsulation
- **Test your code**: Run different scenarios (fighting, running out of mana, leveling up, dying) to ensure everything works as expected. Data hiding is used to protect the internal state of objects.
- **Ask for help**: If you're stuck, reach out to your classmates or mentors. * Usage: All fields in class are declared as `private` or `protected`. Access to these fields are controlled through `public` getter and setter methods. (e.g. `getName`, `setHP`). This ensures that the name or health of the entity cannot be modified incorrectly outside the class.
#### 2. Inheritance
Code reusability is achieved by creating a hierarchy of classes and interfaces.
* Usage:
* `Player` is an abstract class implementing `Entity`. Subclasses: `Knight`, `Wizard`, `Assassin`.
* Also `Enemy` is the superclass for `Goblin`, `Skeleton`, `Vampire` and `Dragon`.
* `Armor` and `Weapon` implementing `Item`. `Sword`, `Dagger`, and `Wand` extend `Weapon`; `Robe`, `KnightArmor`, `LeatherArmor` extend `Armor`.
#### 3. Polymorphism
The ability to process objects differently based on their data type is used extensively.
* Usage:
* Method Overriding: Each enemy class overrides the `attack()` method. For example, the `Dragon` class overrides `attack()` to handle its special "Fiery Breath" mechanic, which ignores player defense. Similarly, each character class (`Knight`, `Wizard`, `Assassin`) overrides `specialAbility()` to provide unique skills.
* Polymorphic Collections: We use a `List<Enemy>` to store different types of enemies. We can iterate through this list and call `enemy.attack(player)` without knowing the specific type of enemy, and the correct version of the method will be executed.
#### 4. Abstraction
Complex implementation details are hidden behind simple interfaces.
* Usage:
* The `Entity` class is declared as abstract. It defines abstract methods like `attack()` which must be implemented by every subclass.
* The `Player` class is abstract, forcing subclasses like `Assassin` to implement the `specialAbility(Entity target)`.
## 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.
![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.