An immersive C++ and SFML text-based adventure game where strategy, resource management, and critical choices determine your fate.
Welcome to Dungeon Escape! This project is a complete, text-driven adventure game built with C++14 and the SFML multimedia library. It showcases a strong application of Object-Oriented Programming (OOP), custom data structures, and modern C++ features. The player awakens in a dungeon and must navigate a series of dangerous rooms, battle enemies, and make a crucial choice to find the key to their freedom.
- Core Features ✨
- Gameplay Mechanics & Flow ⚔️
- Technical Stack 💻
- System Architecture & Design 🏗️
- How to Build and Run ⚙️
- Modern SFML Interface: A graphical window powered by SFML replaces a standard console, providing a more engaging user experience.
- Animated Visuals: The game features animated menu backgrounds, screen shake effects during combat, and damage flashes to enhance player immersion.
- State-Based Game Management: A robust state machine manages the game's flow between the main menu, name input screen, core gameplay, and the final game-over screen.
- Interactive Dungeon Crawl: Navigate a linear series of interconnected rooms, each with a unique description, background, and a potential encounter—be it a valuable item, a fearsome enemy, or a difficult choice.
- Strategic Turn-Based Combat: The combat system's outcome, especially against the final boss, is directly influenced by the player's preparation and item choices.
- Critical Path Choices: The player must make a single, crucial choice between two powerful items, which directly determines whether victory is possible.
The game is a linear adventure that tests the player's resource management and strategic thinking.
The player progresses through a predefined sequence of rooms:
Entrance -> Wizard's Sanctum -> Dragon's Lair -> Zombie's Crypt -> Chamber of Blades -> Room of Choice -> Monster's Den -> Boss Chamber -> Final Door
Moving between rooms (forward or backward) costs Move points. If the player's Health or Moves drop to zero, the game is lost.
In the Boss Chamber, the player faces the ultimate challenge. The outcome is determined by a key item:
- Without the Ultimate Sword: The boss is overwhelming, dealing a massive 75 HP of damage.
- With the Ultimate Sword: Found in the
Chamber of Blades, the sword's magic awakens, weakening the boss and reducing its damage to a more manageable 50 HP.
In the Room of Choice, the player must choose between a tempting full Health Potion and the Golden Key. While the potion offers immediate survival, the Golden Key is essential to winning the game.
To escape through the Final Door, the player must satisfy two conditions:
- Possess the Golden Key.
- Have defeated the Final Boss.
Failing to meet both conditions upon reaching the door results in being trapped forever—a loss. This design ensures the player must face every major challenge to earn their victory.
- Language: C++14
- Core Library: SFML 2.5.1
SFML/Graphics: For all rendering (sprites, text, window).SFML/Window: For window management and user input.SFML/System: For clocks and vector math.SFML/Audio: For background music.
- C++ Standard Library:
<iostream>,<string>,<sstream><vector>,<map>,<deque><memory>(forstd::unique_ptr)<algorithm>(forstd::sort)<stdexcept>
The project is built on a foundation of clean, modular, and extensible object-oriented code.
| Class | Description |
|---|---|
| Game | The central engine. Manages the main game loop, screens, window, and global state. |
| Player | Represents the user's character, holding health, moves, and inventory. |
| Dungeon | Manages the linked-list structure of Room objects that form the game world. |
| Room | A single node in the dungeon, containing a description, background, and an optional Entity. |
| Entity | Abstract base class for any interactive object in a room (e.g., items, enemies). |
| Item | A concrete Entity representing a collectible item. |
| Enemy | A concrete Entity representing a hostile creature. |
| Screen | Abstract base class for a game state's UI (e.g., menu, gameplay). Defines the core interface. |
| GamePlayScreen | The screen where the primary game logic and player interaction occur. |
| Inventory | A custom template class (dynamic array) to hold the player's items. |
| Stack | A custom template class (linked list) used to track the player's path for backtracking. |
| ResourceManager | A static class for loading and caching assets (fonts, textures) to prevent redundant file I/O. |
The project leverages polymorphism for flexible and decoupled game logic:
- Entity Hierarchy: A
Roomcan hold a pointer to anyEntity(ItemorEnemy). This allows the game to handle interactions polymorphically via the virtualinteract()method without theRoomneeding to know the object's specific type. - Screen Hierarchy: The
Gameclass manages a pointer to the currentScreen. It can callhandleInput(),update(), anddraw()on the current screen without knowing if it's theMenuScreen,GamePlayScreen, orGameOverScreen.
The project uses a mix of custom and standard library data structures for optimal performance and logic.
Stack<T>(Linked List Implementation): Used by theDungeonto track the player's path. When the player moves, the previous room is pushed onto the stack, allowing for an efficientbacktrack()(pop) operation.Inventory<T>(Dynamic Array Implementation): Used by thePlayerto store item names. It automatically resizes itself by doubling its capacity when full, demonstrating dynamic memory management.
std::map: Used heavily in theResourceManagerto cache assets (mapping filenames to textures/fonts) and in theGameclass to mapGameStateIDenums to their correspondingScreenobjects.std::deque: Used in theGamePlayScreento manage theactionsLog. A deque is ideal here for its efficiency in adding new messages to the front.std::sort: This algorithm is used by theInventoryclass to provide an alphabetically sorted list of the player's items for a clean UI display.
This project is built on Windows using the MinGW-w64 toolchain (g++ and mingw32-make). It links to SFML 2.5.1 statically.
- Git: Required to clone the repository.
- MinGW-w64: You need the MinGW-w64 toolchain which provides
g++andmingw32-make. Make sure itsbindirectory is added to your system's PATH. - SFML 2.5.1 (Static): Download the official SFML 2.5.1 release that matches your version of MinGW (e.g., 32-bit or 64-bit). You will need the path to this folder for the setup.
-
Clone the Repository Open your terminal (like PowerShell or Command Prompt) and run:
git clone [https://github.com/Fahad2129/Dungeon-Escape-31659-.git](https://github.com/Fahad2129/Dungeon-Escape-31659-.git) cd Dungeon-Escape-31659- -
CRITICAL: Update the Makefile The provided
Makefilecontains a hardcoded path to the SFML library. You must change this to match the location where you unzipped SFML on your computer.- Open the
Makefilein a text editor. - Find these lines:
compile: g++ -c main.cpp -I"C:\\Users\\Fahad Azfar\\Documents\\libraries\\SFML-2.5.1\\include" -DSFML_STATIC link: g++ main.o -o main -L"C:\Users\Fahad Azfar\Documents\\libraries\\SFML-2.5.1\\lib" \ ...
- Replace both paths (
C:\\Users\\Fahad Azfar\\...) with the correct path to your own SFML folder. - Important: Remember to use double backslashes (
\\) for the path separators.
- Open the
-
Compile the Project In your terminal, from the project's root directory, run the
mingw32-makecommand. This will compile the source code and link the executable.mingw32-make
(If you need to do a fresh build, you can clean up old files first by running
mingw32-make clean) -
Run the Game Once the build is successful, an executable named
main.exewill be created in the directory. Run it with this command:.\main.exe