This commit is contained in:
2026-07-24 15:34:03 +03:30
parent 78d4bedb08
commit ae3bb6d43c
39 changed files with 510 additions and 183 deletions
+5
View File
@@ -1,6 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
+105 -7
View File
@@ -1,15 +1,113 @@
package org.project;
import org.project.location.Location;
import org.project.entity.enemies.*;
import org.project.entity.players.*;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO: ADD LOCATIONS TO YOUR GAME
List<Location> locations = new ArrayList<>();
private static final Set<String> collectedKeys = new HashSet<>();
private static final Scanner scanner = new Scanner(System.in);
// TODO: IMPLEMENT GAMEPLAY
public static void main(String[] args) {
System.out.println("\u001B[33m⚔️ WELCOME TO JAVA KNIGHT: THE LEGEND OF JAVANEST ⚔️\u001B[0m\n");
System.out.println("Choose your Class:");
System.out.println("1. Knight (Highest Damage | Special: Shield Bash)");
System.out.println("2. Wizard (Highest HP | Special: Devastating Spell)");
System.out.println("3. Assassin (Highest Mana | Special: Invisibility & Critical Hit)");
System.out.print("→ Choice: ");
int choice = scanner.nextInt();
scanner.nextLine();
System.out.print("Enter your Hero's name: ");
String name = scanner.nextLine();
Player player;
if (choice == 2) player = new Wizard(name);
else if (choice == 3) player = new Assassin(name);
else player = new Knight(name);
System.out.println("\n\u001B[32mWelcome " + player.getName() + "! Your journey begins...\u001B[0m\n");
while (player.isAlive()) {
System.out.println("\n------------------------------------------------");
System.out.println("🔑 Keys Collected: " + collectedKeys.size() + "/3 " + collectedKeys);
System.out.println("1. Explore Location (Fight Monster)");
System.out.println("2. Move to Another Location");
if (collectedKeys.size() >= 3) {
System.out.println("\u001B[31m3. Enter the Castle to Fight the Dragon! 🏰🐉\u001B[0m");
}
System.out.print("→ Choose Action: ");
int menuChoice = scanner.nextInt();
if (menuChoice == 1) {
Enemy enemy = getRandomEnemy();
startCombat(player, enemy);
} else if (menuChoice == 2) {
System.out.println("🏃 You moved to a new location...");
} else if (menuChoice == 3 && collectedKeys.size() >= 3) {
System.out.println("\n\u001B[31m🔥 ENTERING THE DRAGON'S LAIR... 🔥\u001B[0m");
startCombat(player, new Dragon());
if (player.isAlive()) {
System.out.println("\n\u001B[32m🎉 VICTORY! You defeated the Dragon and saved Javanest!\u001B[0m");
}
break;
}
}
if (!player.isAlive()) {
System.out.println("\n\u001B[31m💀 GAME OVER! You have fallen in combat.\u001B[0m");
}
}
private static Enemy getRandomEnemy() {
int rand = new Random().nextInt(3);
if (rand == 0) return new Goblin();
if (rand == 1) return new Skeleton();
return new Vampire();
}
private static void startCombat(Player player, Enemy enemy) {
System.out.println("\n⚔️ \u001B[31mA wild " + enemy.getName() + " appeared!\u001B[0m");
while (player.isAlive() && enemy.isAlive()) {
System.out.println("\n[" + player.getName() + " - \u001B[32m" + player.getHp() + "/" + player.getMaxHP() + " HP\u001B[0m | \u001B[34m" + player.getMp() + "/" + player.getMaxMP() + " Mana\u001B[0m]");
System.out.println("[" + enemy.getName() + " - \u001B[31m" + enemy.getHp() + "/" + enemy.getMaxHP() + " HP\u001B[0m]");
System.out.println("---");
System.out.println("Your Turn:");
System.out.println("1. Light Attack | 2. Heavy Attack (-8 Mana) | 3. Defend (-6 Mana) | 4. Heal (-12 Mana) | 5. Special Ability");
System.out.print("→ Chose: ");
int action = scanner.nextInt();
switch (action) {
case 1 -> player.lightAttack(enemy);
case 2 -> player.heavyAttack(enemy);
case 3 -> player.defend();
case 4 -> player.castHeal();
case 5 -> player.specialAbility(enemy);
default -> player.lightAttack(enemy);
}
if (enemy.isAlive()) {
System.out.println("\n" + enemy.getName() + "'s Turn:");
enemy.attack(player);
}
}
if (player.isAlive()) {
System.out.println("\n\u001B[32m🏆 You defeated the " + enemy.getName() + "!\u001B[0m");
player.addXp(enemy.getXpReward());
if (!(enemy instanceof Dragon)) {
String key = enemy.getKeyType();
if (!collectedKeys.contains(key) && Math.random() < 0.5) {
collectedKeys.add(key);
System.out.println("\u001B[33m🔑 KEY DROPPED! Obtained: " + key + "\u001B[0m");
}
}
player.restoreStats();
}
}
}
@@ -2,20 +2,14 @@ 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);
boolean isAlive();
int getHp();
int getMaxHP();
int getMp();
int getMaxMP();
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
}
}
@@ -0,0 +1,23 @@
package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.item.weapons.Sword;
public class Dragon extends Enemy {
public Dragon() {
super("Dragon", 120, 0, new Sword(), "Dragon Core");
this.xpReward = 200;
}
@Override
public void attack(Entity target) {
if (isStunned) {
System.out.println("💫 Dragon is stunned and skipped turn!");
isStunned = false;
return;
}
System.out.println("🐉🔥 Dragon used \u001B[31mFiery Breath!\u001B[0m (Bypasses defenses!)");
target.takeDamage(22);
}
}
@@ -1,34 +1,60 @@
package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.item.weapons.Weapon;
// 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 hp;
protected int maxHp;
protected int mp;
protected int maxMp;
protected Weapon weapon;
protected int xpReward = 25;
protected String keyType;
protected boolean isStunned = false;
public Enemy(int hp, int mp, Weapon weapon) {
public Enemy(String name, int hp, int mp, Weapon weapon, String keyType) {
this.name = name;
this.hp = hp;
this.maxHp = hp;
this.mp = mp;
this.maxMp = mp;
this.weapon = weapon;
this.keyType = keyType;
}
@Override
public void attack(Entity target) {
if (isStunned) {
System.out.println("💫 " + name + " is stunned and cannot move!");
isStunned = false;
return;
}
int damage = weapon != null ? weapon.getDamage() : 10;
System.out.println("👹 " + name + " attacks!");
target.takeDamage(damage);
}
@Override
public void takeDamage(int damage) {
hp -= damage;
if (hp < 0) hp = 0;
System.out.println(name + " took \u001B[31m" + damage + "\u001B[0m damage! (" + hp + "/" + maxHp + " HP remaining)");
}
public int getHp() {
return hp;
}
@Override public void defend() {}
@Override public void heal(int health) { hp += health; if (hp > maxHp) hp = maxHp; }
@Override public void fillMana(int mana) {}
@Override public boolean isAlive() { return hp > 0; }
public int getMp() {
return mp;
}
public Weapon getWeapon() {
return weapon;
}
}
public void setStunned(boolean stunned) { isStunned = stunned; }
public String getName() { return name; }
@Override public int getHp() { return hp; }
@Override public int getMaxHP() { return maxHp; }
@Override public int getMp() { return mp; }
@Override public int getMaxMP() { return maxMp; }
public Weapon getWeapon() { return weapon; }
public int getXpReward() { return xpReward; }
public String getKeyType() { return keyType; }
}
@@ -0,0 +1,28 @@
package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.item.weapons.Sword;
public class Goblin extends Enemy {
public Goblin() {
super("Goblin", 30, 0, new Sword(), "Goblin Key");
this.xpReward = 20;
}
@Override
public void attack(Entity target) {
if (isStunned) {
System.out.println("💫 Goblin is stunned and skipped turn!");
isStunned = false;
return;
}
if (Math.random() < 0.35) {
System.out.println("👹 Goblin used \u001B[35mCritical Strike!\u001B[0m");
target.takeDamage(20);
} else {
System.out.println("👹 Goblin used Scratch!");
target.takeDamage(10);
}
}
}
@@ -1,6 +1,22 @@
package org.project.entity.enemies;
// TODO: UPDATE IMPLEMENTATION
public class Skeleton {
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
}
import org.project.item.weapons.Sword;
public class Skeleton extends Enemy {
private boolean hasResurrected = false;
public Skeleton() {
super("Skeleton", 35, 0, new Sword(), "Skeleton Key");
this.xpReward = 25;
}
@Override
public void takeDamage(int damage) {
super.takeDamage(damage);
if (hp <= 0 && !hasResurrected) {
hasResurrected = true;
hp = maxHp / 2;
System.out.println("☠️ \u001B[33mSkeleton Resurrected with 50% HP!\u001B[0m");
}
}
}
@@ -0,0 +1,26 @@
package org.project.entity.enemies;
import org.project.entity.Entity;
import org.project.item.weapons.Sword;
public class Vampire extends Enemy {
public Vampire() {
super("Vampire", 45, 0, new Sword(), "Vampire Key");
this.xpReward = 35;
}
@Override
public void attack(Entity target) {
if (isStunned) {
System.out.println("💫 Vampire is stunned and skipped turn!");
isStunned = false;
return;
}
int damage = 12;
System.out.println("🦇 Vampire used \u001B[31mLifesteal Bite!\u001B[0m");
target.takeDamage(damage);
heal(damage / 2);
System.out.println("🩸 Vampire healed for " + (damage / 2) + " HP!");
}
}
@@ -0,0 +1,24 @@
package org.project.entity.players;
import org.project.entity.Entity;
import org.project.item.armors.KnightArmor;
import org.project.item.weapons.Sword;
public class Assassin extends Player {
public Assassin(String name) {
super(name, 40, 60, new Sword(), new KnightArmor());
}
@Override
public void specialAbility(Entity target) {
int manaCost = 18;
if (mp < manaCost) {
System.out.println("❌ Not enough Mana/Stamina for Invisibility!");
return;
}
mp -= manaCost;
isInvisible = true;
nextAttackCritical = true;
System.out.println("🗡️👻 " + name + " turned Invisible! Next attack will be a Critical Hit and incoming damage is dodged!");
}
}
@@ -1,6 +1,28 @@
package org.project.entity.players;
// TODO: UPDATE IMPLEMENTATION
public class Knight {
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
}
import org.project.entity.Entity;
import org.project.entity.enemies.Enemy;
import org.project.item.armors.KnightArmor;
import org.project.item.weapons.Sword;
public class Knight extends Player {
public Knight(String name) {
super(name, 50, 40, new Sword(), new KnightArmor());
}
@Override
public void specialAbility(Entity target) {
int manaCost = 15;
if (mp < manaCost) {
System.out.println("❌ Not enough Mana/Stamina for Shield Bash!");
return;
}
mp -= manaCost;
System.out.println("🛡️⚡ " + name + " used Shield Bash! (-" + manaCost + " Mana)");
target.takeDamage(25);
if (target instanceof Enemy) {
((Enemy) target).setStunned(true);
System.out.println("💫 Enemy is stunned and will skip their next turn!");
}
}
}
@@ -4,86 +4,162 @@ import org.project.entity.Entity;
import org.project.item.armors.Armor;
import org.project.item.weapons.Weapon;
// TODO: UPDATE IMPLEMENTATION
public abstract class Player {
public abstract class Player implements Entity {
protected String name;
Weapon weapon;
Armor armor;
private int hp;
private int maxHP;
private int mp;
private int maxMP;
protected Weapon weapon;
protected Armor armor;
protected int hp;
protected int maxHP;
protected int mp;
protected int maxMP;
protected int level = 1;
protected int xp = 0;
protected int xpToNextLevel = 50;
protected boolean isDefending = false;
protected boolean isInvisible = false;
protected boolean nextAttackCritical = false;
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
this.name = name;
this.hp = hp;
this.maxHP = hp;
this.mp = mp;
this.maxMP = mp;
this.weapon = weapon;
this.armor = armor;
}
@Override
public void attack(Entity target) {
target.takeDamage(weapon.getDamage());
lightAttack(target);
}
public void lightAttack(Entity target) {
int damage = weapon != null ? weapon.getDamage() : 10;
if (nextAttackCritical) {
damage *= 2;
nextAttackCritical = false;
System.out.println("\u001B[35m💥 CRITICAL HIT!\u001B[0m");
}
System.out.println("⚔️ " + name + " used Light Attack! (0 Mana)");
target.takeDamage(damage);
}
public void heavyAttack(Entity target) {
int manaCost = 8;
if (mp < manaCost) {
System.out.println("❌ Not enough Mana/Stamina! Using Light Attack instead.");
lightAttack(target);
return;
}
mp -= manaCost;
int damage = (weapon != null ? weapon.getDamage() : 10) + 12;
if (nextAttackCritical) {
damage *= 2;
nextAttackCritical = false;
System.out.println("\u001B[35m💥 CRITICAL HIT!\u001B[0m");
}
System.out.println("⚔️ " + name + " used Heavy Attack! (-" + manaCost + " Mana)");
target.takeDamage(damage);
}
@Override
public void defend() {
// TODO
}
@Override
public void takeDamage(int damage) {
hp -= damage - armor.getDefense();
int manaCost = 6;
if (mp < manaCost) {
System.out.println("❌ Not enough Mana/Stamina to Defend!");
return;
}
mp -= manaCost;
isDefending = true;
System.out.println("🛡️ " + name + " is Defending! (-" + manaCost + " Mana)");
}
@Override
public void heal(int health) {
hp += health;
if (hp > maxHP) {
hp = maxHP;
}
if (hp > maxHP) hp = maxHP;
}
public void castHeal() {
int manaCost = 12;
if (mp < manaCost) {
System.out.println("❌ Not enough Mana/Stamina to Heal!");
return;
}
mp -= manaCost;
int healAmount = 25;
heal(healAmount);
System.out.println("💚 " + name + " healed for " + healAmount + " HP! (-" + manaCost + " Mana)");
}
public abstract void specialAbility(Entity target);
@Override
public void fillMana(int mana) {
mp += mana;
if (mp > maxMP) {
mp = maxMP;
if (mp > maxMP) mp = maxMP;
}
@Override
public void takeDamage(int damage) {
if (isInvisible) {
System.out.println("👻 " + name + " dodged the attack completely (Invisible)!");
isInvisible = false;
return;
}
int actualDamage = damage;
if (armor != null) {
actualDamage -= armor.getDefense();
}
if (isDefending) {
actualDamage /= 2;
isDefending = false;
System.out.println("🛡️ Defense reduced incoming damage!");
}
if (actualDamage < 0) actualDamage = 0;
hp -= actualDamage;
System.out.println("💥 " + name + " took \u001B[31m" + actualDamage + "\u001B[0m damage!");
}
public void addXp(int amount) {
xp += amount;
System.out.println("\u001B[33m✨ Gained " + amount + " XP!\u001B[0m");
if (xp >= xpToNextLevel) {
levelUp();
}
}
public String getName() {
return name;
private void levelUp() {
level++;
xp -= xpToNextLevel;
xpToNextLevel = (int) (xpToNextLevel * 1.5);
maxHP += 20;
maxMP += 15;
hp = maxHP;
mp = maxMP;
System.out.println("\u001B[32m🎉 LEVEL UP! Reached Level " + level + "! Max HP and Mana increased!\u001B[0m");
}
public int getHp() {
return hp;
public void restoreStats() {
hp = maxHP;
mp = maxMP;
isDefending = false;
isInvisible = false;
nextAttackCritical = false;
}
@Override
public int getMaxHP() {
return maxHP;
}
public int getMp() {
return mp;
}
@Override
public int getMaxMP() {
return maxMP;
}
public Weapon getWeapon() {
return weapon;
}
public Armor getArmor() {
return armor;
}
}
@Override public boolean isAlive() { return hp > 0; }
public String getName() { return name; }
@Override public int getHp() { return hp; }
@Override public int getMaxHP() { return maxHP; }
@Override public int getMp() { return mp; }
@Override public int getMaxMP() { return maxMP; }
public Weapon getWeapon() { return weapon; }
public Armor getArmor() { return armor; }
}
@@ -0,0 +1,25 @@
package org.project.entity.players;
import org.project.entity.Entity;
import org.project.item.armors.KnightArmor;
import org.project.item.weapons.Sword;
public class Wizard extends Player {
public Wizard(String name) {
super(name, 70, 50, new Sword(), new KnightArmor());
}
@Override
public void specialAbility(Entity target) {
int manaCost = 20;
if (mp < manaCost) {
System.out.println("❌ Not enough Mana/Stamina for Devastating Spell!");
return;
}
mp -= manaCost;
System.out.println("🧙‍♂️✨ " + name + " cast Devastating Spell! (-" + manaCost + " Mana)");
target.takeDamage(35);
heal(15);
System.out.println("💚 " + name + " replenished 15 HP from the spell!");
}
}
@@ -4,8 +4,4 @@ import org.project.entity.Entity;
public interface Item {
void use(Entity target);
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
}
}
@@ -1,17 +1,19 @@
package org.project.item.armors;
// TODO: UPDATE IMPLEMENTATION
public abstract class Armor {
private int defense;
private int maxDefense;
private int durability;
private int maxDurability;
import org.project.item.Item;
private boolean isBroke;
public abstract class Armor implements Item {
protected int defense;
protected int maxDefense;
protected int durability;
protected int maxDurability;
protected boolean isBroke;
public Armor(int defense, int durability) {
this.defense = defense;
this.maxDefense = defense;
this.durability = durability;
this.maxDurability = durability;
}
public void checkBreak() {
@@ -21,22 +23,13 @@ public abstract class Armor {
}
}
// 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;
}
}
public int getDefense() { return defense; }
public int getDurability() { return durability; }
public boolean isBroke() { return isBroke; }
}
@@ -1,6 +1,14 @@
package org.project.item.armors;
// TODO: UPDATE IMPLEMENTATION
public class KnightArmor {
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
import org.project.entity.Entity;
public class KnightArmor extends Armor {
public KnightArmor() {
super(5, 100);
}
@Override
public void use(Entity target) {
System.out.println("Armor equipped.");
}
}
@@ -1,8 +1,6 @@
package org.project.item.consumables;
// TODO: UPDATE IMPLEMENTATION
public abstract class Consumable {
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
}
import org.project.item.Item;
public abstract class Consumable implements Item {
}
@@ -2,15 +2,10 @@ 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
public class Flask extends Consumable {
@Override
public void use(Entity target) {
target.heal(target.getMaxHP() / 10);
target.heal(target.getMaxHP() / 2);
System.out.println("🧪 Flask restored HP!");
}
}
}
@@ -1,26 +1,20 @@
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 class Sword extends Weapon {
private int abilityCharge;
public Sword() {
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
super(12, 0);
this.abilityCharge = 0;
}
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
public void uniqueAbility(ArrayList<Entity> targets) {
abilityCharge += 2;
for (Entity target : targets) {
target.takeDamage(getDamage());
}
}
}
}
@@ -1,15 +1,11 @@
package org.project.item.weapons;
import org.project.entity.Entity;
import org.project.item.Item;
// TODO: UPDATE IMPLEMENTATION
public abstract class Weapon {
private int damage;
private int manaCost;
/*
TODO: ADD OTHER REQUIRED AND BONUS ATTRIBUTES
*/
public abstract class Weapon implements Item {
protected int damage;
protected int manaCost;
public Weapon(int damage, int manaCost) {
this.damage = damage;
@@ -21,15 +17,6 @@ public abstract class Weapon {
target.takeDamage(damage);
}
public int getDamage() {
return damage;
}
public int getManaCost() {
return manaCost;
}
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
}
public int getDamage() { return damage; }
public int getManaCost() { return manaCost; }
}
@@ -6,23 +6,16 @@ import java.util.ArrayList;
public class Location {
private String name;
private ArrayList<Location> locations;
private ArrayList<Enemy> enemies;
public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) {
this.locations = locations;
this.enemies = enemies;
public Location(String name) {
this.name = name;
this.locations = new ArrayList<>();
this.enemies = new ArrayList<>();
}
public String getName() {
return name;
}
public ArrayList<Location> getLocations() {
return locations;
}
public ArrayList<Enemy> getEnemies() {
return enemies;
}
}
public String getName() { return name; }
public ArrayList<Location> getLocations() { return locations; }
public ArrayList<Enemy> getEnemies() { return enemies; }
}
Binary file not shown.