Learning Python by creating a simple text-based RPG.
Originally started in June 2016, this project was revisited and completely refactored in November 2025 to use modern Python features like dataclasses, properties, and a modular, multi-file structure.
A simple text-based RPG with classes for Heroes, Enemies, and Items, and functions for leveling up, battling, equipping items, and calculating stats. The intent is to expand on RPG functionality as a learning process to understand coding with Python.
The project is built to be modular, separating data (classes, items, enemies), logic (functions, spawning), and presentation (a rich-based UI) into their own files.
Inspired by classic text-based RPGs like Sword of Hope for the Game Boy.
- Modular Project Structure: All data, logic, and UI are decoupled into separate
.pyfiles (classes.py,functions.py,spawn.py,ui.py,items.py,enemies.py). - Rich Console UI: All game output is handled by a dedicated
ui.pymodule that uses therichlibrary to create beautiful, styled panels for profiles, combat logs, and more. - Dynamic Stat System: All Hero stats (
hpMax,atk,dfn,speed,evasion) are calculated on the fly using@propertymethods, allowing equipment to grant real-time bonuses. - Item & Equipment System:
- Create items (weapons, armor, accessories, treasure) using a dedicated
Itemdataclass. - Equip items in
weapon,armour, andaccessoryslots. - Accessories can grant bonuses to any stat, including HP, Speed, and Evasion.
- Create items (weapons, armor, accessories, treasure) using a dedicated
- Turn-Based Combat:
- First Strike: The combatant with the highest
speedattacks first. - Probabilistic Turns: After the first strike, turn order is determined by a percentage chance based on the speed of both combatants.
- Evasion & Defense: Attacks must pass an Evasion check (vs. a 1-100 roll) and then must be strong enough to overcome the defender's
dfnto deal damage.
- First Strike: The combatant with the highest
- Enemy Spawning Factory: A
spawn.pyfile acts as a "factory" to create enemies from templates, makedeepcopycopies, and dynamically add unique, randomized loot. - Loot & Inventory System:
- Defeated enemies drop Gold and
Itemobjects (both equipment and "treasure"). - Loot is added to the Hero's
inventorylist. - A dedicated "Satchel" screen in the UI displays all collected Gold and "treasure" items.
- Defeated enemies drop Gold and
- Leveling: Gain XP from enemies to level up, which increases your Hero's
base_hpMax,base_speed, andbase_evasion.



