Files

315 lines
5.1 KiB
Markdown

# Java Knight ⚔️
A turn-based RPG with Roguelike elements that runs directly in the terminal.
---
### **Introduction**
**Java Knight** is a terminal-based RPG developed in Java that focuses on practicing and applying core **Object-Oriented Programming (OOP)** concepts.
In this game, players choose a hero class and explore dangerous locations filled with monsters. By defeating enemies, players gain experience, level up, and collect special keys needed to unlock the final area of the game: the **Castle**.
Inside the Castle awaits the final boss — the mighty **Dragon**.
The project was designed to demonstrate clean software architecture using concepts such as:
- Inheritance
- Encapsulation
- Polymorphism
- Abstraction
- Method Overriding
- Modular class design
---
# ⚙️ How to Compile and Run
Make sure you have **Java JDK 17+** installed.
### **Compile the Project**
Open a terminal in the project root folder and run:
```bash
javac -d out src/org/project/**/*.java
```
This command compiles all Java source files and stores the compiled classes inside the `out` directory.
---
### **Run the Game**
```bash
java -cp out org.project.Main
```
The game will start in the terminal.
---
# 🧱 Project Structure & Classes
The project follows a modular object-oriented design.
---
## **Main**
The entry point of the application.
Responsibilities:
- Starts the game
- Creates the `Game` object
- Runs the main game loop
---
## **Game**
Controls the entire gameplay flow.
Responsibilities:
- Character selection
- Location selection
- Combat management
- XP and leveling
- Key collection
- Final boss battle
---
## **Entity**
Base class for all living characters in the game.
Shared attributes:
- Name
- Health
- Damage
Both `Player` and `Enemy` inherit from this class.
---
## **Player (Abstract Class)**
Represents the playable character.
Contains common player functionality such as:
- Health
- Mana/Stamina
- Combat actions
- XP system
- Level system
### **Player Classes**
#### **Knight 🛡️**
- High health
- Balanced combat style
- Special ability can stun enemies
#### **Wizard 🔮**
- High mana pool
- Strong magical attacks
- Special ability deals damage and heals
#### **Assassin 🗡️**
- Fast attacks
- High critical damage
- Special ability boosts burst damage
---
## **Enemy (Abstract Class)**
Base class for all enemies.
Each enemy type has unique behavior and abilities.
### **Enemy Types**
#### **Goblin**
- Low HP
- High critical chance
#### **Skeleton**
- Can resurrect once after death
#### **Vampire**
- Steals health from the player
#### **Dragon 🐉**
- Final boss
- Ignores defense abilities
- Deals massive damage
---
## **Location**
Represents explorable areas in the game.
Each location contains one specific enemy type.
### Example Locations
- Dark Forest → Goblin
- Ancient Ruins → Skeleton
- Bloody Swamp → Vampire
---
## **Item**
Represents collectible items such as keys dropped by enemies.
Keys are required to unlock the Castle.
---
## **Colors**
Utility class containing ANSI color codes for colorful terminal output.
---
# 🧠 OOP Principles Used
### **Encapsulation**
Player and enemy stats are protected using methods such as:
```java
takeDamage()
heal()
```
instead of direct field access.
---
### **Inheritance**
Shared behavior is inherited from base classes.
```text
Entity
├── Player
│ ├── Knight
│ ├── Wizard
│ └── Assassin
└── Enemy
├── Goblin
├── Skeleton
├── Vampire
└── Dragon
```
---
### **Polymorphism**
Different classes override methods such as:
```java
attack()
specialAbility()
```
allowing each subclass to behave differently.
---
### **Abstraction**
Abstract classes like `Player` and `Enemy` define shared structure while forcing subclasses to implement specific behavior.
---
# 🎮 How to Play
## **1. Choose Your Class**
At the beginning of the game, choose one of three character classes:
| Class | Description |
|---|---|
| Knight | High defense and balanced damage |
| Wizard | Powerful magic attacks and healing |
| Assassin | Fast attacks and high critical damage |
---
## **2. Choose a Location**
Each location contains a different enemy type.
Example:
- Mordor → Goblins
- Ancient Bones → Skeletons
- Mystic Falls → Vampires
---
## **3. Fight Enemies**
During combat, you can choose from 5 actions:
1. Light Attack
2. Heavy Attack
3. Defend
4. Heal
5. Special Ability
---
## **4. Gain XP and Level Up**
Defeating enemies grants XP.
Leveling up increases:
- Maximum Health
- Maximum Mana/Stamina
---
## **5. Collect Keys 🗝️**
Enemies have a chance to drop unique keys.
You must collect all keys before entering the Castle.
---
## **6. Defeat the Dragon 🐉**
Once all keys are collected, the Castle becomes accessible.
Defeat the Dragon to win the game.
If your HP reaches 0, the game ends.
---
# ✅ Victory Condition
- Collect all keys
- Enter the Castle
- Defeat the Dragon
---
# ❌ Game Over
- Your character dies during battle
---
Good luck, warrior ⚔️