For now I've done a function that creates menus and prints them, and a function that creates the character as an object.
Now I want to be able to show the stats of the player on the main menu, the problem is that I don't know how to make a copy of the map as it's private...
The code is probably a mess, I hope you guys understand it... thanks!
Where am I supposed to put this code? And I don't really understand it... could you explain it a bit please? I just don't understand the "zero" 0 "one" 1, etc.
The map saved_stats is initialised to contain the following three entries:
1. key (string): "zero" mapped value (int): 0
2. key (string): "one" mapped value (int): 1
3. key (string): "two" mapped value (int): 2
And isn't there any way of creating a global object? Let's say I create new_player::player and then access that object in any function.
Because later on I will need to be accessing the info in that object and I will be changing the values of the player as he get's more exp and levels up...
If it's not possible, then how could I do that? Create the object and then access it with pointers? Sounds tedious
new_player is a class, it represents a character inside the game. It has a map wich has the stats (strength, armor, etc.) it has a name and some functions to access the name and map as they are private.
The game represents a fighting simulator 1v1; if the player wins the fight, he gains experience and gold wich has to be saved on the map (player.stats) so what I need to do is create this player object and be able to access it whenever I want; meaning that I want to be able to access its information (stats and name) and change them if I need to.
If the program is big, you can reduce coupling by:
defining name and stats with internal linkage (make them programatically invisible outside player.cpp),
and provide functions to access and update them.
///////// player.h ////////////
// ...
struct player
{
std::string name ;
std::map<std::string,int> stats ;
static player& instance( /* ... */ ) ; // public access to the only instance of player
private: player() = default ; // constructor is visible, but not publicly accessible
player( const player& ) = delete ; // non-copyable
};