Having trouble making a function do what I want.
Okay, I'm trying to create a text interface with my console for a blackjack game, I'm trying to make a function called init_output to setup a sort of template for output where certain fields can be updated.
This is the structure defining the "menu" of sorts.
Granted it isn't pretty, but eventually I want to add some serialization to this class and make a text editor that can save these structures to the hard drive, so I can load masses of them for a text adventure or something.
Code:
struct text_menu
{
typedef std::map<int, std::string> tmenu;
text_menu() //Construct Blackjack text interface
{
int id; //declare ID for output item
std::string output; //declare the actual output item
id = 0;
output = "Dealer's Cards";
text.insert(std::make_pair(id, output));
id = 1;
output = "--------------";
text.insert(std::make_pair(id, output));
id = 2;
output = "Nothing Here.";
text.insert(std::make_pair(id, output));
id = 1;
output = "--------------";
text.insert(std::make_pair(id, output));
id = 3;
output = "Player's Cards";
text.insert(std::make_pair(id, output));
id = 1;
output = "--------------";
text.insert(std::make_pair(id, output));
id = 4;
output = "Nothing Here.";
text.insert(std::make_pair(id, output));
id = 1;
output = "--------------";
text.insert(std::make_pair(id, output));
id = 5;
output = "What would you like to do?\n1) Hit me\n2) Stay\n3) Fold\n";
text.insert(std::make_pair(id, output));
}
tmenu text;
};
All I'm doing with that is creating a map of strings and ID's to those strings. I may want to make a list of 0's and 1's for every entry into the map so I know which items are dynamic, or updateable, and which items are static.
Here is the IO class that I will use to manage these structures in massive quantities (eventually), right now I have the structure hard coded but I've realized essentially it's a file type.
Code:
class IO
{
public:
typedef std::map<int, std::string> output;
void update_output(int id, std::string update)
{
output::iterator index = coutput.find(id);
(*index).second = update;
}
void init_output(text_menu text)
{
}
void display_output()
{
for( output::iterator index = coutput.begin(); index != coutput.end(); ++index)
{
cout << (*index).second << std::endl;
}
}
int get_input()
{
std::cin >> input;
return input;
}
void clear_screen()
{
system("cls");
}
output coutput;
int input;
};
#endif
While the update_output function strictly is for usage of the game to update certain complex strings like a players hand or something, if I had a list of 1's and 0's in the structure I could accomplish this better, because then I could return a variable to the system to automatically connect game updates with text updates and such.
Essentially though I'm having trouble with the init_output function. I need to copy the map in tmenu.text over to coutput, I've been googling copy stuff for maps but I havn't found anything that really explained it, can anyone help?