# 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!* ### Introduction Java Knight is a text-based Role-Playing Game developed using OOP principles in java. The gameplay is driven by interactive console messages and user input. ___ #### Setup: 1. Install JDK 2. Install IntelliJ IDEA 3. Run the `Main` class in the project ___ ### How to play: 1. **Create character:** Knight/ Wizard/ Assassin ```java 🏰 Welcome to Java Knight! Enter your name: Gru 1. βš”οΈ Knight (High Damage, Balanced HP) 2. πŸ§™ Wizard (High HP, Magic Power) 3. πŸ—‘οΈ Assassin (High Mana, Critical Hits) Choose your character: 3 You chose the Assassin! ``` 2. **Select location:** Forest/ Cave/ Swamp ```java πŸ—ΊοΈ Choose your starting location: 1. Dark Forest 2. Spooky Cave 3. Swamp Enter your choice: 2 🚢 You have arrived at: Spooky Cave ```
When you arrive at the selected location, an enemy (Goblin/ Skeleton/ Vampire) spawns randomly. You can fight, move to another location, or quit. ```java ⚠️ A wild Vampire appears in Spooky Cave! ``` ```java πŸ“ Location: Spooky Cave ❀️ Player HP: 150/150 πŸ’Ž Player MP: 120/120 Enemy: Vampire (HP: 80) ---- Actions ---- 1. πŸ₯· Fight enemy 2. 🚢 Move to another location 3. πŸ”’ Go to Dragon Castle 4. 🏳️ Quit game ``` 3. **Fight:** You can use one of these 5 actions: * Light Attack: Deals moderate damage and costs NO Mana. (Note: If you run out of Mana, this is the ONLY action you can perform.) * Heavy Attack: Deals high damage, medium Mana cost. * Defend: Reduces the damage of the enemy's next strike. Medium Mana cost. * Heal: Restores a portion of the player's HP. Medium-high Mana cost. * Special Ability: A unique class-based ultimate move (Highest Mana cost). ```java βš”οΈ Battle Started: Gru vs Vampire --- Your Turn --- 1. Light Attack | 2. Heavy Attack (-20 Mana) | 3. Defend (-15 Mana) | 4. Heal (-30 Mana) | 5. Special (-50 Mana) ``` 4. You cannot fight the Dragon immediately. You must fight enemies for a chance to drop their specific key, collect all three, and grow stronger first. #### More about the game and characters * Special abilities: * 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. * Monsters: * Goblin πŸ‘Ή: High critical hit chance(40%) 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. Once you obtain a specific key (e.g., Goblin Key), subsequent enemies of that same type (other Goblins) will never drop a key again. You can still fight enemies to earn XP based on enemy strength to automatically level up and increase your base stats (max health and Mana) and become strong enough to face the Dragon. ___ ### Object-Oriented Programming concepts implementation #### 1. Encapsulation Data hiding is used to protect the internal state of objects. * Usage: All fields in class are declared as `private` or `protected`. Access to these fields are controlled through `public` getter and setter methods. (e.g. `getName`, `setHP`). This ensures that the name or health of the entity cannot be modified incorrectly outside the class. #### 2. Inheritance Code reusability is achieved by creating a hierarchy of classes and interfaces. * Usage: * `Player` is an abstract class implementing `Entity`. Subclasses: `Knight`, `Wizard`, `Assassin`. * Also `Enemy` is the superclass for `Goblin`, `Skeleton`, `Vampire` and `Dragon`. * `Armor` and `Weapon` implementing `Item`. `Sword`, `Dagger`, and `Wand` extend `Weapon`; `Robe`, `KnightArmor`, `LeatherArmor` extend `Armor`. #### 3. Polymorphism The ability to process objects differently based on their data type is used extensively. * Usage: * Method Overriding: Each enemy class overrides the `attack()` method. For example, the `Dragon` class overrides `attack()` to handle its special "Fiery Breath" mechanic, which ignores player defense. Similarly, each character class (`Knight`, `Wizard`, `Assassin`) overrides `specialAbility()` to provide unique skills. * Polymorphic Collections: We use a `List` to store different types of enemies. We can iterate through this list and call `enemy.attack(player)` without knowing the specific type of enemy, and the correct version of the method will be executed. #### 4. Abstraction Complex implementation details are hidden behind simple interfaces. * Usage: * The `Entity` class is declared as abstract. It defines abstract methods like `attack()` which must be implemented by every subclass. * The `Player` class is abstract, forcing subclasses like `Assassin` to implement the `specialAbility(Entity target)`.