Well done! This was a challenging assignment and you handled it successfully. The console output and one logical issue were the main problems in your project, but overall you did a good job. Keep up the great work!(100/110 + 0/50)
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:
- Install JDK
- Install IntelliJ IDEA
- Run the
Mainclass in the project
How to play:
- Create character: Knight/ Wizard/ Assassin
🏰 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!
- Select location: Forest/ Cave/ Swamp
🗺️ 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.
⚠️ A wild Vampire appears in Spooky Cave!
📍 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
- 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).
⚔️ 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)
- 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
privateorprotected. Access to these fields are controlled throughpublicgetter 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:
Playeris an abstract class implementingEntity. Subclasses:Knight,Wizard,Assassin.- Also
Enemyis the superclass forGoblin,Skeleton,VampireandDragon. ArmorandWeaponimplementingItem.Sword,Dagger, andWandextendWeapon;Robe,KnightArmor,LeatherArmorextendArmor.
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, theDragonclass overridesattack()to handle its special "Fiery Breath" mechanic, which ignores player defense. Similarly, each character class (Knight,Wizard,Assassin) overridesspecialAbility()to provide unique skills. - Polymorphic Collections: We use a
List<Enemy>to store different types of enemies. We can iterate through this list and callenemy.attack(player)without knowing the specific type of enemy, and the correct version of the method will be executed.
- Method Overriding: Each enemy class overrides the
4. Abstraction
Complex implementation details are hidden behind simple interfaces.
- Usage:
- The
Entityclass is declared as abstract. It defines abstract methods likeattack()which must be implemented by every subclass. - The
Playerclass is abstract, forcing subclasses likeAssassinto implement thespecialAbility(Entity target).
- The