diff --git a/Java-Knight/.idea/.gitignore b/Java-Knight/.idea/.gitignore new file mode 100644 index 0000000..ab1f416 --- /dev/null +++ b/Java-Knight/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/Java-Knight/.idea/compiler.xml b/Java-Knight/.idea/compiler.xml new file mode 100644 index 0000000..935cb4a --- /dev/null +++ b/Java-Knight/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/Java-Knight/.idea/encodings.xml b/Java-Knight/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/Java-Knight/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/Java-Knight/.idea/jarRepositories.xml b/Java-Knight/.idea/jarRepositories.xml new file mode 100644 index 0000000..4158879 --- /dev/null +++ b/Java-Knight/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Java-Knight/.idea/misc.xml b/Java-Knight/.idea/misc.xml new file mode 100644 index 0000000..eba6e1f --- /dev/null +++ b/Java-Knight/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/Java-Knight/.idea/vcs.xml b/Java-Knight/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Java-Knight/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Java-Knight/src/main/java/org/project/Main.java b/Java-Knight/src/main/java/org/project/Main.java index 6bde20e..4101900 100644 --- a/Java-Knight/src/main/java/org/project/Main.java +++ b/Java-Knight/src/main/java/org/project/Main.java @@ -4,12 +4,46 @@ import org.project.location.Location; import java.util.ArrayList; import java.util.List; +import org.project.entity.enemies.Enemy; +import org.project.utils.ConsoleColors; public class Main { public static void main(String[] args) { // TODO: ADD LOCATIONS TO YOUR GAME List locations = new ArrayList<>(); + Location village = new Location("Village", new ArrayList<>(), new ArrayList()); + Location forest = new Location("Forest", new ArrayList<>(), new ArrayList()); + Location cave = new Location("Cave", new ArrayList<>(), new ArrayList()); + Location dungeon = new Location("Dungeon", new ArrayList<>(), new ArrayList()); + Location castle = new Location("Castle", new ArrayList<>(), new ArrayList()); + // TODO: IMPLEMENT GAMEPLAY + //The movement paths between locations + village.getLocations().add(forest); + + forest.getLocations().add(village); + forest.getLocations().add(cave); + + cave.getLocations().add(forest); + cave.getLocations().add(dungeon); + + dungeon.getLocations().add(cave); + dungeon.getLocations().add(castle); + + castle.getLocations().add(dungeon); + + locations.add(village); + locations.add(forest); + locations.add(cave); + locations.add(dungeon); + locations.add(castle); + + //THe first location in the world map + Location currentLocation = locations.get(0); + System.out.println(ConsoleColors.BRIGHT_GREEN + "Welcome to the adventure!" + ConsoleColors.RESET); + System.out.println(ConsoleColors.BRIGHT_CYAN + "You are currently in: " + currentLocation.getName() + ConsoleColors.RESET); + System.out.println(ConsoleColors.BRIGHT_YELLOW + "The world is ready. Gameplay will continue from here." + ConsoleColors.RESET); + } } \ No newline at end of file diff --git a/Java-Knight/src/main/java/org/project/entity/Entity.java b/Java-Knight/src/main/java/org/project/entity/Entity.java index 2a060f9..419002a 100644 --- a/Java-Knight/src/main/java/org/project/entity/Entity.java +++ b/Java-Knight/src/main/java/org/project/entity/Entity.java @@ -18,4 +18,12 @@ public interface Entity { /* TODO: ADD OTHER REQUIRED AND BONUS METHODS */ + /* + Added common entity state accessors so all entities expose their current HP and MP. + This allows combat systems and game logic to interact with Player and Enemy + through the same polymorphic interface. + */ + int getHp(); + + int getMp(); } diff --git a/Java-Knight/src/main/java/org/project/entity/enemies/Dragon.java b/Java-Knight/src/main/java/org/project/entity/enemies/Dragon.java new file mode 100644 index 0000000..88a739d --- /dev/null +++ b/Java-Knight/src/main/java/org/project/entity/enemies/Dragon.java @@ -0,0 +1,38 @@ +package org.project.entity.enemies; +import org.project.entity.Entity; +import org.project.item.weapons.Weapon; +import java.util.Random; + +public class Dragon extends Enemy{ + // Reduces incoming damage by 10 points. + private final int armorDefense = 10; + private final Random random = new Random(); + + public Dragon(Weapon weapon) { + //Massive HP and MP pool to suit its Boss role. + super(350, 100, weapon); + } + + @Override + public void attack(Entity target) { + int baseDamage = weapon.getDamage(); + + //25% chance to perform "Fire Breath" which deals double damage + if (random.nextInt(100) < 25) { + System.out.println("Dragon uses Fire Breath!"); // Visual feedback for boss ability + target.takeDamage(baseDamage * 2); + } else { + target.takeDamage(baseDamage); + } + } + + @Override + public void takeDamage(int damage) { + // Minimum damage received is always 1 unless damage is 0. + int effectiveDamage = Math.max(1, damage - armorDefense); + + if (damage <= 0) effectiveDamage = 0; + + super.takeDamage(effectiveDamage); + } +} diff --git a/Java-Knight/src/main/java/org/project/entity/enemies/Enemy.java b/Java-Knight/src/main/java/org/project/entity/enemies/Enemy.java index e019acb..249672d 100644 --- a/Java-Knight/src/main/java/org/project/entity/enemies/Enemy.java +++ b/Java-Knight/src/main/java/org/project/entity/enemies/Enemy.java @@ -1,17 +1,21 @@ package org.project.entity.enemies; import org.project.item.weapons.Weapon; +import org.project.entity.Entity; // TODO: UPDATE IMPLEMENTATION -public abstract class Enemy { - Weapon weapon; - private int hp; - private int mp; +public abstract class Enemy implements Entity{ + protected Weapon weapon; + protected int hp; + protected int mp; + protected int maxHp; + protected int maxMp; public Enemy(int hp, int mp, Weapon weapon) { this.hp = hp; this.mp = mp; - + this.maxHp = hp; + this.maxMp = mp; this.weapon = weapon; } @@ -20,6 +24,18 @@ public abstract class Enemy { hp -= damage; } + @Override + public void attack(Entity target) { + // English comment: Default enemy attack uses weapon damage. + if (weapon != null) { + target.takeDamage(weapon.getDamage()); + } + } + + protected void setHp(int hp) { + this.hp = hp; + } + public int getHp() { return hp; } @@ -31,4 +47,31 @@ public abstract class Enemy { public Weapon getWeapon() { return weapon; } + @Override + public void defend() { + // English comment: Default enemy defense does nothing special. + } + + @Override + public void heal(int health) { + // English comment: Clamp HP so it never exceeds maximum HP. + hp = Math.min(maxHp, hp + health); + } + + @Override + public void fillMana(int mana) { + // English comment: Clamp MP so it never exceeds maximum MP. + mp = Math.min(maxMp, mp + mana); + } + + @Override + public int getMaxHP() { + return maxHp; + } + + @Override + public int getMaxMP() { + return maxMp; + } + } diff --git a/Java-Knight/src/main/java/org/project/entity/enemies/Goblin.java b/Java-Knight/src/main/java/org/project/entity/enemies/Goblin.java new file mode 100644 index 0000000..15330a9 --- /dev/null +++ b/Java-Knight/src/main/java/org/project/entity/enemies/Goblin.java @@ -0,0 +1,27 @@ +package org.project.entity.enemies; +import org.project.entity.Entity; +import org.project.item.weapons.Weapon; +import java.util.Random; + + +public class Goblin extends Enemy { + private final Random random = new Random(); + + public Goblin(Weapon weapon) { + //Lower health but higher burst damage potential + super(50, 15, weapon); + } + + @Override + public void attack(Entity target) { + + int damage = weapon.getDamage(); + + //Has a 35% chance to deal double damage. + if (random.nextInt(100) < 35) { + damage *= 2; + } + + target.takeDamage(damage); + } +} diff --git a/Java-Knight/src/main/java/org/project/entity/enemies/Skeleton.java b/Java-Knight/src/main/java/org/project/entity/enemies/Skeleton.java index 8a6a555..6b2a49d 100644 --- a/Java-Knight/src/main/java/org/project/entity/enemies/Skeleton.java +++ b/Java-Knight/src/main/java/org/project/entity/enemies/Skeleton.java @@ -1,6 +1,25 @@ package org.project.entity.enemies; +import org.project.item.weapons.Weapon; // TODO: UPDATE IMPLEMENTATION -public class Skeleton { +public class Skeleton extends Enemy{ // TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR + private boolean resurrected = false; + + public Skeleton(Weapon weapon) { + //A low-tier enemy with moderate HP and low mana. + super(80, 20, weapon); + } + + @Override + public void takeDamage(int damage) { + //Apply damage + super.takeDamage(damage); + + //If dies for the first time, resurrect with 50% HP. + if (hp <= 0 && !resurrected) { + resurrected = true; + hp = maxHp / 2; + } + } } diff --git a/Java-Knight/src/main/java/org/project/entity/enemies/Vampire.java b/Java-Knight/src/main/java/org/project/entity/enemies/Vampire.java new file mode 100644 index 0000000..0b036c6 --- /dev/null +++ b/Java-Knight/src/main/java/org/project/entity/enemies/Vampire.java @@ -0,0 +1,26 @@ +package org.project.entity.enemies; +import org.project.entity.Entity; +import org.project.item.weapons.Weapon; + +public class Vampire extends Enemy { + public Vampire(Weapon weapon) { + //Has balanced stats with sustain ability. + super(90, 30, weapon); + } + + @Override + public void attack(Entity target) { + + int damage = weapon.getDamage(); + + target.takeDamage(damage); + + //Heals for 50% of the damage dealt. + this.hp += damage / 2; + + //Ensure HP does not exceed maximum. + if (this.hp > this.maxHp) { + this.hp = this.maxHp; + } + } +} diff --git a/Java-Knight/src/main/java/org/project/entity/players/Assassin.java b/Java-Knight/src/main/java/org/project/entity/players/Assassin.java new file mode 100644 index 0000000..08f55ea --- /dev/null +++ b/Java-Knight/src/main/java/org/project/entity/players/Assassin.java @@ -0,0 +1,11 @@ +package org.project.entity.players; +import org.project.item.armors.AssassinLeatherArmor; +import org.project.item.weapons.Dagger; + +public class Assassin extends Player{ + //The highest max mana/stamina + public Assassin(String name) { + //The highest max mana/stamina and agile equipment. + super(name, 100, 100, new Dagger(), new AssassinLeatherArmor()); + } +} diff --git a/Java-Knight/src/main/java/org/project/entity/players/Knight.java b/Java-Knight/src/main/java/org/project/entity/players/Knight.java index 14d8fa2..a95f1bc 100644 --- a/Java-Knight/src/main/java/org/project/entity/players/Knight.java +++ b/Java-Knight/src/main/java/org/project/entity/players/Knight.java @@ -1,6 +1,14 @@ package org.project.entity.players; +import org.project.item.armors.KnightArmor; +import org.project.item.weapons.Sword; // TODO: UPDATE IMPLEMENTATION -public class Knight { +public class Knight extends Player{ // TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR + // Knight-specific constructor with higher damage-oriented equipment. + public Knight(String name) { + // Base stats are selected according to README priorities: + // Knight should have the strongest base damage and solid survivability. + super(name, 120, 30, new Sword(), new KnightArmor()); + } } diff --git a/Java-Knight/src/main/java/org/project/entity/players/Player.java b/Java-Knight/src/main/java/org/project/entity/players/Player.java index ff5385c..0a70974 100644 --- a/Java-Knight/src/main/java/org/project/entity/players/Player.java +++ b/Java-Knight/src/main/java/org/project/entity/players/Player.java @@ -5,7 +5,7 @@ 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; @@ -18,6 +18,8 @@ public abstract class Player { this.name = name; this.hp = hp; this.mp = mp; + this.maxHP = hp; + this.maxMP = mp; this.weapon = weapon; this.armor = armor; @@ -31,6 +33,10 @@ public abstract class Player { @Override public void defend() { // TODO + // If armor is broken, defend action repairs it + if (armor != null && armor.getIsBrocke()) { + armor.repair(); + } } diff --git a/Java-Knight/src/main/java/org/project/entity/players/Wizard.java b/Java-Knight/src/main/java/org/project/entity/players/Wizard.java new file mode 100644 index 0000000..7813a38 --- /dev/null +++ b/Java-Knight/src/main/java/org/project/entity/players/Wizard.java @@ -0,0 +1,11 @@ +package org.project.entity.players; +import org.project.item.armors.WizardRobe; +import org.project.item.weapons.Staff; + +public class Wizard extends Player { + // Wizard is the class with the highest max HP according to the README. + public Wizard(String name) { + //The highest max HP and enough mana for spell usage. + super(name, 150, 80, new Staff(), new WizardRobe()); + } +} diff --git a/Java-Knight/src/main/java/org/project/item/Item.java b/Java-Knight/src/main/java/org/project/item/Item.java index 6d6b5ad..87f68e7 100644 --- a/Java-Knight/src/main/java/org/project/item/Item.java +++ b/Java-Knight/src/main/java/org/project/item/Item.java @@ -8,4 +8,14 @@ public interface Item { /* TODO: ADD OTHER REQUIRED AND BONUS METHODS */ + /* + Added shared item inspection and identification methods. + These methods allow unified access to item information in inventories and UI, + keeping all items (Weapon, Armor, Consumable) consistent under the same contract. + */ + String getName(); // Returns the name of the item. + + String getDescription(); // Returns a brief description of the item. + + int getValue(); // Represents shop or trade value of item. } diff --git a/Java-Knight/src/main/java/org/project/item/armors/Armor.java b/Java-Knight/src/main/java/org/project/item/armors/Armor.java index 7ca8774..af8ee4e 100644 --- a/Java-Knight/src/main/java/org/project/item/armors/Armor.java +++ b/Java-Knight/src/main/java/org/project/item/armors/Armor.java @@ -1,7 +1,9 @@ package org.project.item.armors; +import org.project.item.Item; + // TODO: UPDATE IMPLEMENTATION -public abstract class Armor { +public abstract class Armor implements Item { private int defense; private int maxDefense; private int durability; @@ -16,27 +18,47 @@ public abstract class Armor { public void checkBreak() { if (durability <= 0) { - isBroke = true; defense = 0; + isBroke = true; } } // TODO: (BONUS) UPDATE THE REPAIR METHOD + /* + Repair weapon durability. + */ public void repair() { - isBroke = false; - defense = maxDefense; durability = maxDurability; } - public int getDefense() { - return defense; - } + /* + Inspection methods required by Item interface. + These are left abstract so each concrete weapon + can define its own identity and value. + */ + @Override + public abstract String getName(); + @Override + public abstract String getDescription(); + + @Override + public abstract int getValue(); + + /* + BONUS: durability getters. + */ public int getDurability() { return durability; } - public boolean isBroke() { + public int getMaxDurability() { + return maxDurability; + } + public int getDefense(){ + return defense; + } + public boolean getIsBrocke(){ return isBroke; } } diff --git a/Java-Knight/src/main/java/org/project/item/armors/AssassinLeatherArmor.java b/Java-Knight/src/main/java/org/project/item/armors/AssassinLeatherArmor.java new file mode 100644 index 0000000..be2eaaa --- /dev/null +++ b/Java-Knight/src/main/java/org/project/item/armors/AssassinLeatherArmor.java @@ -0,0 +1,31 @@ +package org.project.item.armors; +import org.project.entity.Entity; + +public class AssassinLeatherArmor extends Armor { + //offering medium protection (2/3 of Knight) + public AssassinLeatherArmor() { + super(8, 60); + } + + // Added item identity methods required by the Item contract. + @Override + public String getName() { + return "Assassin Leather Armor"; + } + + @Override + public String getDescription() { + return "Reinforced leather armor providing a balance between protection and speed."; + } + + @Override + public int getValue() { + return 100; + } + + @Override + public void use(Entity target) { + + } + +} diff --git a/Java-Knight/src/main/java/org/project/item/armors/KnightArmor.java b/Java-Knight/src/main/java/org/project/item/armors/KnightArmor.java index eb59a46..7e08a49 100644 --- a/Java-Knight/src/main/java/org/project/item/armors/KnightArmor.java +++ b/Java-Knight/src/main/java/org/project/item/armors/KnightArmor.java @@ -1,6 +1,33 @@ package org.project.item.armors; +import org.project.entity.Entity; // TODO: UPDATE IMPLEMENTATION -public class KnightArmor { +public class KnightArmor extends Armor { // TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR + // Added default knight armor stats for the combat and durability systems. + public KnightArmor() { + + super(12, 120); + } + + // Added item identity methods required by the Item contract. + @Override + public String getName() { + return "Knight Armor"; + } + + @Override + public String getDescription() { + return "Heavy armor designed for frontline combat and high durability."; + } + + @Override + public int getValue() { + return 140; + } + + @Override + public void use(Entity target) { + + } } \ No newline at end of file diff --git a/Java-Knight/src/main/java/org/project/item/armors/WizardRobe.java b/Java-Knight/src/main/java/org/project/item/armors/WizardRobe.java new file mode 100644 index 0000000..b3ef34d --- /dev/null +++ b/Java-Knight/src/main/java/org/project/item/armors/WizardRobe.java @@ -0,0 +1,30 @@ +package org.project.item.armors; +import org.project.entity.Entity; + +public class WizardRobe extends Armor{ + public WizardRobe() { + // Lower defense but reasonable durability for magic users. + super(4, 80); + } + + // Added item identity methods required by the Item contract. + @Override + public String getName() { + return "Wizard Robe"; + } + + @Override + public String getDescription() { + return "Light magical robe providing minimal protection but high mobility for casters."; + } + + @Override + public int getValue() { + return 60; + } + + @Override + public void use(Entity target) { + + } +} diff --git a/Java-Knight/src/main/java/org/project/item/consumables/Consumable.java b/Java-Knight/src/main/java/org/project/item/consumables/Consumable.java index 028e13d..49abf3e 100644 --- a/Java-Knight/src/main/java/org/project/item/consumables/Consumable.java +++ b/Java-Knight/src/main/java/org/project/item/consumables/Consumable.java @@ -1,8 +1,35 @@ package org.project.item.consumables; +import org.project.entity.Entity; +import org.project.item.Item; // TODO: UPDATE IMPLEMENTATION -public abstract class Consumable { +public abstract class Consumable implements Item { /* TODO: ADD OTHER REQUIRED AND BONUS METHODS */ + // Base economic value for all consumables + protected int value; + + //To initialize consumable value + public Consumable(int value) { + this.value = value; + } + + // Shared implementation of getValue for all consumables + @Override + public int getValue() { + return value; + } + + /* + * Abstract methods force subclasses to define their own identity and behavior. + */ + @Override + public abstract String getName(); + + @Override + public abstract String getDescription(); + + @Override + public abstract void use(Entity target); } diff --git a/Java-Knight/src/main/java/org/project/item/consumables/Flask.java b/Java-Knight/src/main/java/org/project/item/consumables/Flask.java index c0e7a6d..dbec402 100644 --- a/Java-Knight/src/main/java/org/project/item/consumables/Flask.java +++ b/Java-Knight/src/main/java/org/project/item/consumables/Flask.java @@ -3,14 +3,30 @@ package org.project.item.consumables; import org.project.entity.Entity; // TODO: UPDATE IMPLEMENTATION -public class Flask { +public class Flask extends Consumable{ /* THIS IS AN EXAMPLE OF A CONSUMABLE DESIGN. */ + public Flask() { + super(50); + } // TODO: UPDATE USE METHOD @Override public void use(Entity target) { target.heal(target.getMaxHP() / 10); } + + // Defines the display name + @Override + public String getName() { + return "Healing Flask"; + } + + //The effect of the flask + @Override + public String getDescription() { + return "A small flask that restores a portion of the user's health."; + } + } diff --git a/Java-Knight/src/main/java/org/project/item/weapons/Dagger.java b/Java-Knight/src/main/java/org/project/item/weapons/Dagger.java new file mode 100644 index 0000000..6bed635 --- /dev/null +++ b/Java-Knight/src/main/java/org/project/item/weapons/Dagger.java @@ -0,0 +1,36 @@ +package org.project.item.weapons; +import org.project.entity.Entity; + +public class Dagger extends Weapon{ + private double criticalChance; + + public Dagger() { + // Dagger is meant to be quick and efficient, not the highest raw damage weapon. + super(12, 2); + this.criticalChance = 0.30; + } + + // Critical damage supports a high-risk, high-reward playstyle. + public void criticalStrike(Entity target) { + if (Math.random() < criticalChance) { + target.takeDamage(getDamage() * 2); + } else { + target.takeDamage(getDamage()); + } + } + + @Override + public String getName() { + return "Dagger"; + } + + @Override + public String getDescription() { + return "A light and deadly blade designed for quick strikes and critical hits."; + } + + @Override + public int getValue() { + return 90; + } +} diff --git a/Java-Knight/src/main/java/org/project/item/weapons/Staff.java b/Java-Knight/src/main/java/org/project/item/weapons/Staff.java new file mode 100644 index 0000000..e554a46 --- /dev/null +++ b/Java-Knight/src/main/java/org/project/item/weapons/Staff.java @@ -0,0 +1,40 @@ +package org.project.item.weapons; +import org.project.entity.Entity; +import java.util.ArrayList; + +public class Staff extends Weapon{ + private int spellCharge; + + public Staff() { + // Staff is designed around magic damage and higher mana dependency. + super(10, 8); + this.spellCharge = 0; + } + + // This ability is intended to be stronger than a normal attack and to consume buildup. + public void magicBurst(ArrayList targets) { + spellCharge++; + + if (spellCharge >= 2) { + for (Entity target : targets) { + target.takeDamage(getDamage() + 6); + } + spellCharge = 0; + } + } + + @Override + public String getName() { + return "Staff"; + } + + @Override + public String getDescription() { + return "A rune-carved staff that channels arcane energy for powerful spells."; + } + + @Override + public int getValue() { + return 120; + } +} diff --git a/Java-Knight/src/main/java/org/project/item/weapons/Sword.java b/Java-Knight/src/main/java/org/project/item/weapons/Sword.java index 96226ee..3cb124e 100644 --- a/Java-Knight/src/main/java/org/project/item/weapons/Sword.java +++ b/Java-Knight/src/main/java/org/project/item/weapons/Sword.java @@ -5,7 +5,7 @@ import org.project.entity.Entity; import java.util.ArrayList; // TODO: UPDATE IMPLEMENTATION -public class Sword { +public class Sword extends Weapon { /* THIS IS AN EXAMPLE OF A WEAPON DESIGN. */ @@ -14,13 +14,35 @@ public class Sword { public Sword() { // TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR + // Added default sword stats based on the combat system requirements. + super(15, 5); + + // Initialize ability charge for gameplay progression. + this.abilityCharge = 0; } // TODO: (BONUS) UPDATE THE UNIQUE ABILITY + // Added a sword-specific multi-target attack ability. + // The ability gains charge after each use and damages all enemies in range. public void uniqueAbility(ArrayList targets) { - abilityCharge += 2; + abilityCharge++; for (Entity target : targets) { target.takeDamage(getDamage()); } } + // Added item identity methods required by the Item contract. + @Override + public String getName() { + return "Sword"; + } + + @Override + public String getDescription() { + return "A balanced melee weapon used by knights."; + } + + @Override + public int getValue() { + return 100; + } } diff --git a/Java-Knight/src/main/java/org/project/item/weapons/Weapon.java b/Java-Knight/src/main/java/org/project/item/weapons/Weapon.java index cb9fcf2..661f95c 100644 --- a/Java-Knight/src/main/java/org/project/item/weapons/Weapon.java +++ b/Java-Knight/src/main/java/org/project/item/weapons/Weapon.java @@ -1,15 +1,29 @@ package org.project.item.weapons; import org.project.entity.Entity; +import org.project.item.Item; // TODO: UPDATE IMPLEMENTATION -public abstract class Weapon { +public abstract class Weapon implements Item { private int damage; private int manaCost; /* TODO: ADD OTHER REQUIRED AND BONUS ATTRIBUTES */ + /* + Added shared item attributes for inspection and inventory usage. + Subclasses will define the concrete values (name, description, value). + */ + private String name; + private String description; + private int value; + + /* + Added durability system so weapons can degrade through combat usage. + */ + private int durability = 100; + private int maxDurability = 100; public Weapon(int damage, int manaCost) { this.damage = damage; @@ -19,6 +33,7 @@ public abstract class Weapon { @Override public void use(Entity target) { target.takeDamage(damage); + reduceDurability(); } public int getDamage() { @@ -28,8 +43,52 @@ public abstract class Weapon { public int getManaCost() { return manaCost; } + /* + Reduces durability whenever the weapon is used. + */ + private void reduceDurability() { + durability--; + if (durability < 0) { + durability = 0; + } + } /* TODO: ADD OTHER REQUIRED AND BONUS METHODS */ + /* + Repair weapon durability. + */ + public void repair() { + durability = maxDurability; + } + + /* + Implemented inspection methods required by Item interface. + */ + @Override + public String getName() { + return name; + } + + @Override + public String getDescription() { + return description; + } + + @Override + public int getValue() { + return value; + } + + /* + Durability getters. + */ + public int getDurability() { + return durability; + } + + public int getMaxDurability() { + return maxDurability; + } } diff --git a/Java-Knight/src/main/java/org/project/location/Location.java b/Java-Knight/src/main/java/org/project/location/Location.java index b0b4b98..23162cf 100644 --- a/Java-Knight/src/main/java/org/project/location/Location.java +++ b/Java-Knight/src/main/java/org/project/location/Location.java @@ -6,10 +6,11 @@ import java.util.ArrayList; public class Location { private String name; - + private ArrayList locations; private ArrayList enemies; - public Location(ArrayList locations, ArrayList enemies) { + public Location(String name, ArrayList locations, ArrayList enemies) { + this.name = name; this.locations = locations; this.enemies = enemies; } @@ -25,4 +26,44 @@ public class Location { public ArrayList getEnemies() { return enemies; } + + /** + *This method initializes the game world by creating locations + * and establishing their connections. + * @return The starting location. + */ + public static Location generateMap() { + // Create individual locations + Location village = new Location("Village", new ArrayList<>(), new ArrayList<>()); + Location forest = new Location("Forest", new ArrayList<>(), new ArrayList<>()); + Location cave = new Location("Cave", new ArrayList<>(), new ArrayList<>()); + Location dungeon = new Location("Dungeon", new ArrayList<>(), new ArrayList<>()); + Location castle = new Location("Castle", new ArrayList<>(), new ArrayList<>()); + + // Establishing connections between locations + // Village <-> Forest + village.addConnection(forest); + forest.addConnection(village); + + // Forest <-> Cave + forest.addConnection(cave); + cave.addConnection(forest); + + // Cave <-> Dungeon + cave.addConnection(dungeon); + dungeon.addConnection(cave); + + // Dungeon <-> Castle + dungeon.addConnection(castle); + castle.addConnection(dungeon); + + return village; // Start of the journey + } + + //Helper method to add a connection to avoid direct list manipulation from outside. + public void addConnection(Location location) { + if (!this.locations.contains(location)) { + this.locations.add(location); + } + } } diff --git a/Java-Knight/src/main/java/org/project/utils/ConsoleColors.java b/Java-Knight/src/main/java/org/project/utils/ConsoleColors.java new file mode 100644 index 0000000..374804b --- /dev/null +++ b/Java-Knight/src/main/java/org/project/utils/ConsoleColors.java @@ -0,0 +1,23 @@ +package org.project.utils; + +public class ConsoleColors { + public static final String RESET = "\u001B[0m"; + + public static final String BLACK = "\u001B[30m"; + public static final String RED = "\u001B[31m"; + public static final String GREEN = "\u001B[32m"; + public static final String YELLOW = "\u001B[33m"; + public static final String BLUE = "\u001B[34m"; + public static final String PURPLE = "\u001B[35m"; + public static final String CYAN = "\u001B[36m"; + public static final String WHITE = "\u001B[37m"; + + // Bold or bright variants + public static final String BRIGHT_RED = "\u001B[91m"; + public static final String BRIGHT_GREEN = "\u001B[92m"; + public static final String BRIGHT_YELLOW = "\u001B[93m"; + public static final String BRIGHT_BLUE = "\u001B[94m"; + public static final String BRIGHT_PURPLE = "\u001B[95m"; + public static final String BRIGHT_CYAN = "\u001B[96m"; + public static final String BRIGHT_WHITE = "\u001B[97m"; +} diff --git a/Java-Knight/target/classes/org/project/Main.class b/Java-Knight/target/classes/org/project/Main.class new file mode 100644 index 0000000..45c41fa Binary files /dev/null and b/Java-Knight/target/classes/org/project/Main.class differ diff --git a/Java-Knight/target/classes/org/project/entity/Entity.class b/Java-Knight/target/classes/org/project/entity/Entity.class new file mode 100644 index 0000000..4f6b1a5 Binary files /dev/null and b/Java-Knight/target/classes/org/project/entity/Entity.class differ diff --git a/Java-Knight/target/classes/org/project/entity/enemies/Dragon.class b/Java-Knight/target/classes/org/project/entity/enemies/Dragon.class new file mode 100644 index 0000000..de52d9a Binary files /dev/null and b/Java-Knight/target/classes/org/project/entity/enemies/Dragon.class differ diff --git a/Java-Knight/target/classes/org/project/entity/enemies/Enemy.class b/Java-Knight/target/classes/org/project/entity/enemies/Enemy.class new file mode 100644 index 0000000..2c232fa Binary files /dev/null and b/Java-Knight/target/classes/org/project/entity/enemies/Enemy.class differ diff --git a/Java-Knight/target/classes/org/project/entity/enemies/Goblin.class b/Java-Knight/target/classes/org/project/entity/enemies/Goblin.class new file mode 100644 index 0000000..a0ab880 Binary files /dev/null and b/Java-Knight/target/classes/org/project/entity/enemies/Goblin.class differ diff --git a/Java-Knight/target/classes/org/project/entity/enemies/Skeleton.class b/Java-Knight/target/classes/org/project/entity/enemies/Skeleton.class new file mode 100644 index 0000000..7024043 Binary files /dev/null and b/Java-Knight/target/classes/org/project/entity/enemies/Skeleton.class differ diff --git a/Java-Knight/target/classes/org/project/entity/enemies/Vampire.class b/Java-Knight/target/classes/org/project/entity/enemies/Vampire.class new file mode 100644 index 0000000..93c23dd Binary files /dev/null and b/Java-Knight/target/classes/org/project/entity/enemies/Vampire.class differ diff --git a/Java-Knight/target/classes/org/project/entity/players/Assassin.class b/Java-Knight/target/classes/org/project/entity/players/Assassin.class new file mode 100644 index 0000000..19a379b Binary files /dev/null and b/Java-Knight/target/classes/org/project/entity/players/Assassin.class differ diff --git a/Java-Knight/target/classes/org/project/entity/players/Knight.class b/Java-Knight/target/classes/org/project/entity/players/Knight.class new file mode 100644 index 0000000..3d67b9a Binary files /dev/null and b/Java-Knight/target/classes/org/project/entity/players/Knight.class differ diff --git a/Java-Knight/target/classes/org/project/entity/players/Player.class b/Java-Knight/target/classes/org/project/entity/players/Player.class new file mode 100644 index 0000000..37bde65 Binary files /dev/null and b/Java-Knight/target/classes/org/project/entity/players/Player.class differ diff --git a/Java-Knight/target/classes/org/project/entity/players/Wizard.class b/Java-Knight/target/classes/org/project/entity/players/Wizard.class new file mode 100644 index 0000000..cf05abb Binary files /dev/null and b/Java-Knight/target/classes/org/project/entity/players/Wizard.class differ diff --git a/Java-Knight/target/classes/org/project/item/Item.class b/Java-Knight/target/classes/org/project/item/Item.class new file mode 100644 index 0000000..f4b4c63 Binary files /dev/null and b/Java-Knight/target/classes/org/project/item/Item.class differ diff --git a/Java-Knight/target/classes/org/project/item/armors/Armor.class b/Java-Knight/target/classes/org/project/item/armors/Armor.class new file mode 100644 index 0000000..40e8138 Binary files /dev/null and b/Java-Knight/target/classes/org/project/item/armors/Armor.class differ diff --git a/Java-Knight/target/classes/org/project/item/armors/AssassinLeatherArmor.class b/Java-Knight/target/classes/org/project/item/armors/AssassinLeatherArmor.class new file mode 100644 index 0000000..11c455a Binary files /dev/null and b/Java-Knight/target/classes/org/project/item/armors/AssassinLeatherArmor.class differ diff --git a/Java-Knight/target/classes/org/project/item/armors/KnightArmor.class b/Java-Knight/target/classes/org/project/item/armors/KnightArmor.class new file mode 100644 index 0000000..2a570fd Binary files /dev/null and b/Java-Knight/target/classes/org/project/item/armors/KnightArmor.class differ diff --git a/Java-Knight/target/classes/org/project/item/armors/WizardRobe.class b/Java-Knight/target/classes/org/project/item/armors/WizardRobe.class new file mode 100644 index 0000000..27fe2da Binary files /dev/null and b/Java-Knight/target/classes/org/project/item/armors/WizardRobe.class differ diff --git a/Java-Knight/target/classes/org/project/item/consumables/Consumable.class b/Java-Knight/target/classes/org/project/item/consumables/Consumable.class new file mode 100644 index 0000000..544034a Binary files /dev/null and b/Java-Knight/target/classes/org/project/item/consumables/Consumable.class differ diff --git a/Java-Knight/target/classes/org/project/item/consumables/Flask.class b/Java-Knight/target/classes/org/project/item/consumables/Flask.class new file mode 100644 index 0000000..810a535 Binary files /dev/null and b/Java-Knight/target/classes/org/project/item/consumables/Flask.class differ diff --git a/Java-Knight/target/classes/org/project/item/weapons/Dagger.class b/Java-Knight/target/classes/org/project/item/weapons/Dagger.class new file mode 100644 index 0000000..9ba58db Binary files /dev/null and b/Java-Knight/target/classes/org/project/item/weapons/Dagger.class differ diff --git a/Java-Knight/target/classes/org/project/item/weapons/Staff.class b/Java-Knight/target/classes/org/project/item/weapons/Staff.class new file mode 100644 index 0000000..c340e93 Binary files /dev/null and b/Java-Knight/target/classes/org/project/item/weapons/Staff.class differ diff --git a/Java-Knight/target/classes/org/project/item/weapons/Sword.class b/Java-Knight/target/classes/org/project/item/weapons/Sword.class new file mode 100644 index 0000000..3442bc5 Binary files /dev/null and b/Java-Knight/target/classes/org/project/item/weapons/Sword.class differ diff --git a/Java-Knight/target/classes/org/project/item/weapons/Weapon.class b/Java-Knight/target/classes/org/project/item/weapons/Weapon.class new file mode 100644 index 0000000..b3795a3 Binary files /dev/null and b/Java-Knight/target/classes/org/project/item/weapons/Weapon.class differ diff --git a/Java-Knight/target/classes/org/project/location/Location.class b/Java-Knight/target/classes/org/project/location/Location.class new file mode 100644 index 0000000..e773098 Binary files /dev/null and b/Java-Knight/target/classes/org/project/location/Location.class differ diff --git a/Java-Knight/target/classes/org/project/utils/ConsoleColors.class b/Java-Knight/target/classes/org/project/utils/ConsoleColors.class new file mode 100644 index 0000000..8750cc4 Binary files /dev/null and b/Java-Knight/target/classes/org/project/utils/ConsoleColors.class differ diff --git a/NewReadMe.md b/NewReadMe.md new file mode 100644 index 0000000..77c1d39 --- /dev/null +++ b/NewReadMe.md @@ -0,0 +1,248 @@ +:::writing + +# Javanest Adventure + +## Overview + +**Javanest Adventure** is a turn‑based console RPG written in Java. +The player explores different locations, fights monsters, collects keys, and eventually unlocks the castle to confront the final enemy. + +The game is inspired by classic text‑based RPGs and demonstrates core **object‑oriented programming (OOP)** concepts such as inheritance, abstraction, interfaces, and polymorphism. + +--- + +# Story + +The peaceful land of **Javanest** has fallen under a terrible curse. + +A powerful **Dragon** has taken control of the kingdom and unleashed monsters across the land. Villages are abandoned, forests are haunted, and caves are filled with undead creatures. + +The dragon locked itself inside the **Castle**, and the only way to enter is by collecting **three hidden keys** scattered among the monsters. + +Your mission is simple: + +- Explore the world +- Defeat monsters +- Collect the keys +- Enter the castle +- Defeat the dragon and free Javanest + +--- + +# Game Features + +## Turn-Based Combat + +Combat is **turn-based**. +Each round consists of: + +1. Player turn +2. Enemy turn + +The battle continues until either the player or the enemy dies. + +--- + +## Player Actions + +During each turn the player can choose one of the following actions: + +1. **Attack** – perform a normal attack with the equipped weapon +2. **Use Skill** – perform a stronger ability depending on the player class +3. **Use Item** – consume a healing or utility item +4. **Defend** – reduce incoming damage +5. **Run** – attempt to escape the battle + +--- + +## Exploration + +The world contains several locations: + +- Village (starting area) +- Forest +- Cave +- Dungeon +- Castle (final area) + +Players can move between connected locations and may encounter enemies in dangerous areas. + +--- + +## Keys and Progression + +The **Castle is locked**. + +To unlock it the player must collect **3 keys**. + +Keys are obtained by **defeating enemies**. + +Once all keys are collected, the player can enter the **Castle** and fight the final boss. + +--- + +# Enemies + +Enemies are represented by the abstract class `Enemy`. + +Possible enemy types include: + +- Skeleton +- Goblin +- Vampire +- Dragon (final boss) + +Each enemy has different stats such as: + +- Health +- Attack power +- Defense + +--- + +# Player Classes + +The player is represented by the abstract class `Player`, which implements the `Entity` interface. + +Possible subclasses include: + +- **Knight** – high defense and balanced attack +- **Wizard** – strong magic attacks and mana usage +- **Assassin** – fast and high critical damage + +Each class has different abilities and combat strategies. + +--- + +# Items + +Items help the player survive and improve combat performance. + +Types of items include: + +- **Weapon** – increases attack damage +- **Armor** – increases defense +- **Consumable** – restores health or provides temporary effects + +--- + +# Project Structure + +Example structure of the project: + +``` +src/ + ├── Main.java + ├── Entity.java + ├── Player.java + ├── Enemy.java + ├── Location.java + │ + ├── players/ + │ ├── Knight.java + │ ├── Wizard.java + │ └── Assassin.java + │ + ├── enemies/ + │ ├── Skeleton.java + │ ├── Goblin.java + │ ├── Vampire.java + │ └── Dragon.java + │ + ├── items/ + │ ├── Item.java + │ ├── Weapon.java + │ ├── Armor.java + │ └── Consumable.java + │ + └── utils/ + └── ConsoleColors.java +``` + +--- + +# Console Colors + +The game uses ANSI colors to improve readability. + +| Color | Usage | +| ------ | ------------------- | +| Red | Damage messages | +| Blue | Mana or defense | +| Green | Healing and success | +| Yellow | Warnings and keys | +| Cyan | UI information | + +Example: + +``` +System.out.println(ConsoleColors.RED + "You took 10 damage!" + ConsoleColors.RESET); +``` + +--- + +# How to Run the Game + +### Compile + +``` +javac *.java +``` + +### Run + +``` +java Main +``` + +The game will start in the **Village** and the player can begin exploring. + +--- + +# Gameplay Loop + +Typical gameplay flow: + +1. Player starts in Village +2. Moves to a new location +3. Random enemy appears +4. Combat begins +5. Enemy defeated → possible key drop +6. Repeat exploration +7. Collect 3 keys +8. Enter Castle +9. Fight the Dragon +10. Win the game + +--- + +# OOP Concepts Used + +This project demonstrates several core Java concepts: + +- **Abstraction** +- **Inheritance** +- **Interfaces** +- **Polymorphism** +- **Encapsulation** + +--- + +# Future Improvements + +Possible future features: + +- Inventory system +- Equipment upgrades +- Experience and leveling +- More enemy types +- More locations +- Boss mechanics +- Save/load system + +--- + +# Author + +Developed as a Java OOP project for practicing game architecture and object‑oriented design. +::: diff --git a/structure.txt b/structure.txt new file mode 100644 index 0000000..a3a05e5 Binary files /dev/null and b/structure.txt differ