How bolknote/gopnik2 works
Project type and purpose
• This is a monolithic, text-based Hack & Slash RPG written in C++ (“Gopnik-2”).
• It provides a game engine, command interpreter (player actions), hero/enemy modeling, and platform abstraction for Linux/Windows.
File structure
• Top-level:
• CMakeLists.txt – build definition with cmake
• src/ – all C++ source code
• / – public headers (gopnik2 API)
• tests/ – unit/integration tests
• Inside src/:
• main.cpp – program entry point, game loop setup
• game.cpp/h – central Game class, loop tick, state manager
• hero.cpp, hero_type.cpp – player and NPC data models
• comm/ – ~80 command handler source files (one per in-game action) + generic command dispatcher (_sv.cpp, _clsc.cpp, etc.)
• pltl/ – custom template/utility library (pltl0-2.cpp)
• utils.cpp – miscellaneous helpers (logging, parsing, RNG)
• /gopnik2/: mirrors src/ layout; platform.h abstracts OS specifics.
README for additional insights
• Confirms it is a port of an older text-only RPG, upgraded balance and complexity.
• Build instructions rely on cmake and standard compilers.
• No external services, purely local execution.
a. Main components:
1. Entry Point (main.cpp): initializes configuration, logger, Game instance.
2. Game Engine (Game class): manages game loop, state transitions, difficulty, random encounters.
3. Command Processor:
– Command Dispatcher (in src/comm/_*.cpp)
– Individual Command Handlers (a.cpp, b.cpp, …, z.cpp)
4. Data Models: Hero, HeroType, Inventory, Stats, Enemy, World.
5. Utilities & Platform Abstraction (pltl, utils, platform.h)
6. Build & Test System (CMake, tests/test.cpp)
b. Relationships & interactions:
• main → Game: bootstraps engine
• Game ↔ Command Processor: on each tick, Game passes player input to Dispatcher, which calls a specific Handler
• Handlers → Game/Data Models: modify state (hero stats, inventory, world)
• Game → Output: prints to console, reads input
• Utilities support Game and Commands (randomness, string parsing)
c. Architectural patterns and principles:
• Modular command-handler pattern: decouples parsing and action logic
• Single-responsibility: each .cpp in comm/ addresses one action
• Abstraction layer for platform differences
• Layered structure: entry → core engine → domain logic → utilities
d. Key technologies:
• C++17 (or later), STL
• CMake for build orchestration
• pltl: custom template library
• Standard console I/O