I'm currently making a text-based adventure game. I just started, and it's a personal project for me to learn C++ more in depth. I was wondering whether the best way to switch "levels" within the game. Should I contain each level in a header file? Should I create functions for each level in the main file? Not really sure what the best way to go about this is, I have very little experience in C++, and I'm wondering what the most highly optimized, or the safest way to go about this is.
This question will probably get closed soon due to SO rules. But in the meantime, this might provide some direction. In mature engines, you would typically not represent different levels with different C++ classes. Instead, things like levels would be data (e.g. data files), and the engine would be data-driven to read that data and present a view of interacting with levels to the player. You would possibly create a new
Level instance initialized with level data, and some high-level level flow described by separate data/scripts that switches what the current level instance is at the right time.
For a very naive first attempt, a different C++ class per level could be a starting point, but it wont scale at all if you don't refactor it to be data driven (depends on scope of game).
You should read a book like Game Engine Architecture to get started.