# ⚔️ Java Knight: A Turn-Based RPG --- ## 📖 Introduction **Java Knight** is a terminal-based, turn-based role-playing game (RPG) developed in Java as a university assignment. The game incorporates Roguelike elements where the player must collect three unique keys by defeating cursed creatures to unlock the final boss fight against a Dragon. --- ## 🏹 Storyline 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 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 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! --- ## 🎮 How to Play ### Controls During the game, you will be presented with menus and prompts. Use the number keys (1-5) to select options. | Key | Action | |-----|-----------------------------| | 1 | Light Attack (0 Mana) | | 2 | Heavy Attack (-8 Mana) | | 3 | Defend (-6 Mana) | | 4 | Heal (-12 Mana) | | 5 | Special Ability (-15 Mana) | ### Game Flow 1. **Choose your warrior:** Knight, Wizard, or Assassin? 2. **Enter a location:** A random enemy (Goblin, Skeleton, or Vampire) spawns. 3. **Choose an action:** Fight, move to another location, or (later) go to the Castle! 4. **Turn-based combat:** Alternate attacks will be between you and the enemy! 5. **Recovery:** After each victory, your HP and Mana are fully restored! 6. **Key Collection:** Each defeated enemy has a 20% chance to drop their unique key! 7. **Level Up:** Defeating enemies grants experience; reaching thresholds increases your max HP and Mana! 8. **Final Boss:** After collecting all 3 keys, you can enter the Castle to fight the Dragon! ### Character Classes | Class | HP |Mana| Special Ability | |---------------|-----|----|------------------------------------------------------------------| | Knight ⚔️ | 45 | 45 | Shield Bash – Deals heavy damage + stuns enemy | | Wizard 🧙‍♂️ | 60 | 45 | Devastating Spell – Deals massive damage + heals self | | Assassin 🗡️ | 45 | 60 | Invisibility – Next attack is critical, dodges next enemy attack | ### Enemies |Enemy|HP| Damage | Special Ability | |-----|--|--------|---------------------------------------------------| |Goblin 👹| 30 | 10 | 40% critical hit chance | |Skeleton ☠️ | 45 | 10 | Resurrects once with 50% HP | |Vampire 🦇 | 55 | 12 | Lifesteal (40% of damage heals itself) | |Dragon (Boss) 🐉 | 150 | 25 | Immune to defense, fiery breath bypasses shields | --- ## Prerequisites Java Development Kit (JDK) 17 or higher - **Git** (optional, for cloning) ### Step 1: Clone the Repository ```bash git clone https://git.meshcomp.ir/AdvancedProgramming1404/HW-04-JAVA-KNIGHT.git cd HW-04-JAVA-KNIGHT ``` ### Step 2: Compile the Project Navigate to the project root directory (where the src folder is located) and run: ```bash javac -d out src/org/project/*.java src/org/project/entity/*.java src/org/project/entity/enemies/*.java src/org/project/entity/players/*.java src/org/project/item/*.java src/org/project/item/weapons/*.java src/org/project/item/armors/*.java src/org/project/item/consumables/*.java ``` Or simply: ```bash javac -d out src/org/project/**/*.java src/org/project/*.java ``` ### Step 3: Run the Game ```bash java -cp out org.project.Main ``` ### Alternative (if you have an IDE): 1. Open the project in **IntelliJ IDEA, Eclipse**, or **VS Code** 2. Locate the `Main.java` file in `src/org/project/` 3. Click **Run** or press `Shift+F10` --- ## 🏗️ Project Architecture & OOP Principles ### Class Hierarchy ```plaintest Entity (abstract) ├── Player (abstract) │ ├── Knight │ ├── Wizard │ └── Assassin └── Enemy (abstract) ├── Goblin ├── Skeleton ├── Vampire └── Dragon Item (interface) ├── Weapon (abstract) │ ├── Sword │ ├── Staff │ ├── Dagger │ ├── BoneDagger │ ├── Claw │ └── DragonClaw ├── Armor (abstract) │ ├── KnightArmor │ ├── WizardRobe │ └── LeatherArmor └── Consumable (abstract) └── Flask ICombatActions (interface) └── Implemented by Player and Enemy ``` ### OOP Principles Used | Principle | Implementation | |---------------|-----------------------------------------------------------------------------------------------------| | Encapsulation | All fields are `private` or `protected` with public getters/setters | | Inheritance | `Player` and `Enemy` extend `Entity`; specific classes extend these | | Polymorphism | `Entity` references can point to any player/enemy object; `ICombatActions` unifies combat behaviors | | Abstraction | `Entity`, `Player`, `Enemy`, `Weapon`, `Armor` are abstract classes | | Interfaces | `ICombatActions` defines the 5 combat actions; `Item` defines consumable/equipment behavior | ### Design Patterns - **Template Method Pattern:** The `attack()` method in `Enemy` is overridden by each enemy type - **Factory Pattern:** `spawnRandomEnemy()` creates enemies without exposing instantiation logic - **Strategy Pattern:** Each player class implements `ICombatActions` differently --- ## 📁 Package Structure ```plaintext src/org/project/ ├── Main.java ├── entity/ │ ├── Entity.java │ ├── players/ │ │ ├── Player.java │ │ ├── Knight.java │ │ ├── Wizard.java │ │ └── Assassin.java │ └── enemies/ │ ├── Enemy.java │ ├── Goblin.java │ ├── Skeleton.java │ ├── Vampire.java │ └── Dragon.java ├── item/ │ ├── Item.java │ ├── weapons/ │ │ ├── Weapon.java │ │ ├── Sword.java │ │ ├── Staff.java │ │ ├── Dagger.java │ │ └── ... │ ├── armors/ │ │ ├── Armor.java │ │ ├── KnightArmor.java │ │ ├── WizardRobe.java │ │ └── LeatherArmor.java │ └── consumables/ │ ├── Consumable.java │ └── Flask.java └── location/ └── Location.java ``` --- ## 🎯 Game Features - ✅ Turn-based combat system - ✅ 3 playable classes with unique stats and abilities - ✅ 4 enemy types including a final boss - ✅ Random key drop system (20% chance) - ✅ Experience and leveling system (XP scales with enemy strength) - ✅ Full HP/Mana recovery after each battle - ✅ Progressive unlocking of the Castle (requires 3 keys) - ✅ Colorful console output using ANSI escape codes --- ## 👥 Contributors Zahra Gharagozloo Mazlaghan – Advanced Programming Course Instructor: Dr. Kheradpisheh University: Shahid Beheshti University --- **Enjoy the game, and may you break the curse of Javanest! ⚔️🐉**