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"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="RemoteRepositoriesConfiguration"> <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> <remote-repository>
<option name="id" value="central" /> <option name="id" value="central" />
<option name="name" value="Central Repository" /> <option name="name" value="Central Repository" />
+105 -7
View File
@@ -1,15 +1,113 @@
package org.project; 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.*;
import java.util.List;
public class Main { public class Main {
public static void main(String[] args) { private static final Set<String> collectedKeys = new HashSet<>();
// TODO: ADD LOCATIONS TO YOUR GAME private static final Scanner scanner = new Scanner(System.in);
List<Location> locations = new ArrayList<>();
// 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 { public interface Entity {
void attack(Entity target); void attack(Entity target);
void defend(); void defend();
void heal(int health); void heal(int health);
void fillMana(int mana); void fillMana(int mana);
void takeDamage(int damage); void takeDamage(int damage);
boolean isAlive();
int getHp();
int getMaxHP(); int getMaxHP();
int getMp();
int getMaxMP(); 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; package org.project.entity.enemies;
import org.project.entity.Entity;
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 { protected String name;
Weapon weapon; protected int hp;
private int hp; protected int maxHp;
private int mp; 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.hp = hp;
this.maxHp = hp;
this.mp = mp; this.mp = mp;
this.maxMp = mp;
this.weapon = weapon; 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 @Override
public void takeDamage(int damage) { public void takeDamage(int damage) {
hp -= 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() { @Override public void defend() {}
return hp; @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() { public void setStunned(boolean stunned) { isStunned = stunned; }
return mp; public String getName() { return name; }
} @Override public int getHp() { return hp; }
@Override public int getMaxHP() { return maxHp; }
public Weapon getWeapon() { @Override public int getMp() { return mp; }
return weapon; @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; package org.project.entity.enemies;
// TODO: UPDATE IMPLEMENTATION import org.project.item.weapons.Sword;
public class Skeleton {
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR 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; 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.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.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; protected Weapon weapon;
Armor armor; protected Armor armor;
private int hp;
private int maxHP; protected int hp;
private int mp; protected int maxHP;
private int maxMP; 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) { public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
this.name = name; this.name = name;
this.hp = hp; this.hp = hp;
this.maxHP = hp;
this.mp = mp; this.mp = mp;
this.maxMP = mp;
this.weapon = weapon; this.weapon = weapon;
this.armor = armor; this.armor = armor;
} }
@Override @Override
public void attack(Entity target) { 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 @Override
public void defend() { public void defend() {
// TODO int manaCost = 6;
if (mp < manaCost) {
System.out.println("❌ Not enough Mana/Stamina to Defend!");
return;
} }
mp -= manaCost;
isDefending = true;
@Override System.out.println("🛡️ " + name + " is Defending! (-" + manaCost + " Mana)");
public void takeDamage(int damage) {
hp -= damage - armor.getDefense();
} }
@Override @Override
public void heal(int health) { public void heal(int health) {
hp += health; hp += health;
if (hp > maxHP) { if (hp > maxHP) 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 @Override
public void fillMana(int mana) { public void fillMana(int mana) {
mp += mana; mp += mana;
if (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();
}
}
private void levelUp() {
level++;
xp -= xpToNextLevel;
xpToNextLevel = (int) (xpToNextLevel * 1.5);
maxHP += 20;
maxMP += 15;
hp = maxHP;
mp = maxMP; mp = maxMP;
} System.out.println("\u001B[32m🎉 LEVEL UP! Reached Level " + level + "! Max HP and Mana increased!\u001B[0m");
} }
public void restoreStats() {
public String getName() { hp = maxHP;
return name; mp = maxMP;
} isDefending = false;
isInvisible = false;
public int getHp() { nextAttackCritical = false;
return hp;
}
@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 { public interface Item {
void use(Entity target); void use(Entity target);
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
} }
@@ -1,17 +1,19 @@
package org.project.item.armors; package org.project.item.armors;
// TODO: UPDATE IMPLEMENTATION import org.project.item.Item;
public abstract class Armor {
private int defense;
private int maxDefense;
private int durability;
private int maxDurability;
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) { public Armor(int defense, int durability) {
this.defense = defense; this.defense = defense;
this.maxDefense = defense;
this.durability = durability; this.durability = durability;
this.maxDurability = durability;
} }
public void checkBreak() { public void checkBreak() {
@@ -21,22 +23,13 @@ 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;
} }
public int getDefense() { public int getDefense() { return defense; }
return defense; public int getDurability() { return durability; }
} public boolean isBroke() { return isBroke; }
public int getDurability() {
return durability;
}
public boolean isBroke() {
return isBroke;
}
} }
@@ -1,6 +1,14 @@
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(5, 100);
}
@Override
public void use(Entity target) {
System.out.println("Armor equipped.");
}
} }
@@ -1,8 +1,6 @@
package org.project.item.consumables; package org.project.item.consumables;
// TODO: UPDATE IMPLEMENTATION import org.project.item.Item;
public abstract class Consumable {
/* public abstract class Consumable implements Item {
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
} }
@@ -2,15 +2,10 @@ package org.project.item.consumables;
import org.project.entity.Entity; import org.project.entity.Entity;
// TODO: UPDATE IMPLEMENTATION public class Flask extends Consumable {
public class Flask {
/*
THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN.
*/
// TODO: UPDATE USE METHOD
@Override @Override
public void use(Entity target) { public void use(Entity target) {
target.heal(target.getMaxHP() / 10); target.heal(target.getMaxHP() / 2);
System.out.println("🧪 Flask restored HP!");
} }
} }
@@ -1,22 +1,16 @@
package org.project.item.weapons; package org.project.item.weapons;
import org.project.entity.Entity; import org.project.entity.Entity;
import java.util.ArrayList; import java.util.ArrayList;
// TODO: UPDATE IMPLEMENTATION public class Sword extends Weapon {
public class Sword { private int abilityCharge;
/*
THIS IS AN EXAMPLE OF A WEAPON DESIGN.
*/
int abilityCharge;
public Sword() { 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) { public void uniqueAbility(ArrayList<Entity> targets) {
abilityCharge += 2; abilityCharge += 2;
for (Entity target : targets) { for (Entity target : targets) {
@@ -1,15 +1,11 @@
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 { protected int damage;
private int damage; protected int manaCost;
private int manaCost;
/*
TODO: ADD OTHER REQUIRED AND BONUS ATTRIBUTES
*/
public Weapon(int damage, int manaCost) { public Weapon(int damage, int manaCost) {
this.damage = damage; this.damage = damage;
@@ -21,15 +17,6 @@ public abstract class Weapon {
target.takeDamage(damage); target.takeDamage(damage);
} }
public int getDamage() { public int getDamage() { return damage; }
return damage; public int getManaCost() { return manaCost; }
}
public int getManaCost() {
return manaCost;
}
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
} }
@@ -6,23 +6,16 @@ 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) {
this.locations = locations; this.name = name;
this.enemies = enemies; this.locations = new ArrayList<>();
this.enemies = new ArrayList<>();
} }
public String getName() { public String getName() { return name; }
return name; public ArrayList<Location> getLocations() { return locations; }
} public ArrayList<Enemy> getEnemies() { return enemies; }
public ArrayList<Location> getLocations() {
return locations;
}
public ArrayList<Enemy> getEnemies() {
return enemies;
}
} }
Binary file not shown.