Skip to content

A console-based RPG battle system built in C++ demonstrating core OOP principles (Inheritance, Polymorphism) and dynamic memory management.

Notifications You must be signed in to change notification settings

TonyTheSlacker/OOP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 

Repository files navigation

C++ Console RPG: Battle System

Language Paradigm Status

A turn-based role-playing game (RPG) engine running in the console. This project serves as a practical demonstration of Object-Oriented Programming (OOP) in C++, featuring a modular class hierarchy, runtime polymorphism, and dynamic character casting.

Players can choose between PvP (Player vs. Player) or PvE (Player vs. Environment) modes, utilizing unique skills, leveling up, and managing resources (HP/SP).


πŸ—οΈ Key Features

βš”οΈ Game Modes

  • PvE Campaign: Infinite survival mode against randomized enemies (Slimes, Dragons, and even Gods).
  • PvP Duel: Local multiplayer allowing two players to pit different classes against each other.

πŸ›‘οΈ Class System (Polymorphism)

Three distinct character classes derived from a base abstract class, each with unique stats and abilities:

  • Knight: High HP/Strength. Abilities: Power Slash, Shield Block.
  • Wizard: High Magic. Abilities: Fireball, Light of Justice.
  • Assassin: High Agility/Strength. Abilities: Deep Cut, Stealth.

πŸ“ˆ Progression System

  • Leveling Mechanics: XP gain system that scales stats (Strength/Magic) by 20% upon leveling up.
  • Resource Management: Tactical use of Potions and Skill Points (SP) is required to survive longer battles.

πŸ› οΈ Technical Implementation

1. OOP Architecture

The system uses a robust inheritance structure to share logic while allowing unique behaviors.

  • Base Class: Character (Abstract Class with pure virtual functions).
  • Derived Classes: Knight, Wizard, Assassin.
  • Polymorphism: The action() and useSkill() methods are overridden to provide unique gameplay for each class.

2. Dynamic Casting & RTTI

The battle loop uses dynamic_cast to safely determine the specific subclass of a character pointer at runtime, allowing for class-specific logic within a generic loop.

// Snippet from battlePVE function
if (auto knight = dynamic_cast<Knight*>(&player)) {
    damage = knight->action();
}
else if (auto wizard = dynamic_cast<Wizard*>(&player)) {
    damage = wizard->action();
}

3. Memory Management

Uses pointers (Character* player) to manage polymorphic objects.

Explicit delete calls ensure no memory leaks occur when characters are destroyed after battle.

πŸš€ How to Run

  1. Clone the repository: git clone https://github.com/TonyTheSlacker/OOP.git

  2. Open Project: Open the .sln file in Visual Studio.

  3. Compile & Run: Press F5 (or click "Local Windows Debugger").

Compatibility: The code uses standard C++ libraries (, , ) and is cross-compatible, though system("cls") is optimized for Windows.

About

A console-based RPG battle system built in C++ demonstrating core OOP principles (Inheritance, Polymorphism) and dynamic memory management.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages