1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
|
void newgame()
{
cout << "\nPlease type your name here:\n";
string username;
cin >> username;
cout << "\n\nYour name is " << username << ".\n\n";
}
void loadgame()
{
cout << "Load function coming soon!\n";
}
void help()
{
cout << "Simply type the letter in [X].\nFor example in this case 'X'.\nTry to get back to main menu.\n\n[B]ack\n\n";
}
void empty ()
{
cout << "Welcome adventurer!\n\n[N]ew game\n[L]oad game\n[Q]uit\n\nType 'H' to get help.\n\n";
}
int main()
{
map<char,void(*)()> function_map;
function_map.insert(pair<char,void(*)()>('N', newgame));//new
function_map.insert(pair<char,void(*)()>('n', newgame));
function_map.insert(pair<char,void(*)()>('L', loadgame));//Load
function_map.insert(pair<char,void(*)()>('l', loadgame));
function_map.insert(pair<char,void(*)()>('H', help));//help
function_map.insert(pair<char,void(*)()>('h', help));
function_map.insert(pair<char,void(*)()>('B', empty));//Back
function_map.insert(pair<char,void(*)()>('b', empty));
cout << "Welcome adventurer!\n\n[N]ew game\n[L]oad game\n[Q]uit\n\nType 'H' to get help.\n\n";
char input = cin.get();
while (input != 'q') {
if (function_map.find(input) != function_map.end())
function_map[input]();
else
cout << "\"" << input << "\" not found!\n";
cin.ignore(numeric_limits<streamsize>::max(), '\n');
input = cin.get();
}
};//End program
|