Minor changes for the game. New README.md implemented

This commit is contained in:
2026-05-11 14:23:10 +03:30
parent 6958fc396f
commit 84675dda65
16 changed files with 76 additions and 255 deletions
@@ -19,9 +19,7 @@ public interface Entity {
int getHealManaCost(); int getHealManaCost();
int getDefendManaCost(); int getDefendManaCost();
void skipNextTurn(); // void skipNextTurn(); /disabled
void skipTurn(); // void skipTurn(); /disabled
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
} }
@@ -3,16 +3,14 @@ package org.project.entity.enemies;
import org.project.entity.Entity; 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 implements Entity {
Weapon weapon; Weapon weapon;
private int hp; private int hp;
private int maxHP; private int maxHP;
private int mp; private int mp;
private int maxMP; private int maxMP;
private boolean canPlayThisTurn = true; // private boolean canPlayThisTurn = true;
private boolean isDefendingThisTurn = false; private boolean isDefendingThisTurn = false;
private boolean isAlive;
private int healManaCost; private int healManaCost;
private int defendManaCost; private int defendManaCost;
public Enemy(int hp, int mp, Weapon weapon, public Enemy(int hp, int mp, Weapon weapon,
@@ -65,14 +63,14 @@ public abstract class Enemy implements Entity {
mp = 0; mp = 0;
} }
} }
@Override // @Override //disabled
public void skipNextTurn() { // public void skipNextTurn() {
this.canPlayThisTurn = false; // this.canPlayThisTurn = false;
} // }
@Override // @Override //disabled
public void skipTurn() { // public void skipTurn() {
this.canPlayThisTurn = true; // this.canPlayThisTurn = true;
} // }
@Override @Override
public String getType() { public String getType() {
return "Enemy"; return "Enemy";
@@ -5,7 +5,6 @@ import org.project.item.weapons.Weapon;
import java.util.Random; import java.util.Random;
// TODO: UPDATE IMPLEMENTATION
public class Skeleton extends Enemy implements Key { public class Skeleton extends Enemy implements Key {
private static int DEFAULT_HP = 100; private static int DEFAULT_HP = 100;
private static int DEFAULT_MP = 100; private static int DEFAULT_MP = 100;
@@ -61,5 +60,4 @@ public class Skeleton extends Enemy implements Key {
keysRemaining = 1; keysRemaining = 1;
} }
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
} }
@@ -3,7 +3,6 @@ package org.project.entity.players;
import org.project.item.weapons.Sword; import org.project.item.weapons.Sword;
import org.project.item.weapons.Weapon; import org.project.item.weapons.Weapon;
// TODO: UPDATE IMPLEMENTATION
public class Knight extends Player { public class Knight extends Player {
private static int DEFAULT_HP = 100; private static int DEFAULT_HP = 100;
private static int DEFAULT_MP = 80; private static int DEFAULT_MP = 80;
@@ -35,5 +34,4 @@ public class Knight extends Player {
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
} }
@@ -6,7 +6,6 @@ import org.project.item.weapons.Weapon;
import java.util.ArrayList; import java.util.ArrayList;
// TODO: UPDATE IMPLEMENTATION
public abstract class Player implements Entity{ public abstract class Player implements Entity{
protected String name; protected String name;
Weapon weapon; Weapon weapon;
@@ -86,14 +85,14 @@ public abstract class Player implements Entity{
} }
} }
@Override // @Override
public void skipNextTurn() { // public void skipNextTurn() {
this.canPlayThisTurn = false; // this.canPlayThisTurn = false;
} // }
@Override // @Override
public void skipTurn() { // public void skipTurn() {
this.canPlayThisTurn = true; // this.canPlayThisTurn = true;
} // }
public String getName() { public String getName() {
return name; return name;
} }
@@ -1,42 +0,0 @@
package org.project.item.armors;
// TODO: UPDATE IMPLEMENTATION
public abstract class Armor {
private int defense;
private int maxDefense;
private int durability;
private int maxDurability;
private boolean isBroke;
public Armor(int defense, int durability) {
this.defense = defense;
this.durability = durability;
}
public void checkBreak() {
if (durability <= 0) {
isBroke = true;
defense = 0;
}
}
// TODO: (BONUS) UPDATE THE REPAIR METHOD
public void repair() {
isBroke = false;
defense = maxDefense;
durability = maxDurability;
}
public int getDefense() {
return defense;
}
public int getDurability() {
return durability;
}
public boolean isBroke() {
return isBroke;
}
}
@@ -1,6 +0,0 @@
package org.project.item.armors;
// TODO: UPDATE IMPLEMENTATION
public class KnightArmor {
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
}
@@ -23,7 +23,6 @@ public class BoneHarpoon extends Weapon{
@Override @Override
public String getExplanation() { public String getExplanation() {
return "Melee slashing tool for skeletons.\n"+ return "Melee slashing tool for skeletons.\n"+
"Damage: "+ this.getDamage() +" Mana cost: " + this.getManaCost() + "Damage: "+ this.getDamage() +" Mana cost: " + this.getManaCost();
"\nSpecial ability: When used by the skeleton, it resurrects with 50% hp.";
} }
} }
@@ -24,7 +24,6 @@ public class Dagger extends Weapon{
@Override @Override
public String getExplanation() { public String getExplanation() {
return "Melee piercing for Assassins.\n"+ return "Melee piercing for Assassins.\n"+
"Damage: "+ this.getDamage() +" Mana cost: " + this.getManaCost() + "Damage: "+ this.getDamage() +" Mana cost: " + this.getManaCost();
"\nSpecial ability: Inflicts 40 damage";
} }
} }
@@ -23,7 +23,6 @@ public class Fireball extends Weapon{
@Override @Override
public String getExplanation() { public String getExplanation() {
return "Magical balls of fire for Wizards.\n"+ return "Magical balls of fire for Wizards.\n"+
"Damage: "+ this.getDamage() +" Mana cost: " + this.getManaCost() + "Damage: "+ this.getDamage() +" Mana cost: " + this.getManaCost();
"\nSpecial ability: Throws 3 fireballs at once inflicting 3 times the normal damage.\n";
} }
} }
@@ -24,8 +24,7 @@ public class GoblinSickle extends Weapon {
@Override @Override
public String getExplanation() { public String getExplanation() {
return "Melee slashing tool for goblins. Causes bleeding over time.\n" + return "Melee slashing tool for goblins. Causes bleeding over time.\n" +
"Damage: "+ this.getDamage() +" Mana cost: " + this.getManaCost() + "Damage: "+ this.getDamage() +" Mana cost: " + this.getManaCost();
"Special ability: The target takes twice the normal damage.";
} }
} }
@@ -25,7 +25,6 @@ public class MirrorClaws extends Weapon{
@Override @Override
public String getExplanation() { public String getExplanation() {
return "Melee slashing weapon for vampires. Inflicts \"reflection\" debuff.\n" + return "Melee slashing weapon for vampires. Inflicts \"reflection\" debuff.\n" +
"Damage: "+ this.getDamage() +" Mana cost: " + this.getManaCost() + "Damage: "+ this.getDamage() +" Mana cost: " + this.getManaCost();
"\nSpecial ability: reduces target's mana by 30 on top of normal damage.";
} }
} }
@@ -26,6 +26,6 @@ public class Sword extends Weapon {
} }
@Override @Override
public String getExplanation() { public String getExplanation() {
return "Melee piercing/bludgeoning for knights. Ignores armor on critical hits."; return "Melee piercing/bludgeoning for knights.";
} }
} }
@@ -16,7 +16,7 @@ public class TailScythe extends Weapon{
public void useSpecialAbility(Entity attacker, Entity target) { public void useSpecialAbility(Entity attacker, Entity target) {
target.takeDamage(this.getDamage() + 20); target.takeDamage(this.getDamage() + 20);
attacker.reduceMana(this.getManaCost() + 5); attacker.reduceMana(this.getManaCost() + 5);
target.skipNextTurn(); // target.skipNextTurn(); disabled
} }
@Override @Override
public String getType() { public String getType() {
@@ -25,7 +25,6 @@ public class TailScythe extends Weapon{
@Override @Override
public String getExplanation() { public String getExplanation() {
return "Melee sweeping attack for Dragons. Hitting targets with its tail.\n" + return "Melee sweeping attack for Dragons. Hitting targets with its tail.\n" +
"Damage: "+ this.getDamage() +" Mana cost: " + this.getManaCost() + "Damage: "+ this.getDamage() +" Mana cost: " + this.getManaCost();
"Special ability:The target takes +20 damage than normal attack. Also loses their next turn.";
} }
} }
@@ -3,16 +3,11 @@ package org.project.item.weapons;
import org.project.entity.Entity; import org.project.entity.Entity;
import org.project.item.Item; import org.project.item.Item;
// TODO: UPDATE IMPLEMENTATION
public abstract class Weapon implements Item { public abstract class Weapon implements Item {
private int damage; private int damage;
private int manaCost; private int manaCost;
private int specialMana; private int specialMana;
/*
TODO: ADD OTHER REQUIRED AND BONUS ATTRIBUTES
*/
public Weapon(int damage, int manaCost, int specialMana) { public Weapon(int damage, int manaCost, int specialMana) {
this.damage = damage; this.damage = damage;
this.manaCost = manaCost; this.manaCost = manaCost;
@@ -51,7 +46,5 @@ public abstract class Weapon implements Item {
attacker.reduceMana(this.getManaCost()); attacker.reduceMana(this.getManaCost());
} }
public abstract void useSpecialAbility(Entity attacker, Entity target); public abstract void useSpecialAbility(Entity attacker, Entity target);
/*
TODO: ADD OTHER REQUIRED AND BONUS METHODS
*/
} }
+47 -156
View File
@@ -1,175 +1,66 @@
# Fourth Assignment - Java Knight ⚔️ # ⚔️ Java Knight: The Legend of Javanest
A turn-based RPG with Roguelike elements which can be run in the terminal.
### **Prologue: The Legend of Javanest** Java Knight is a turn-based, console-based RPG built in Java. Players take on the role of a hero tasked with saving the land of Javanest by defeating monsters, collecting mystical keys, and ultimately slaying the Dragon.
*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**
Welcome to **Java knight**, a turn-based RPG inspired by Roguelike games! In this assignment, you will develop a **text-based role-playing game (RPG)**. This project is designed to rigorously test your understanding of **Object-Oriented Programming (OOP) principles**.
⚠️ **REQUIREMENT:** You **must** utilize all the OOP concepts you have learned so far—including *Inheritance, Interfaces, Abstract Classes, Encapsulation, Polymorphism, Overloading, and Overriding*. It is extremely important that you use everything in its right place. Your design and architecture will be graded based on how well you apply these principles to avoid code duplication and maintain a clean structure.
🎯 **Your goal is not just to complete the assignment but to learn and apply OOP effectively!**
### **What is a Turn-Based Game?**
In this combat system, two sides - which are usually the player's side and the enemy's side - attack each other in turns. The side which is not attacking can perform actions to avoid or deflect the enemy's attack.
### **Core Mechanics:**
- **Turn-based combat** Players and monsters take turns attacking each other.
- **Character classes with Unique Traits** Players can choose from archetypes like **Knight, Assassin, or Wizard**, each starting with distinctly different base stats.
- **Unified Mana/Stamina System** All player classes use a unified resource (Mana/Stamina) to perform actions.
- **Standardized Action Set** Every player character has exactly 5 specific actions available during their turn.
- **Experience & Leveling System** Earn XP based on enemy strength to automatically level up and increase your base stats.
- **Progression System** You cannot fight the Dragon immediately. You must farm enemies for a chance to drop their specific key, collect all three, and grow stronger first.
--- ---
## Tasks 📝 ## 🚀 Quick Start
### 1️⃣ Step 1: Fork & Setup 🍴 **Prerequisites:** Java JDK 8 or higher.
1. **Fork** this repository and clone it to your local machine.
```bash
git clone https://git.meshcomp.ir/AdvancedProgramming1404/HW-04-JAVA-KNIGHT.git
```
2. Create a new branch named `develop` and switch to it.
```bash
git checkout -b develop
```
### 2️⃣ Step 2: Implement the Class Hierarchy 🌲
A well-structured OOP hierarchy is crucial. Avoid duplicating code by placing shared logic in abstract classes. 1. **Navigate to the source root:**
```bash
- **Entities & Locations:** You have `Entity`, `Item`(Bonus) , and `Location`. cd your-project-folder/src
- **Players:** `Player` is an abstract class implementing `Entity`. Subclasses: `Wizard`, `Knight`, `Assassin`. ```
- **Base Stat Differences:** Each class must have distinct starting stats. For example: 2. **Compile the project:**
- **Knight:** Highest Base Damage. ```bash
- **Wizard:** Highest Max Health (HP). javac org/project/Main.java
- **Assassin:** Highest Max Stamina/Mana. ```
- **Enemies:** `Enemy` is an abstract class implementing `Entity`. Subclasses: `Skeleton`, `Goblin`, `Vampire`, and **`Dragon`**. 3. **Run the game:**
- **The Boss:** Even though `Dragon` is the final boss, it **must** be a subclass of `Enemy` to inherit common combat properties, while possessing extremely high stats and unique mechanics. ```bash
- **Item (Bonus):** `Consumable`, `Armor`, `Weapon` are abstract classes implementing `Item`. example : java org.project.Main
- KnightArmor extends Armor - you can add more subclasses of Armor for extra score ```
- Sword extends Weapon - you can add more subclasses of Weapon for extra score
- Flask extends Consumable - you can add more subclasses of Consumable for extra score
![structure](Readme_Pictures/structure.png)
### 3️⃣ Step 3: Implement Player & Monster Methods 🏹
**Player Actions (The Rule of Five):**
Every player class **must** implement exactly the following 5 actions (You can use an interface like `ICombatActions`). Every action (except Light Attack) consumes a specific amount of Mana/Stamina. The **Special Ability** must consume the *highest* amount of Mana compared to the others.
1. **Light Attack:** Deals moderate damage and costs **NO Mana**. (Note: If the player runs out of Mana/Stamina, this is the ONLY action they can perform.)
2. **Heavy Attack:** Deals high damage, medium Mana cost.
3. **Defend:** Completely blocks or significantly reduces the damage of the enemy's *next* strike. Medium Mana cost.
4. **Heal:** Restores a portion of the player's HP. Medium-high Mana cost.
5. **Special Ability:** A unique class-based ultimate move (Highest Mana cost):
- **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.
**Monster Abilities:**
- **Goblin** 👹: High critical hit chance 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.
🔹 Make sure each entity **prints messages** when performing actions. example output (while in combat) :
```bash
You chose to FIGHT!
[Ser Duncan - 45/45 HP | 40/40 Mana]
[Goblin - 30/30 HP]
--- ---
Your Turn: ## ⚙️ Game Mechanics
1. Light Attack | 2. Heavy Attack (-8 Mana) | 3. Defend (-6 Mana) | 4. Heal (-12 Mana) | 5. Shield Bash (-15 Mana)
```
```bash - **Progression & XP:** After each victory, your HP and Mana are fully recovered. Defeating enemies grants Experience Points (XP).
→ Chose: Light Attack - **The Shop:** Between fights, you can visit the inventory to convert XP into permanent stat upgrades. 1 XP can be exchanged for either 1 Max HP or 1 Max MP.
⚔️ Ser Duncan (Knight) used Light Attack! (0 Mana) - **The Hunt for Keys:** To reach the end-game, you must collect three unique keys (Goblin, Skeleton, and Vampire). These have a chance to drop after defeating the respective enemy type.
Goblin took 10 damage! - **The Castle:** The path to the final boss is locked until all three keys are in your possession. Only then can you enter the castle to face the Dragon.
Goblin has 20/30 HP remaining.
Ser Duncan Mana: 40/40
```
```
Goblin's Turn :
👹 Goblin used Critical Strike!
💥 Critical hit! Ser Duncan took 20 damage!
Ser Duncan has 25/45 HP remaining.
```
🔹 *Narrative Console:* Use ANSI escape codes to print colorful narrative logs (e.g., Red for damage, Blue for Mana usage, Green for healing).
### 4️⃣ Step 4: Implement the Game Loop & Progression 🎮
1. **The Core Loop:** The game starts with the player entering a location. A random standard enemy (`Goblin`, `Skeleton`, or `Vampire`) spawns immediately.
2. **Player Choices:** Before engaging, the player is presented with the following options:
- **1. Fight the enemy:** Enter the turn-based combat sequence.
- **2. Move to another location:** Skip the current enemy and spawn a new random one.
- **3. Go to the Castle to fight the Dragon:** *(Note: This option must remain strictly hidden or locked until the player has successfully collected all 3 keys).*
3. **The Key Drop Logic (RNG Gatekeeping):**
- When the player defeats an enemy, there is a **specific percentage chance (e.g., 20%)** that it will drop the unique key associated with its species (Goblin Key, Skeleton Key, Vampire Key).
- **One Key Per Species:** Once a player obtains a specific key (e.g., Goblin Key), subsequent enemies of that same type (other Goblins) will **never** drop a key again.
- The player **must collect all 3 distinct keys** to unlock Option 3 and enter the Castle.
4. **Post-Combat Recovery:** After each successful battle, the player's HP and Mana bars must automatically replenish (either fully or partially) to their base amounts so they are ready for the next encounter.
5. **Experience & Leveling System:**
- Defeating an enemy grants **XP**. The amount of XP must scale proportionally to the enemy's power level.
- Upon reaching an XP threshold, the player levels up. **Leveling up must automatically increase the player's Max HP and Max Stamina/Mana**, making them strong enough to eventually face the Dragon.
6. **Final Boss Fight:** Once the 3 Keys are obtained and the player chooses to go to the Castle, they will face the Dragon. Defeating the Dragon breaks the curse, resulting in **Victory**. Dying at any point results in **Game Over**.
🔹 Example game loop structure:
```java
while (player.isAlive() && enemy.isAlive())
player.attack(enemy);
if (enemy.isAlive()) {
enemy.attack(player);
}
}
```
### 5️⃣ Step 5: Extra Features & Bonus Tasks ⭐
*(Optional for extra credit)*
**Dynamic Economy & Merchant System:** Implement coins that drop from enemies. Add a "Visit Merchant" option to the main loop where players can spend coins to buy specific weapons, armors, or consumables.
**Multiple Weapons & Inventory:** Players can buy, store, and swap between multiple weapons or use consumables mid-combat.
**Multiplayer/Party Mode:** Allow multiple players to team up and fight multiple enemies together. The Dragon's breath attack will damage the entire party simultaneously.
**PvP Mode:** Implement a **Player vs. Player** combat system.
### 6️⃣ Step 6: Write a Comprehensive README 📄
As the final mandatory step of your development, you must replace the default `README.md` with your own comprehensive documentation. Your README should include:
- A brief introduction to the game.
- How to compile and run your project from the terminal.
- An explanation of the classes, design patterns, and OOP principles you used.
- A brief guide on how to play (controls, stats, classes).
--- ---
## Evaluation Criteria ⚖ ## 🎮 How to Play
| **Criteria** | **Points** | ### Hero Classes
|-------------------------------------------------------------|------------| - **Knight:** Balanced stats with high-damage melee capabilities.
| Proper use of OOP principles | **50** | - **Assassin:** High stamina/mana efficiency with lower costs for defending.
| Working combat mechanics, Leveling System & Enemy abilities | **20** | - **Wizard:** High mana pool and powerful magical abilities.
| Clear and Comprehensive `README.md` | **20** |
| Code readability, documentation, and comments | **10** |
| Meaningful, interactive, & colored console outputs | **10** |
| Inventory (item) and Merchant System (bonus) | **20** |
| Other Extra features (bonus tasks) | **20** |
| **Total Score** | **150** |
## Tips 🚀 ### Combat Actions
- **Follow OOP principles**: Avoid redundant code by using inheritance properly. Think carefully about what belongs in an abstract class vs. a specific subclass. Make sure you use overriding and overloading correctly. On your turn, choose one of the following:
- **Test your code**: Run different scenarios (fighting, running out of mana, leveling up, dying) to ensure everything works as expected. 1. **Light Attack:** Moderate damage; costs **0 Mana**.
- **Ask for help**: If you're stuck, reach out to your classmates or mentors. 2. **Heavy Attack:** High damage; costs Mana.
3. **Special Ability:** Unique class-based move; highest Mana cost.
4. **Defend:** Reduces or blocks the next enemy attack; costs Mana.
5. **Heal:** Restores HP during combat; costs Mana.
## Submission ⌛ ---
- **Deadline**: Submit your assignment before **21 Ordibehesht (May 11th, 2026)**.
- **Submission Format**: Push your code to your forked repository, create a PR, and ensure your comprehensive `README.md` is included in the root directory. ## 🛠 Technical Architecture & OOP Principles
This project demonstrates core Object-Oriented Programming principles:
- **Inheritance:** Uses hierarchies for `Player` (Knight/Wizard/Assassin) and `Enemy` (Goblin/Skeleton/Vampire/Dragon) to share common logic while allowing unique overrides.
- **Polymorphism:** The combat engine handles any `Entity` implementation. The `Weapon` system allows different damage behaviors to be executed through a single interface.
- **Encapsulation:** Core stats like HP, Mana, and XP are protected. Data integrity is maintained through getters, setters, and specialized methods like `takeDamage()` and `reduceMana()`.
- **Abstraction:** The `Weapon`, `Enemy`, and `Player` classes are abstract, ensuring that specific game entities must follow a strict template while hiding the complexity of underlying calculations.
- **Interfaces:** The `Entity`, `Item`, and `Key` interfaces decouple behaviors from the class hierarchy, allowing for flexible interaction between different game objects.
<br/>
![cover](Readme_Pictures/image.png) ![cover](Readme_Pictures/image.png)
###### - Born of God and Void. You shall seal the blinding light that plagues their dreams. You are the Vessel. You are the Java Knight. ###### - Born of God and Void. You shall seal the blinding light that plagues their dreams. You are the Vessel. You are the Java Knight.