Forth Assignment #1
Generated
+2
-2
@@ -1,9 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_23_PREVIEW" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="jdk" jdkName="23 (2)" jdkType="JavaSDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
||||
Generated
+1
-1
@@ -8,7 +8,7 @@
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="25" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_23_PREVIEW" project-jdk-name="23" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
</project>
|
||||
+2
-2
@@ -9,8 +9,8 @@
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>25</maven.compiler.source>
|
||||
<maven.compiler.target>25</maven.compiler.target>
|
||||
<maven.compiler.source>23</maven.compiler.source>
|
||||
<maven.compiler.target>23</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
|
||||
@@ -9,7 +9,17 @@ public class Main {
|
||||
public static void main(String[] args) {
|
||||
// TODO: ADD LOCATIONS TO YOUR GAME
|
||||
List<Location> locations = new ArrayList<>();
|
||||
Location forest = new Location("Forest", new ArrayList<>());
|
||||
Location dungeon = new Location("Dungeon", new ArrayList<>());
|
||||
Location castle = new Location("Castle", new ArrayList<>());
|
||||
|
||||
locations.add(forest);
|
||||
locations.add(dungeon);
|
||||
locations.add(castle);
|
||||
// TODO: IMPLEMENT GAMEPLAY
|
||||
System.out.println("Locations in the game:");
|
||||
for (Location location : locations) {
|
||||
System.out.println(location.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.project.entity;
|
||||
|
||||
public interface Entity {
|
||||
/*public interface Entity {
|
||||
void attack(Entity target);
|
||||
|
||||
void defend();
|
||||
@@ -18,4 +18,72 @@ public interface Entity {
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
public abstract class Entity {
|
||||
|
||||
protected String name;
|
||||
|
||||
protected int hp;
|
||||
protected int mp;
|
||||
|
||||
protected int maxHP;
|
||||
protected int maxMP;
|
||||
|
||||
public Entity(String name, int hp, int mp) {
|
||||
|
||||
this.name = name;
|
||||
|
||||
this.hp = hp;
|
||||
this.mp = mp;
|
||||
|
||||
this.maxHP = hp;
|
||||
this.maxMP = mp;
|
||||
}
|
||||
|
||||
public abstract void attack(Entity target);
|
||||
|
||||
public abstract void defend();
|
||||
|
||||
public abstract void heal(int health);
|
||||
|
||||
public void fillMana(int mana) {
|
||||
|
||||
mp += mana;
|
||||
|
||||
if (mp > maxMP) {
|
||||
mp = maxMP;
|
||||
}
|
||||
}
|
||||
|
||||
public void takeDamage(int damage) {
|
||||
|
||||
hp -= damage;
|
||||
|
||||
if (hp < 0) {
|
||||
hp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAlive() {
|
||||
return hp > 0;
|
||||
}
|
||||
|
||||
public int getMaxHP() {
|
||||
return maxHP;
|
||||
}
|
||||
|
||||
public int getMaxMP() {
|
||||
return maxMP;
|
||||
}
|
||||
|
||||
public int getHp() {
|
||||
return hp;
|
||||
}
|
||||
|
||||
public int getMp() {
|
||||
return mp;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Enemy {
|
||||
/*public abstract class Enemy {
|
||||
Weapon weapon;
|
||||
private int hp;
|
||||
private int mp;
|
||||
private int mp;*/
|
||||
public abstract class Enemy extends Entity {
|
||||
|
||||
public Enemy(int hp, int mp, Weapon weapon) {
|
||||
this.hp = hp;
|
||||
this.mp = mp;
|
||||
protected Weapon weapon;
|
||||
//protected int hp;
|
||||
//protected int mp;
|
||||
protected String name;
|
||||
|
||||
|
||||
public Enemy(String name,int hp, int mp, Weapon weapon) {
|
||||
|
||||
super(name, hp, mp);
|
||||
|
||||
this.weapon = weapon;
|
||||
}
|
||||
@@ -18,7 +25,14 @@ public abstract class Enemy {
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
hp -= damage;
|
||||
if (hp < 0) hp = 0;
|
||||
}
|
||||
@Override
|
||||
public boolean isAlive() {
|
||||
return hp > 0;
|
||||
}
|
||||
@Override
|
||||
public abstract void attack(Entity target);
|
||||
|
||||
public int getHp() {
|
||||
return hp;
|
||||
@@ -31,4 +45,7 @@ public abstract class Enemy {
|
||||
public Weapon getWeapon() {
|
||||
return weapon;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,58 @@
|
||||
package org.project.entity.enemies;
|
||||
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.weapons.Weapon;
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Skeleton {
|
||||
/*public class Skeleton {
|
||||
// TODO: DESIGN ENEMY AND IMPLEMENT THE CONSTRUCTOR
|
||||
}
|
||||
}*/
|
||||
public class Skeleton extends Enemy {
|
||||
|
||||
private boolean revived = false;
|
||||
public Skeleton(int hp, int mp, Weapon weapon) {
|
||||
super("Skeleton", hp, mp, weapon);
|
||||
}
|
||||
@Override
|
||||
public void heal(int health) {
|
||||
|
||||
hp += health;
|
||||
|
||||
if (hp > maxHP) {
|
||||
hp = maxHP;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fillMana(int mana) {
|
||||
|
||||
mp += mana;
|
||||
|
||||
if (mp > maxMP) {
|
||||
mp = maxMP;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void attack(Entity target) {
|
||||
int damage = weapon.getDamage();
|
||||
target.takeDamage(damage);
|
||||
System.out.println(" Skeleton attacked and dealt " + damage + " damage!");
|
||||
}
|
||||
@Override
|
||||
public void defend() {
|
||||
System.out.println("Skeleton is defending!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
super.takeDamage(damage);
|
||||
|
||||
if (!revived && hp <= 0) {
|
||||
revived = true;
|
||||
|
||||
hp = maxHP / 2;
|
||||
|
||||
System.out.println(
|
||||
"💀 Skeleton revived with 50% HP!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,58 @@
|
||||
package org.project.entity.players;
|
||||
import org.project.entity.Entity;
|
||||
import org.project.item.armors.Armor;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class Knight {
|
||||
//public class Knight {
|
||||
// TODO: DESIGN KNIGHT'S WEAPON AND ARMOR AND IMPLEMENT THE CONSTRUCTOR
|
||||
//}
|
||||
public class Knight extends Player {
|
||||
|
||||
public Knight(String name, int hp, int mp,
|
||||
Weapon weapon, Armor armor) {
|
||||
|
||||
super(name, hp, mp, weapon, armor);
|
||||
}
|
||||
|
||||
public void lightAttack(Entity target) {
|
||||
|
||||
int damage = weapon.getDamage();
|
||||
|
||||
target.takeDamage(damage);
|
||||
|
||||
System.out.println(name +
|
||||
" used Light Attack!");
|
||||
}
|
||||
|
||||
public void heavyAttack(Entity target) {
|
||||
|
||||
int damage = weapon.getDamage() * 2;
|
||||
|
||||
target.takeDamage(damage);
|
||||
|
||||
mp -= 10;
|
||||
|
||||
System.out.println(name +
|
||||
" used Heavy Attack!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defend() {
|
||||
|
||||
System.out.println(name +
|
||||
" raised shield!");
|
||||
}
|
||||
|
||||
public void specialAbility(Entity target) {
|
||||
|
||||
int damage = weapon.getDamage() * 3;
|
||||
|
||||
target.takeDamage(damage);
|
||||
|
||||
mp -= 20;
|
||||
|
||||
System.out.println(name +
|
||||
" used Shield Bash!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,19 +5,14 @@ import org.project.item.armors.Armor;
|
||||
import org.project.item.weapons.Weapon;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Player {
|
||||
public abstract class Player extends Entity {
|
||||
protected String name;
|
||||
Weapon weapon;
|
||||
Armor armor;
|
||||
private int hp;
|
||||
private int maxHP;
|
||||
private int mp;
|
||||
private int maxMP;
|
||||
protected Weapon weapon;
|
||||
protected Armor armor;
|
||||
|
||||
public Player(String name, int hp, int mp, Weapon weapon, Armor armor) {
|
||||
this.name = name;
|
||||
this.hp = hp;
|
||||
this.mp = mp;
|
||||
|
||||
super(name, hp, mp);
|
||||
|
||||
this.weapon = weapon;
|
||||
this.armor = armor;
|
||||
@@ -31,12 +26,23 @@ public abstract class Player {
|
||||
@Override
|
||||
public void defend() {
|
||||
// TODO
|
||||
System.out.println(name + " is defending!");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void takeDamage(int damage) {
|
||||
hp -= damage - armor.getDefense();
|
||||
int finalDamage = damage - armor.getDefense();
|
||||
|
||||
if (finalDamage < 0) {
|
||||
finalDamage = 0;
|
||||
}
|
||||
|
||||
hp -= finalDamage;
|
||||
|
||||
if (hp < 0) {
|
||||
hp = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,4 +8,5 @@ public interface Item {
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
String getName();
|
||||
}
|
||||
|
||||
@@ -1,19 +1,35 @@
|
||||
package org.project.item.armors;
|
||||
import org.project.entity.Entity;
|
||||
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;
|
||||
private int maxDurability;
|
||||
|
||||
protected String name;
|
||||
private boolean isBroke;
|
||||
|
||||
public Armor(int defense, int durability) {
|
||||
public Armor(String name , int defense, int durability) {
|
||||
this.name = name;
|
||||
this.defense = defense;
|
||||
this.maxDefense = defense;
|
||||
this.maxDurability = durability;
|
||||
this.durability = durability;
|
||||
}
|
||||
@Override
|
||||
public void use(Entity target) {
|
||||
|
||||
System.out.println(
|
||||
target.getName() +
|
||||
" equipped armor!"
|
||||
);
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void checkBreak() {
|
||||
if (durability <= 0) {
|
||||
isBroke = true;
|
||||
@@ -23,9 +39,11 @@ public abstract class Armor {
|
||||
|
||||
// TODO: (BONUS) UPDATE THE REPAIR METHOD
|
||||
public void repair() {
|
||||
isBroke = false;
|
||||
defense = maxDefense;
|
||||
durability = maxDurability;
|
||||
if(isBroke) {
|
||||
isBroke = false;
|
||||
defense = maxDefense;
|
||||
durability = maxDurability;
|
||||
}
|
||||
}
|
||||
|
||||
public int getDefense() {
|
||||
@@ -39,4 +57,5 @@ public abstract class Armor {
|
||||
public boolean isBroke() {
|
||||
return isBroke;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package org.project.item.armors;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public class KnightArmor {
|
||||
public class KnightArmor extends Armor {
|
||||
// TODO: DESIGN ARMOR'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
||||
public KnightArmor(int defense, int durability) {
|
||||
|
||||
super("Knight Armor", defense, durability);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,18 @@
|
||||
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
|
||||
*/
|
||||
protected String name;
|
||||
public Consumable(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public abstract void use(Entity target);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,13 @@ 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("Flask");
|
||||
}
|
||||
|
||||
// TODO: UPDATE USE METHOD
|
||||
@Override
|
||||
|
||||
@@ -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,6 +14,8 @@ public class Sword {
|
||||
|
||||
public Sword() {
|
||||
// TODO: DESIGN SWORD'S ATTRIBUTES IMPLEMENT THE CONSTRUCTOR
|
||||
super("Sword", 15, 5);
|
||||
this.abilityCharge = 0;
|
||||
}
|
||||
|
||||
// TODO: (BONUS) UPDATE THE UNIQUE ABILITY
|
||||
@@ -22,5 +24,9 @@ public class Sword {
|
||||
for (Entity target : targets) {
|
||||
target.takeDamage(getDamage());
|
||||
}
|
||||
System.out.println(
|
||||
"⚔️ Sword used special ability!"
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
package org.project.item.weapons;
|
||||
|
||||
import org.project.item.Item;
|
||||
import org.project.entity.Entity;
|
||||
|
||||
// TODO: UPDATE IMPLEMENTATION
|
||||
public abstract class Weapon {
|
||||
public abstract class Weapon implements Item {
|
||||
private int damage;
|
||||
private int manaCost;
|
||||
|
||||
protected String name;
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS ATTRIBUTES
|
||||
*/
|
||||
|
||||
public Weapon(int damage, int manaCost) {
|
||||
public Weapon(String name,int damage, int manaCost) {
|
||||
this.name = name;
|
||||
this.damage = damage;
|
||||
this.manaCost = manaCost;
|
||||
}
|
||||
@@ -20,7 +21,10 @@ public abstract class Weapon {
|
||||
public void use(Entity target) {
|
||||
target.takeDamage(damage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public int getDamage() {
|
||||
return damage;
|
||||
}
|
||||
@@ -28,7 +32,7 @@ public abstract class Weapon {
|
||||
public int getManaCost() {
|
||||
return manaCost;
|
||||
}
|
||||
|
||||
public abstract void uniqueAbility(java.util.ArrayList<Entity> targets);
|
||||
/*
|
||||
TODO: ADD OTHER REQUIRED AND BONUS METHODS
|
||||
*/
|
||||
|
||||
@@ -9,19 +9,15 @@ public class Location {
|
||||
|
||||
private ArrayList<Enemy> enemies;
|
||||
|
||||
public Location(ArrayList<Location> locations, ArrayList<Enemy> enemies) {
|
||||
this.locations = locations;
|
||||
public Location(String name, ArrayList<Enemy> enemies) {
|
||||
|
||||
this.name = name;
|
||||
this.enemies = enemies;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public ArrayList<Location> getLocations() {
|
||||
return locations;
|
||||
}
|
||||
|
||||
public ArrayList<Enemy> getEnemies() {
|
||||
return enemies;
|
||||
}
|
||||
|
||||
@@ -1,175 +1,306 @@
|
||||
# Fourth Assignment - Java Knight ⚔️
|
||||
A turn-based RPG with Roguelike elements which can be run in the terminal.
|
||||
# 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**
|
||||
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.
|
||||
A turn-based RPG game written in Java using Object-Oriented Programming (OOP) principles.
|
||||
|
||||
---
|
||||
|
||||
## Tasks 📝
|
||||
# 📖 Story
|
||||
|
||||
### 1️⃣ Step 1: Fork & Setup 🍴
|
||||
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 🌲
|
||||
For centuries, the land of **Javanest** lived peacefully until a powerful Dragon attacked the kingdom and cursed its people.
|
||||
|
||||
A well-structured OOP hierarchy is crucial. Avoid duplicating code by placing shared logic in abstract classes.
|
||||
The curse transformed innocent humans into terrifying monsters such as:
|
||||
|
||||
- **Entities & Locations:** You have `Entity`, `Item`(Bonus) , and `Location`.
|
||||
- **Players:** `Player` is an abstract class implementing `Entity`. Subclasses: `Wizard`, `Knight`, `Assassin`.
|
||||
- **Base Stat Differences:** Each class must have distinct starting stats. For example:
|
||||
- **Knight:** Highest Base Damage.
|
||||
- **Wizard:** Highest Max Health (HP).
|
||||
- **Assassin:** Highest Max Stamina/Mana.
|
||||
- **Enemies:** `Enemy` is an abstract class implementing `Entity`. Subclasses: `Skeleton`, `Goblin`, `Vampire`, and **`Dragon`**.
|
||||
- **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.
|
||||
- **Item (Bonus):** `Consumable`, `Armor`, `Weapon` are abstract classes implementing `Item`. example :
|
||||
- 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
|
||||
- Skeletons ☠️
|
||||
- Goblins 👹
|
||||
- Vampires 🧛
|
||||
|
||||

|
||||
The Dragon hid inside its Castle and divided the three magical keys among the monsters.
|
||||
|
||||
### 3️⃣ Step 3: Implement Player & Monster Methods 🏹
|
||||
Your mission is to:
|
||||
|
||||
**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]
|
||||
- Defeat enemies
|
||||
- Collect all three keys
|
||||
- Become stronger through battles
|
||||
- Enter the Castle
|
||||
- Defeat the Dragon and save Javanest
|
||||
|
||||
---
|
||||
|
||||
Your Turn:
|
||||
1. Light Attack | 2. Heavy Attack (-8 Mana) | 3. Defend (-6 Mana) | 4. Heal (-12 Mana) | 5. Shield Bash (-15 Mana)
|
||||
# 🎮 Game Features
|
||||
|
||||
- Turn-based combat system
|
||||
- Different player classes
|
||||
- Enemy special abilities
|
||||
- Mana/Stamina system
|
||||
- Weapons and armors
|
||||
- Healing system
|
||||
- RPG progression mechanics
|
||||
- Object-Oriented design
|
||||
|
||||
---
|
||||
|
||||
# 🧱 Project Structure
|
||||
|
||||
```text
|
||||
src/
|
||||
└── org.project
|
||||
├── entity
|
||||
│ ├── Entity.java
|
||||
│ ├── enemies
|
||||
│ │ ├── Enemy.java
|
||||
│ │ └── Skeleton.java
|
||||
│ └── players
|
||||
│ ├── Player.java
|
||||
│ └── Knight.java
|
||||
│
|
||||
├── item
|
||||
│ ├── Item.java
|
||||
│ ├── armors
|
||||
│ │ ├── Armor.java
|
||||
│ │ └── KnightArmor.java
|
||||
│ ├── weapons
|
||||
│ │ ├── Weapon.java
|
||||
│ │ └── Sword.java
|
||||
│ └── consumables
|
||||
│ ├── Consumable.java
|
||||
│ └── Flask.java
|
||||
│
|
||||
├── location
|
||||
│ └── Location.java
|
||||
│
|
||||
└── Main.java
|
||||
```
|
||||
|
||||
```bash
|
||||
→ Chose: Light Attack
|
||||
⚔️ Ser Duncan (Knight) used Light Attack! (0 Mana)
|
||||
Goblin took 10 damage!
|
||||
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).
|
||||
---
|
||||
|
||||
# 🧠 OOP Concepts Used
|
||||
|
||||
### 4️⃣ Step 4: Implement the Game Loop & Progression 🎮
|
||||
This project was designed using multiple OOP principles.
|
||||
|
||||
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:
|
||||
## ✅ Inheritance
|
||||
|
||||
- `Knight extends Player`
|
||||
- `Skeleton extends Enemy`
|
||||
- `Sword extends Weapon`
|
||||
- `KnightArmor extends Armor`
|
||||
|
||||
---
|
||||
|
||||
## ✅ Abstract Classes
|
||||
|
||||
Used to avoid duplicated code:
|
||||
|
||||
- `Entity`
|
||||
- `Player`
|
||||
- `Enemy`
|
||||
- `Weapon`
|
||||
- `Armor`
|
||||
- `Consumable`
|
||||
|
||||
---
|
||||
|
||||
## ✅ Interfaces
|
||||
|
||||
The `Item` interface is implemented by:
|
||||
|
||||
- `Weapon`
|
||||
- `Armor`
|
||||
- `Consumable`
|
||||
|
||||
---
|
||||
|
||||
## ✅ Encapsulation
|
||||
|
||||
Important fields such as:
|
||||
|
||||
- HP
|
||||
- Mana
|
||||
- Defense
|
||||
- Durability
|
||||
|
||||
are protected/private and accessed using getters.
|
||||
|
||||
---
|
||||
|
||||
## ✅ Polymorphism
|
||||
|
||||
Methods like:
|
||||
|
||||
- `attack()`
|
||||
- `use()`
|
||||
- `takeDamage()`
|
||||
|
||||
behave differently depending on the object type.
|
||||
|
||||
---
|
||||
|
||||
## ✅ Method Overriding
|
||||
|
||||
Examples:
|
||||
|
||||
- `attack()`
|
||||
- `takeDamage()`
|
||||
- `uniqueAbility()`
|
||||
|
||||
are overridden in subclasses.
|
||||
|
||||
---
|
||||
|
||||
# ⚔️ Player Class
|
||||
|
||||
## Knight
|
||||
|
||||
The Knight is a powerful melee fighter with:
|
||||
|
||||
- High damage
|
||||
- Strong defense
|
||||
- Heavy attacks
|
||||
- Shield abilities
|
||||
|
||||
### Knight Abilities
|
||||
|
||||
- Light Attack
|
||||
- Heavy Attack
|
||||
- Defend
|
||||
- Heal
|
||||
- Special Ability (Shield Bash)
|
||||
|
||||
---
|
||||
|
||||
# 👹 Enemies
|
||||
|
||||
## Skeleton ☠️
|
||||
|
||||
### Special Ability
|
||||
|
||||
Can revive once with 50% HP after dying.
|
||||
|
||||
---
|
||||
|
||||
# 🛡️ Items
|
||||
|
||||
## Weapons
|
||||
|
||||
### Sword ⚔️
|
||||
|
||||
- Deals damage to enemies
|
||||
- Has a special ability attacking multiple targets
|
||||
|
||||
---
|
||||
|
||||
## Armors
|
||||
|
||||
### KnightArmor 🛡️
|
||||
|
||||
- Reduces incoming damage
|
||||
- Has durability system
|
||||
|
||||
---
|
||||
|
||||
## Consumables
|
||||
|
||||
### Flask 🧪
|
||||
|
||||
- Restores player health
|
||||
|
||||
---
|
||||
|
||||
# ❤️ Combat System
|
||||
|
||||
The game uses a turn-based combat system.
|
||||
|
||||
Example combat loop:
|
||||
|
||||
```java
|
||||
while (player.isAlive() && enemy.isAlive())
|
||||
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)*
|
||||
# ▶️ How to Run
|
||||
|
||||
✅ **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.
|
||||
## Compile
|
||||
|
||||
### 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).
|
||||
```bash
|
||||
javac src/org/project/Main.java
|
||||
```
|
||||
|
||||
## Run
|
||||
|
||||
```bash
|
||||
java org.project.Main
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Evaluation Criteria ⚖
|
||||
# ☕ Requirements
|
||||
|
||||
| **Criteria** | **Points** |
|
||||
|-------------------------------------------------------------|------------|
|
||||
| Proper use of OOP principles | **50** |
|
||||
| Working combat mechanics, Leveling System & Enemy abilities | **20** |
|
||||
| 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** |
|
||||
- Java JDK 21 or newer
|
||||
- IntelliJ IDEA or any Java IDE
|
||||
|
||||
## Tips 🚀
|
||||
- **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.
|
||||
- **Test your code**: Run different scenarios (fighting, running out of mana, leveling up, dying) to ensure everything works as expected.
|
||||
- **Ask for help**: If you're stuck, reach out to your classmates or mentors.
|
||||
---
|
||||
|
||||
## 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.
|
||||
# 🎨 Console Output
|
||||
|
||||

|
||||
The game uses terminal messages to display:
|
||||
|
||||
- Attacks
|
||||
- Damage
|
||||
- Healing
|
||||
- Mana usage
|
||||
- Enemy actions
|
||||
|
||||
Example:
|
||||
|
||||
```text
|
||||
⚔️ Knight used Heavy Attack!
|
||||
💀 Skeleton revived with 50% HP!
|
||||
🧪 Flask healed the player!
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
# 🚀 Future Improvements
|
||||
|
||||
Possible future features:
|
||||
|
||||
- Goblin enemy
|
||||
- Vampire enemy
|
||||
- Dragon boss
|
||||
- XP and Level system
|
||||
- Inventory system
|
||||
- Merchant/shop system
|
||||
- Multiplayer mode
|
||||
- PvP mode
|
||||
- ANSI colored terminal output
|
||||
|
||||
---
|
||||
|
||||
# 👨💻 Developer Notes
|
||||
|
||||
This project was developed as the Fourth Assignment for Advanced Programming.
|
||||
|
||||
The main goal of the project is practicing:
|
||||
|
||||
- Clean architecture
|
||||
- OOP design
|
||||
- Java inheritance hierarchy
|
||||
- Combat system implementation
|
||||
|
||||
---
|
||||
|
||||
# 🏆 Final Goal
|
||||
|
||||
Collect all three keys, enter the Castle, defeat the Dragon, and save the land of Javanest.
|
||||
###### - Born of God and Void. You shall seal the blinding light that plagues their dreams. You are the Vessel. You are the Java Knight.
|
||||
Reference in New Issue
Block a user