feat : implement Java Knight game #1
@@ -1,15 +1,13 @@
|
||||
package org.project;
|
||||
|
||||
import org.project.location.Location;
|
||||
import org.project.game.Game;
|
||||
import java.util.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
// TODO: ADD LOCATIONS TO YOUR GAME
|
||||
List<Location> locations = new ArrayList<>();
|
||||
|
||||
// TODO: IMPLEMENT GAMEPLAY
|
||||
public class Main
|
||||
{
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Game game = new Game();
|
||||
game.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,9 @@
|
||||
package org.project.entity;
|
||||
|
||||
public interface Entity {
|
||||
void attack(Entity target);
|
||||
|
||||
void defend();
|
||||
|
||||
void heal(int health);
|
||||
|
||||
void fillMana(int mana);
|
||||
|
||||
void takeDamage(int damage);
|
||||
|
||||
int getMaxHP();
|
||||
|
||||
int getMaxMP();
|
||||
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
public interface Entity
|
||||
{
|
||||
String getName();
|
||||
int getHealth();
|
||||
int getMaxHealth();
|
||||
boolean isAlive();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.project.entity.actions;
|
||||
|
||||
import org.project.entity.enemies.Enemy;
|
||||
|
||||
public interface ICombatActions
|
||||
{
|
||||
void lightAttack(Enemy enemy);
|
||||
void heavyAttack(Enemy enemy);
|
||||
void defend();
|
||||
void heal();
|
||||
void specialAbility(Enemy enemy);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.players.Player;
|
||||
import org.project.utilities.Colors;
|
||||
|
||||
public class Dragon extends Enemy
|
||||
{
|
||||
public Dragon()
|
||||
{
|
||||
super("Dragon", 250, 30, 200);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Player player)
|
||||
{
|
||||
System.out.println(Colors.RED + "🐉 Dragon used Fiery Breath!" + Colors.RESET);
|
||||
player.takeDamage(damage);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,34 +1,76 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.item.weapons.Weapon;
|
||||
import org.project.entity.Entity;
|
||||
import org.project.entity.players.Player;
|
||||
import org.project.utilities.Colors;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Enemy {
|
||||
Weapon weapon;
|
||||
private int hp;
|
||||
private int mp;
|
||||
public abstract class Enemy implements Entity
|
||||
{
|
||||
protected String name;
|
||||
protected int maxHealth;
|
||||
protected int health;
|
||||
protected int damage;
|
||||
protected int xpReward;
|
||||
|
||||
public Enemy(int hp, int mp, Weapon weapon) {
|
||||
this.hp = hp;
|
||||
this.mp = mp;
|
||||
protected boolean stunned = false;
|
||||
|
||||
this.weapon = weapon;
|
||||
public Enemy(String name, int maxHealth, int damage, int xpReward)
|
||||
{
|
||||
this.name = name;
|
||||
this.maxHealth = maxHealth;
|
||||
this.health = maxHealth;
|
||||
this.damage = damage;
|
||||
this.xpReward = xpReward;
|
||||
}
|
||||
|
||||
public abstract void attack(Player player);
|
||||
|
||||
public void takeDamage(int amount)
|
||||
{
|
||||
health -= amount;
|
||||
|
||||
if (health < 0)
|
||||
health = 0;
|
||||
|
||||
System.out.println(Colors.RED + name + " took " + amount + " damage!" + Colors.RESET);
|
||||
}
|
||||
|
||||
public int getXpReward()
|
||||
{
|
||||
return xpReward;
|
||||
}
|
||||
|
||||
public void setStunned(boolean stunned)
|
||||
{
|
||||
this.stunned = stunned;
|
||||
}
|
||||
|
||||
public boolean isStunned()
|
||||
{
|
||||
return stunned;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
hp -= damage;
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getHp() {
|
||||
return hp;
|
||||
@Override
|
||||
public int getHealth()
|
||||
{
|
||||
return health;
|
||||
}
|
||||
|
||||
public int getMp() {
|
||||
return mp;
|
||||
@Override
|
||||
public int getMaxHealth()
|
||||
{
|
||||
return maxHealth;
|
||||
}
|
||||
|
||||
public Weapon getWeapon() {
|
||||
return weapon;
|
||||
@Override
|
||||
public boolean isAlive()
|
||||
{
|
||||
return health > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.players.Player;
|
||||
import org.project.utilities.Colors;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class Goblin extends Enemy
|
||||
{
|
||||
Random random = new Random();
|
||||
|
||||
public Goblin()
|
||||
{
|
||||
super("Goblin", 60, 12, 25);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Player player)
|
||||
{
|
||||
int dmg = damage;
|
||||
|
||||
if (random.nextInt(100) < 40)
|
||||
{
|
||||
dmg *= 2;
|
||||
System.out.println(Colors.RED + "👹 Goblin landed CRITICAL HIT!" + Colors.RESET);
|
||||
}
|
||||
|
||||
player.takeDamage(dmg);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,37 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Skeleton {
|
||||
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
|
||||
import org.project.entity.players.Player;
|
||||
import org.project.utilities.Colors;
|
||||
|
||||
public class Skeleton extends Enemy
|
||||
{
|
||||
private boolean resurrected = false;
|
||||
|
||||
public Skeleton()
|
||||
{
|
||||
super("Skeleton", 80, 14, 35);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Player player)
|
||||
{
|
||||
player.takeDamage(damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAlive()
|
||||
{
|
||||
|
||||
if (health <= 0 && !resurrected)
|
||||
{
|
||||
resurrected = true;
|
||||
health = maxHealth / 2;
|
||||
|
||||
System.out.println(Colors.PURPLE + "☠️ Skeleton resurrected!" + Colors.RESET);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return health > 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.players.Player;
|
||||
import org.project.utilities.Colors;
|
||||
|
||||
public class Vampire extends Enemy {
|
||||
|
||||
public Vampire()
|
||||
{
|
||||
super("Vampire", 90, 16, 45);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Player player)
|
||||
{
|
||||
|
||||
player.takeDamage(damage);
|
||||
|
||||
health += 8;
|
||||
|
||||
if (health > maxHealth)
|
||||
health = maxHealth;
|
||||
|
||||
System.out.println(Colors.GREEN + "🦇 Vampire drained life!" + Colors.RESET);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.entity.enemies.Enemy;
|
||||
import org.project.utilities.Colors;
|
||||
|
||||
public class Assassin extends Player
|
||||
{
|
||||
public Assassin(String name)
|
||||
{
|
||||
super(name, 100, 120, 16);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassName()
|
||||
{
|
||||
return "Assassin";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lightAttack(Enemy enemy)
|
||||
{
|
||||
|
||||
int dmg = damage;
|
||||
|
||||
if (criticalNext)
|
||||
{
|
||||
dmg *= 2;
|
||||
criticalNext = false;
|
||||
|
||||
System.out.println(Colors.RED + "CRITICAL HIT!" + Colors.RESET);
|
||||
}
|
||||
|
||||
enemy.takeDamage(dmg);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heavyAttack(Enemy enemy)
|
||||
{
|
||||
if (mana < 10) return;
|
||||
|
||||
mana -= 10;
|
||||
|
||||
enemy.takeDamage(damage + 14);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend()
|
||||
{
|
||||
if (mana < 8) return;
|
||||
|
||||
mana -= 8;
|
||||
defending = true;
|
||||
|
||||
System.out.println("🗡️ Assassin prepares to evade!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal()
|
||||
{
|
||||
if (mana < 12) return;
|
||||
|
||||
mana -= 12;
|
||||
|
||||
health += 18;
|
||||
|
||||
if (health > maxHealth)
|
||||
health = maxHealth;
|
||||
|
||||
System.out.println(Colors.GREEN + "Assassin healed!" + Colors.RESET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void specialAbility(Enemy enemy)
|
||||
{
|
||||
if (mana < 20) return;
|
||||
|
||||
mana -= 20;
|
||||
|
||||
invisible = true;
|
||||
criticalNext = true;
|
||||
|
||||
System.out.println(Colors.PURPLE + "👻 Assassin became invisible!" + Colors.RESET);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,76 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Knight {
|
||||
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
|
||||
import org.project.entity.enemies.Enemy;
|
||||
import org.project.utilities.Colors;
|
||||
|
||||
public class Knight extends Player
|
||||
{
|
||||
|
||||
public Knight(String name)
|
||||
{
|
||||
super(name, 120, 70, 18);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassName()
|
||||
{
|
||||
return "Knight";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lightAttack(Enemy enemy)
|
||||
{
|
||||
System.out.println("⚔️ Knight used Light Attack!");
|
||||
enemy.takeDamage(damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heavyAttack(Enemy enemy)
|
||||
{
|
||||
if (mana < 10) return;
|
||||
|
||||
mana -= 10;
|
||||
|
||||
System.out.println("⚔️ Knight used Heavy Attack!");
|
||||
enemy.takeDamage(damage + 10);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend()
|
||||
{
|
||||
if (mana < 8) return;
|
||||
|
||||
mana -= 8;
|
||||
defending = true;
|
||||
|
||||
System.out.println("🛡️ Knight is defending!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal()
|
||||
{
|
||||
if (mana < 12) return;
|
||||
|
||||
mana -= 12;
|
||||
|
||||
health += 20;
|
||||
|
||||
if (health > maxHealth)
|
||||
health = maxHealth;
|
||||
|
||||
System.out.println(Colors.GREEN + "Knight healed!" + Colors.RESET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void specialAbility(Enemy enemy)
|
||||
{
|
||||
if (mana < 18) return;
|
||||
|
||||
mana -= 18;
|
||||
|
||||
enemy.takeDamage(damage + 20);
|
||||
enemy.setStunned(true);
|
||||
|
||||
System.out.println(Colors.PURPLE + "⚔️ SHIELD BASH! Enemy stunned!" + Colors.RESET);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,89 +1,146 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.weapons.Weapon;
|
||||
import org.project.entity.actions.ICombatActions;
|
||||
import org.project.utilities.Colors;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Player {
|
||||
import java.util.*;
|
||||
|
||||
public abstract class Player implements Entity, ICombatActions
|
||||
{
|
||||
protected String name;
|
||||
Weapon weapon;
|
||||
Armor armor;
|
||||
private int hp;
|
||||
private int maxHP;
|
||||
private int mp;
|
||||
private int maxMP;
|
||||
|
||||
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
|
||||
protected int maxHealth;
|
||||
protected int health;
|
||||
|
||||
protected int maxMana;
|
||||
protected int mana;
|
||||
|
||||
protected int damage;
|
||||
|
||||
protected int level = 1;
|
||||
protected int xp = 0;
|
||||
|
||||
protected boolean defending = false;
|
||||
protected boolean invisible = false;
|
||||
protected boolean criticalNext = false;
|
||||
|
||||
protected Set<String> keys = new HashSet<>();
|
||||
|
||||
public Player(String name, int maxHealth, int maxMana, int damage)
|
||||
{
|
||||
this.name = name;
|
||||
this.hp = hp;
|
||||
this.mp = mp;
|
||||
this.maxHealth = maxHealth;
|
||||
this.health = maxHealth;
|
||||
|
||||
this.weapon = weapon;
|
||||
this.armor = armor;
|
||||
this.maxMana = maxMana;
|
||||
this.mana = maxMana;
|
||||
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void attack(Entity target) {
|
||||
target.takeDamage(weapon.getDamage());
|
||||
}
|
||||
public abstract String getClassName();
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
// TODO
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
hp -= damage - armor.getDefense();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal(int health) {
|
||||
hp += health;
|
||||
if (hp > maxHP) {
|
||||
hp = maxHP;
|
||||
public void takeDamage(int amount)
|
||||
{
|
||||
if (invisible)
|
||||
{
|
||||
System.out.println(Colors.PURPLE + "Attack dodged due to invisibility!" + Colors.RESET);
|
||||
invisible = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (defending)
|
||||
{
|
||||
amount /= 2;
|
||||
defending = false;
|
||||
}
|
||||
|
||||
health -= amount;
|
||||
|
||||
if (health < 0)
|
||||
health = 0;
|
||||
|
||||
System.out.println(Colors.RED + name + " took " + amount + " damage!" + Colors.RESET);
|
||||
}
|
||||
|
||||
public void restore()
|
||||
{
|
||||
health = maxHealth;
|
||||
mana = maxMana;
|
||||
}
|
||||
|
||||
public void gainXP(int amount)
|
||||
{
|
||||
xp += amount;
|
||||
|
||||
System.out.println(Colors.YELLOW + "You gained " + amount + " XP!" + Colors.RESET);
|
||||
|
||||
if (xp >= level * 50)
|
||||
levelUp();
|
||||
}
|
||||
|
||||
public void levelUp()
|
||||
{
|
||||
level++;
|
||||
|
||||
maxHealth += 10;
|
||||
maxMana += 10;
|
||||
damage += 3;
|
||||
|
||||
health = maxHealth;
|
||||
mana = maxMana;
|
||||
|
||||
System.out.println(Colors.GREEN + "LEVEL UP! You are now level " + level + Colors.RESET);
|
||||
}
|
||||
|
||||
public boolean hasAllKeys()
|
||||
{
|
||||
return keys.contains("Goblin") && keys.contains("Skeleton") && keys.contains("Vampire");
|
||||
}
|
||||
|
||||
public void addKey(String key)
|
||||
{
|
||||
keys.add(key);
|
||||
System.out.println(Colors.YELLOW + "You obtained the " + key + " Key!" + Colors.RESET);
|
||||
}
|
||||
|
||||
public boolean hasKey(String key)
|
||||
{
|
||||
return keys.contains(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillMana(int mana) {
|
||||
mp += mana;
|
||||
if (mp > maxMP) {
|
||||
mp = maxMP;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getName() {
|
||||
public String getName()
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getHp() {
|
||||
return hp;
|
||||
@Override
|
||||
public int getHealth()
|
||||
{
|
||||
return health;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxHP() {
|
||||
return maxHP;
|
||||
}
|
||||
|
||||
public int getMp() {
|
||||
return mp;
|
||||
public int getMaxHealth()
|
||||
{
|
||||
return maxHealth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxMP() {
|
||||
return maxMP;
|
||||
public boolean isAlive()
|
||||
{
|
||||
return health > 0;
|
||||
}
|
||||
|
||||
public Weapon getWeapon() {
|
||||
return weapon;
|
||||
public int getMana()
|
||||
{
|
||||
return mana;
|
||||
}
|
||||
|
||||
public Armor getArmor() {
|
||||
return armor;
|
||||
public int getMaxMana()
|
||||
{
|
||||
return maxMana;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package org.project.entity.players;
|
||||
|
||||
import org.project.entity.enemies.Enemy;
|
||||
import org.project.utilities.Colors;
|
||||
|
||||
public class Wizard extends Player
|
||||
{
|
||||
public Wizard(String name)
|
||||
{
|
||||
super(name, 140, 80, 14);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassName()
|
||||
{
|
||||
return "Wizard";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lightAttack(Enemy enemy)
|
||||
{
|
||||
enemy.takeDamage(damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heavyAttack(Enemy enemy)
|
||||
{
|
||||
if (mana < 10) return;
|
||||
|
||||
mana -= 10;
|
||||
|
||||
enemy.takeDamage(damage + 12);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend()
|
||||
{
|
||||
if (mana < 8) return;
|
||||
|
||||
mana -= 8;
|
||||
defending = true;
|
||||
|
||||
System.out.println("🔮 Wizard raised magical shield!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void heal()
|
||||
{
|
||||
if (mana < 12) return;
|
||||
|
||||
mana -= 12;
|
||||
|
||||
health += 25;
|
||||
|
||||
if (health > maxHealth)
|
||||
health = maxHealth;
|
||||
|
||||
System.out.println(Colors.GREEN + "Wizard healed!" + Colors.RESET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void specialAbility(Enemy enemy)
|
||||
{
|
||||
if (mana < 20) return;
|
||||
|
||||
mana -= 20;
|
||||
|
||||
enemy.takeDamage(damage + 25);
|
||||
|
||||
health += 15;
|
||||
|
||||
if (health > maxHealth)
|
||||
health = maxHealth;
|
||||
|
||||
System.out.println(Colors.PURPLE + "🔥 Arcane Blast activated!" + Colors.RESET);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
package org.project.game;
|
||||
|
||||
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.location.Location;
|
||||
import org.project.utilities.Colors;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Game {
|
||||
|
||||
private final Scanner scanner = new Scanner(System.in);
|
||||
private final Random random = new Random();
|
||||
|
||||
private Player player;
|
||||
|
||||
private final Location[] locations = {
|
||||
new Location("Mordor", new Goblin()),
|
||||
new Location("Ancient Bones", new Skeleton()),
|
||||
new Location("Mystic Falls", new Vampire())
|
||||
};
|
||||
|
||||
|
||||
public void start()
|
||||
{
|
||||
System.out.println("=== JAVA KNIGHT ⚔️ ===");
|
||||
|
||||
System.out.print("Enter your name: ");
|
||||
String name = scanner.nextLine();
|
||||
|
||||
System.out.println("Choose your class:");
|
||||
System.out.println("1. Knight");
|
||||
System.out.println("2. Wizard");
|
||||
System.out.println("3. Assassin");
|
||||
|
||||
int choice = scanner.nextInt();
|
||||
|
||||
switch (choice)
|
||||
{
|
||||
case 2:
|
||||
player = new Wizard(name);
|
||||
break;
|
||||
case 3:
|
||||
player = new Assassin(name);
|
||||
break;
|
||||
default:
|
||||
player = new Knight(name);
|
||||
}
|
||||
|
||||
gameLoop();
|
||||
}
|
||||
|
||||
private void gameLoop()
|
||||
{
|
||||
|
||||
while (player.isAlive())
|
||||
{
|
||||
System.out.println("\nChoose a location:");
|
||||
|
||||
for (int i = 0; i < locations.length; i++)
|
||||
System.out.println((i + 1) + ". " + locations[i].getName());
|
||||
|
||||
int locChoice = scanner.nextInt();
|
||||
|
||||
Location location = locations[locChoice - 1];
|
||||
Enemy enemy = location.spawnEnemy();
|
||||
|
||||
|
||||
System.out.println("\n📍 Location: " + location.getName());
|
||||
System.out.println("Enemy appeared: " + enemy.getName());
|
||||
|
||||
System.out.println("\n1. Fight");
|
||||
System.out.println("2. Move");
|
||||
|
||||
if (player.hasAllKeys())
|
||||
System.out.println("3. Go to Castle");
|
||||
|
||||
int choice = scanner.nextInt();
|
||||
|
||||
if (choice == 1)
|
||||
{
|
||||
battle(enemy);
|
||||
|
||||
if (!player.isAlive())
|
||||
{
|
||||
System.out.println(Colors.RED + "GAME OVER!" + Colors.RESET);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
else if (choice == 2)
|
||||
{
|
||||
System.out.println("You moved away.");
|
||||
}
|
||||
else if (choice == 3 && player.hasAllKeys())
|
||||
{
|
||||
battle(new Dragon());
|
||||
|
||||
if (player.isAlive())
|
||||
{
|
||||
System.out.println(Colors.GREEN +
|
||||
"🐉 Dragon defeated! Peace restored to Javanest!" +
|
||||
Colors.RESET);
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println(Colors.RED + "GAME OVER!" + Colors.RESET);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void battle(Enemy enemy)
|
||||
{
|
||||
System.out.println("\n⚔️ Battle Started!");
|
||||
|
||||
while (player.isAlive() && enemy.isAlive()) {
|
||||
|
||||
System.out.println("\n[" + player.getName() + " - "
|
||||
+ player.getHealth() + "/" + player.getMaxHealth()
|
||||
+ " HP | "
|
||||
+ player.getMana() + "/" + player.getMaxMana()
|
||||
+ " Mana]");
|
||||
|
||||
System.out.println("[" + enemy.getName() + " - "
|
||||
+ enemy.getHealth() + "/" + enemy.getMaxHealth()
|
||||
+ " HP]");
|
||||
|
||||
System.out.println("\n1.Light Attack");
|
||||
System.out.println("2.Heavy Attack");
|
||||
System.out.println("3.Defend");
|
||||
System.out.println("4.Heal");
|
||||
System.out.println("5.Special Ability");
|
||||
|
||||
int choice = scanner.nextInt();
|
||||
|
||||
switch (choice) {
|
||||
case 1:
|
||||
player.lightAttack(enemy);
|
||||
break;
|
||||
case 2:
|
||||
player.heavyAttack(enemy);
|
||||
break;
|
||||
case 3:
|
||||
player.defend();
|
||||
break;
|
||||
case 4:
|
||||
player.heal();
|
||||
break;
|
||||
case 5:
|
||||
player.specialAbility(enemy);
|
||||
break;
|
||||
}
|
||||
|
||||
if (!enemy.isAlive())
|
||||
break;
|
||||
|
||||
if (enemy.isStunned())
|
||||
{
|
||||
System.out.println(Colors.YELLOW + enemy.getName() + " is stunned!" + Colors.RESET);
|
||||
enemy.setStunned(false);
|
||||
continue;
|
||||
}
|
||||
|
||||
enemy.attack(player);
|
||||
}
|
||||
|
||||
if (player.isAlive())
|
||||
{
|
||||
System.out.println(Colors.GREEN + enemy.getName() + " defeated!" + Colors.RESET);
|
||||
|
||||
player.gainXP(enemy.getXpReward());
|
||||
|
||||
dropKey(enemy);
|
||||
|
||||
player.restore();
|
||||
|
||||
System.out.println(Colors.BLUE + "HP and Mana restored!" + Colors.RESET);
|
||||
}
|
||||
}
|
||||
|
||||
private void dropKey(Enemy enemy)
|
||||
{
|
||||
if (enemy instanceof Dragon)
|
||||
return;
|
||||
|
||||
int chance = random.nextInt(100);
|
||||
|
||||
if (chance < 20 && !player.hasKey(enemy.getName()))
|
||||
player.addKey(enemy.getName());
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,14 @@
|
||||
package org.project.item;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
public class Item
|
||||
{
|
||||
private String name;
|
||||
|
||||
public interface Item {
|
||||
void use(Entity target);
|
||||
public Item(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,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);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package org.project.item.weapons;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Sword {
|
||||
/*
|
||||
THIS IS AN EXAMPLE OF A WEAPON DESIGN.
|
||||
*/
|
||||
|
||||
int abilityCharge;
|
||||
|
||||
public Sword() {
|
||||
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
||||
}
|
||||
|
||||
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
|
||||
public void uniqueAbility(ArrayList<Entity> targets) {
|
||||
abilityCharge += 2;
|
||||
for (Entity target : targets) {
|
||||
target.takeDamage(getDamage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package org.project.item.weapons;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Weapon {
|
||||
private int damage;
|
||||
private int manaCost;
|
||||
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS ATTRIBUTES
|
||||
*/
|
||||
|
||||
public Weapon(int damage, int manaCost) {
|
||||
this.damage = damage;
|
||||
this.manaCost = manaCost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void use(Entity target) {
|
||||
target.takeDamage(damage);
|
||||
}
|
||||
|
||||
public int getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
public int getManaCost() {
|
||||
return manaCost;
|
||||
}
|
||||
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
}
|
||||
@@ -2,27 +2,21 @@ package org.project.location;
|
||||
|
||||
import org.project.entity.enemies.Enemy;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class Location {
|
||||
|
||||
private String name;
|
||||
private Enemy enemy;
|
||||
|
||||
private ArrayList<Enemy> enemies;
|
||||
|
||||
public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) {
|
||||
this.locations = locations;
|
||||
this.enemies = enemies;
|
||||
public Location(String name, Enemy enemy) {
|
||||
this.name = name;
|
||||
this.enemy = enemy;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public ArrayList<Location> getLocations() {
|
||||
return locations;
|
||||
}
|
||||
|
||||
public ArrayList<Enemy> getEnemies() {
|
||||
return enemies;
|
||||
public Enemy spawnEnemy() {
|
||||
return enemy;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.project.utilities;
|
||||
|
||||
public class Colors
|
||||
{
|
||||
public static final String RESET = "\u001B[0m";
|
||||
public static final String RED = "\u001B[31m";
|
||||
public static final String GREEN = "\u001B[32m";
|
||||
public static final String BLUE = "\u001B[34m";
|
||||
public static final String YELLOW = "\u001B[33m";
|
||||
public static final String PURPLE = "\u001B[35m";
|
||||
}
|
||||
@@ -1,175 +1,314 @@
|
||||
# Fourth Assignment - Java Knight ⚔️
|
||||
A turn-based RPG with Roguelike elements which can be run in the terminal.
|
||||
# Java Knight ⚔️
|
||||
|
||||
### **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!*
|
||||
A turn-based RPG with Roguelike elements that runs directly in the terminal.
|
||||
|
||||
---
|
||||
|
||||
### **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.
|
||||
**Java Knight** is a terminal-based RPG developed in Java that focuses on practicing and applying core **Object-Oriented Programming (OOP)** concepts.
|
||||
|
||||
🎯 **Your goal is not just to complete the assignment but to learn and apply OOP effectively!**
|
||||
In this game, players choose a hero class and explore dangerous locations filled with monsters. By defeating enemies, players gain experience, level up, and collect special keys needed to unlock the final area of the game: the **Castle**.
|
||||
|
||||
### **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.
|
||||
Inside the Castle awaits the final boss — the mighty **Dragon**.
|
||||
|
||||
### **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.
|
||||
The project was designed to demonstrate clean software architecture using concepts such as:
|
||||
|
||||
- Inheritance
|
||||
- Encapsulation
|
||||
- Polymorphism
|
||||
- Abstraction
|
||||
- Method Overriding
|
||||
- Modular class design
|
||||
|
||||
---
|
||||
|
||||
## Tasks 📝
|
||||
# ⚙️ How to Compile and Run
|
||||
|
||||
Make sure you have **Java JDK 17+** installed.
|
||||
|
||||
### **Compile the Project**
|
||||
|
||||
Open a terminal in the project root folder and run:
|
||||
|
||||
### 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
|
||||
javac -d out src/org/project/**/*.java
|
||||
```
|
||||
2. Create a new branch named `develop` and switch to it.
|
||||
```bash
|
||||
git checkout -b develop
|
||||
```
|
||||
### 2️⃣ Step 2: Implement the Class Hierarchy 🌲
|
||||
|
||||
A well-structured OOP hierarchy is crucial. Avoid duplicating code by placing shared logic in abstract classes.
|
||||
|
||||
- **Entities & Locations:** You have `Entity`, `Item`(Bonus) , and `Location`.
|
||||
- **Players:** `Player` is an abstract class implementing `Entity`. Subclasses: `Wizard`, `Knight`, `Assassin`.
|
||||
- **Base Stat Differences:** Each class must have distinct starting stats. For example:
|
||||
- **Knight:** Highest Base Damage.
|
||||
- **Wizard:** Highest Max Health (HP).
|
||||
- **Assassin:** Highest Max Stamina/Mana.
|
||||
- **Enemies:** `Enemy` is an abstract class implementing `Entity`. Subclasses: `Skeleton`, `Goblin`, `Vampire`, and **`Dragon`**.
|
||||
- **The Boss:** Even though `Dragon` is the final boss, it **must** be a subclass of `Enemy` to inherit common combat properties, while possessing extremely high stats and unique mechanics.
|
||||
- **Item (Bonus):** `Consumable`, `Armor`, `Weapon` are abstract classes implementing `Item`. example :
|
||||
- KnightArmor extends Armor - you can add more subclasses of Armor for extra score
|
||||
- Sword extends Weapon - you can add more subclasses of Weapon for extra score
|
||||
- Flask extends Consumable - you can add more subclasses of Consumable for extra score
|
||||
|
||||

|
||||
|
||||
### 3️⃣ Step 3: Implement Player & Monster Methods 🏹
|
||||
|
||||
**Player Actions (The Rule of Five):**
|
||||
Every player class **must** implement exactly the following 5 actions (You can use an interface like `ICombatActions`). Every action (except Light Attack) consumes a specific amount of Mana/Stamina. The **Special Ability** must consume the *highest* amount of Mana compared to the others.
|
||||
1. **Light Attack:** Deals moderate damage and costs **NO Mana**. (Note: If the player runs out of Mana/Stamina, this is the ONLY action they can perform.)
|
||||
2. **Heavy Attack:** Deals high damage, medium Mana cost.
|
||||
3. **Defend:** Completely blocks or significantly reduces the damage of the enemy's *next* strike. Medium Mana cost.
|
||||
4. **Heal:** Restores a portion of the player's HP. Medium-high Mana cost.
|
||||
5. **Special Ability:** A unique class-based ultimate move (Highest Mana cost):
|
||||
- **Wizard** 🧙♂️: Casts a devastating spell that damages the enemy while simultaneously replenishing some HP.
|
||||
- **Assassin** 🗡️: Turns invisible, dodging the next incoming attack completely and guaranteeing a *Critical Hit* on their next turn.
|
||||
- **Knight** ⚔️: Performs a shield bash that stuns the enemy, forcing them to skip their next turn while dealing heavy damage.
|
||||
|
||||
**Monster Abilities:**
|
||||
- **Goblin** 👹: High critical hit chance but low health.
|
||||
- **Skeleton** ☠️: Can resurrect once per battle with 50% HP.
|
||||
- **Vampire** 🦇: Lifesteal ability – a portion of the damage it deals to the player is added back to its own health.
|
||||
- **Dragon (Final Boss)** 🐉: Immune to normal defense. Its fiery breath bypasses shields and deals massive damage.
|
||||
|
||||
🔹 Make sure each entity **prints messages** when performing actions. example output (while in combat) :
|
||||
|
||||
```bash
|
||||
You chose to FIGHT!
|
||||
|
||||
[Ser Duncan - 45/45 HP | 40/40 Mana]
|
||||
[Goblin - 30/30 HP]
|
||||
This command compiles all Java source files and stores the compiled classes inside the `out` directory.
|
||||
|
||||
---
|
||||
|
||||
Your Turn:
|
||||
1. Light Attack | 2. Heavy Attack (-8 Mana) | 3. Defend (-6 Mana) | 4. Heal (-12 Mana) | 5. Shield Bash (-15 Mana)
|
||||
```
|
||||
### **Run the Game**
|
||||
|
||||
```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
|
||||
java -cp out org.project.Main
|
||||
```
|
||||
```
|
||||
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).
|
||||
|
||||
The game will start in the terminal.
|
||||
|
||||
### 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**.
|
||||
# 🧱 Project Structure & Classes
|
||||
|
||||
🔹 Example game loop structure:
|
||||
The project follows a modular object-oriented design.
|
||||
|
||||
---
|
||||
|
||||
## **Main**
|
||||
|
||||
The entry point of the application.
|
||||
|
||||
Responsibilities:
|
||||
|
||||
- Starts the game
|
||||
- Creates the `Game` object
|
||||
- Runs the main game loop
|
||||
|
||||
---
|
||||
|
||||
## **Game**
|
||||
|
||||
Controls the entire gameplay flow.
|
||||
|
||||
Responsibilities:
|
||||
|
||||
- Character selection
|
||||
- Location selection
|
||||
- Combat management
|
||||
- XP and leveling
|
||||
- Key collection
|
||||
- Final boss battle
|
||||
|
||||
---
|
||||
|
||||
## **Entity**
|
||||
|
||||
Base class for all living characters in the game.
|
||||
|
||||
Shared attributes:
|
||||
|
||||
- Name
|
||||
- Health
|
||||
- Damage
|
||||
|
||||
Both `Player` and `Enemy` inherit from this class.
|
||||
|
||||
---
|
||||
|
||||
## **Player (Abstract Class)**
|
||||
|
||||
Represents the playable character.
|
||||
|
||||
Contains common player functionality such as:
|
||||
|
||||
- Health
|
||||
- Mana/Stamina
|
||||
- Combat actions
|
||||
- XP system
|
||||
- Level system
|
||||
|
||||
### **Player Classes**
|
||||
|
||||
#### **Knight 🛡️**
|
||||
- High health
|
||||
- Balanced combat style
|
||||
- Special ability can stun enemies
|
||||
|
||||
#### **Wizard 🔮**
|
||||
- High mana pool
|
||||
- Strong magical attacks
|
||||
- Special ability deals damage and heals
|
||||
|
||||
#### **Assassin 🗡️**
|
||||
- Fast attacks
|
||||
- High critical damage
|
||||
- Special ability boosts burst damage
|
||||
|
||||
---
|
||||
|
||||
## **Enemy (Abstract Class)**
|
||||
|
||||
Base class for all enemies.
|
||||
|
||||
Each enemy type has unique behavior and abilities.
|
||||
|
||||
### **Enemy Types**
|
||||
|
||||
#### **Goblin**
|
||||
- Low HP
|
||||
- High critical chance
|
||||
|
||||
#### **Skeleton**
|
||||
- Can resurrect once after death
|
||||
|
||||
#### **Vampire**
|
||||
- Steals health from the player
|
||||
|
||||
#### **Dragon 🐉**
|
||||
- Final boss
|
||||
- Ignores defense abilities
|
||||
- Deals massive damage
|
||||
|
||||
---
|
||||
|
||||
## **Location**
|
||||
|
||||
Represents explorable areas in the game.
|
||||
|
||||
Each location contains one specific enemy type.
|
||||
|
||||
### Example Locations
|
||||
|
||||
- Dark Forest → Goblin
|
||||
- Ancient Ruins → Skeleton
|
||||
- Bloody Swamp → Vampire
|
||||
|
||||
---
|
||||
|
||||
## **Item**
|
||||
|
||||
Represents collectible items such as keys dropped by enemies.
|
||||
|
||||
Keys are required to unlock the Castle.
|
||||
|
||||
---
|
||||
|
||||
## **Colors**
|
||||
|
||||
Utility class containing ANSI color codes for colorful terminal output.
|
||||
|
||||
---
|
||||
|
||||
# 🧠 OOP Principles Used
|
||||
|
||||
### **Encapsulation**
|
||||
Player and enemy stats are protected using methods such as:
|
||||
|
||||
```java
|
||||
while (player.isAlive() && enemy.isAlive())
|
||||
player.attack(enemy);
|
||||
if (enemy.isAlive()) {
|
||||
enemy.attack(player);
|
||||
}
|
||||
}
|
||||
takeDamage()
|
||||
heal()
|
||||
```
|
||||
|
||||
|
||||
### 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).
|
||||
instead of direct field access.
|
||||
|
||||
---
|
||||
|
||||
## Evaluation Criteria ⚖
|
||||
### **Inheritance**
|
||||
Shared behavior is inherited from base classes.
|
||||
|
||||
| **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** |
|
||||
```text
|
||||
Entity
|
||||
├── Player
|
||||
│ ├── Knight
|
||||
│ ├── Wizard
|
||||
│ └── Assassin
|
||||
│
|
||||
└── Enemy
|
||||
├── Goblin
|
||||
├── Skeleton
|
||||
├── Vampire
|
||||
└── Dragon
|
||||
```
|
||||
|
||||
## Tips 🚀
|
||||
- **Follow OOP principles**: Avoid redundant code by using inheritance properly. Think carefully about what belongs in an abstract class vs. a specific subclass. Make sure you use overriding and overloading correctly.
|
||||
- **Test your code**: Run different scenarios (fighting, running out of mana, leveling up, dying) to ensure everything works as expected.
|
||||
- **Ask for help**: If you're stuck, reach out to your classmates or mentors.
|
||||
---
|
||||
|
||||
## Submission ⌛
|
||||
- **Deadline**: Submit your assignment before **21 Ordibehesht (May 11th, 2026)**.
|
||||
- **Submission Format**: Push your code to your forked repository, create a PR, and ensure your comprehensive `README.md` is included in the root directory.
|
||||
### **Polymorphism**
|
||||
Different classes override methods such as:
|
||||
|
||||

|
||||
###### - Born of God and Void. You shall seal the blinding light that plagues their dreams. You are the Vessel. You are the Java Knight.
|
||||
```java
|
||||
attack()
|
||||
specialAbility()
|
||||
```
|
||||
|
||||
allowing each subclass to behave differently.
|
||||
|
||||
---
|
||||
|
||||
### **Abstraction**
|
||||
Abstract classes like `Player` and `Enemy` define shared structure while forcing subclasses to implement specific behavior.
|
||||
|
||||
---
|
||||
|
||||
# 🎮 How to Play
|
||||
|
||||
## **1. Choose Your Class**
|
||||
|
||||
At the beginning of the game, choose one of three character classes:
|
||||
|
||||
| Class | Description |
|
||||
|---|---|
|
||||
| Knight | High defense and balanced damage |
|
||||
| Wizard | Powerful magic attacks and healing |
|
||||
| Assassin | Fast attacks and high critical damage |
|
||||
|
||||
---
|
||||
|
||||
## **2. Choose a Location**
|
||||
|
||||
Each location contains a different enemy type.
|
||||
|
||||
Example:
|
||||
|
||||
- Mordor → Goblins
|
||||
- Ancient Bones → Skeletons
|
||||
- Mystic Falls → Vampires
|
||||
|
||||
---
|
||||
|
||||
## **3. Fight Enemies**
|
||||
|
||||
During combat, you can choose from 5 actions:
|
||||
|
||||
1. Light Attack
|
||||
2. Heavy Attack
|
||||
3. Defend
|
||||
4. Heal
|
||||
5. Special Ability
|
||||
|
||||
---
|
||||
|
||||
## **4. Gain XP and Level Up**
|
||||
|
||||
Defeating enemies grants XP.
|
||||
|
||||
Leveling up increases:
|
||||
|
||||
- Maximum Health
|
||||
- Maximum Mana/Stamina
|
||||
|
||||
---
|
||||
|
||||
## **5. Collect Keys 🗝️**
|
||||
|
||||
Enemies have a chance to drop unique keys.
|
||||
|
||||
You must collect all keys before entering the Castle.
|
||||
|
||||
---
|
||||
|
||||
## **6. Defeat the Dragon 🐉**
|
||||
|
||||
Once all keys are collected, the Castle becomes accessible.
|
||||
|
||||
Defeat the Dragon to win the game.
|
||||
|
||||
If your HP reaches 0, the game ends.
|
||||
|
||||
---
|
||||
|
||||
# ✅ Victory Condition
|
||||
|
||||
- Collect all keys
|
||||
- Enter the Castle
|
||||
- Defeat the Dragon
|
||||
|
||||
---
|
||||
|
||||
# ❌ Game Over
|
||||
|
||||
- Your character dies during battle
|
||||
|
||||
---
|
||||
|
||||
Good luck, warrior ⚔️
|
||||
|
||||
Reference in New Issue
Block a user