1 question is what type? For me there is 2 types, one is where you type commands that are then parsed as you explore the world, the other more simple approach for a beginner is to display a list of options to the player (1. go north 2. go south 3. examine note) etc.
if the latter, what I did was start with a "room" or "area" class, with had pointers to it's links.
1 2 3 4 5 6 7 8 9 10 11 12
|
class room {
public:
std::string name;
std::string desc;
room* north{ nullptr };
room* east{ nullptr };
room* south{ nullptr };
room* west{ nullptr };
std::vector<std::string> menu;
std::vector<std::string> menu_2;
bool seen{ false };
void(*fptr)(room*);
| |
Then in main declare a pointer to keep track of the current room the player is in, give it a starting room then in the game loop call the rooms function pointer, e.g.:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
room* current = starting_room;
void game_loop()
{
while (true)
{
print(current->name);
if (current->seen)
{
current->print_menu_2();
}
else
{
current->print_menu();
}
current->fptr(current);
}
}
| |
Then the rest is easy really, build a player class to store details, inventory etc, a battle class to handle combat based on dice rolls and player vs enemy stats and so on.
For each area you'll probably have a bunch of functions that are executed when the player navigates it's preset menu options. One thing I would recommend though, is that you add sound and use something like NCURSES or PDCURSES to make a proper text interface, as raw command line I/O is a bit lame (just my opinion)