Im trying to create a Text Based Game and i want to have a 'Game Menu'. This is my code but i dont know exactly how to make the menu. Please Help! I also wouldnt mind if some can tell me how i would be able to integrate a cheat into this.

#include "Library.h"

using namespace std;

void Intro();
void RaceClass();
void Cheats();

int main()
{
    
    HANDLE hOut;
    hOut = GetStdHandle (STD_OUTPUT_HANDLE);

    SetConsoleTextAttribute (hOut, FOREGROUND_RED);
    cout << "\t Vitium Victoria \n\n";
    SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN);
    cout << "Programmed by";
    SetConsoleTextAttribute (hOut, FOREGROUND_RED);
    cout << "\t Kile Exley \n";
    SetConsoleTextAttribute (hOut, FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_RED);
    cout << "Written by";
    SetConsoleTextAttribute (hOut, FOREGROUND_RED);
    cout << "\t Bryan Exley\n\n\n";
    
    SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
    Intro();
    
    SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
    cout << "\n\n";
    
    system("PAUSE");
    return 0;
}

void Intro()
{
     
     HANDLE hOut;
     hOut = GetStdHandle (STD_OUTPUT_HANDLE);
     
     char charName[32];
     int userRace;
     int userClass;
     char gmOption;
     
     cout << "Welcome to the world of Vitium Victoria!\n";
     cout << "Here you shall find adventures and horrors alike.\n";
     cout << "The world is brimming with nightmares waiting to be dreamt;\n";
     cout << "treasures and quests waiting to be sought, and fantastical journies to be had!\n\n";
     SetConsoleTextAttribute (hOut, FOREGROUND_RED);
     cout << "\t Game Menu\n";
     SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | BACKGROUND_RED | BACKGROUND_GREEN);
     cout << "1 - New Game\n";
     cout << "2 - Load\n";
     cout << "3 - Cheats\n";
     cin >> gmOption;
     
     if (gmOption == 1)
     {
                  RaceClass();
     }
     if (gmOption == 3)
     {
                  Cheats();
     }
}
     
void RaceClass()
{
     
     HANDLE hOut;
     hOut = GetStdHandle (STD_OUTPUT_HANDLE);
     
     char userRace;
     char userClass;
     char charName;
     
     cout << "What is your name?\n";
     cin >> charName;
     cout << "Hello, ";
     SetConsoleTextAttribute (hOut, FOREGROUND_RED);
     cout << charName;
     cout << "\n\n";
     SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
     
     srand ( time(NULL) );
     
     userRace = rand() % 8 + 1;
     userClass = rand() % 6 + 1;
     
     //Human
     if (userRace == 1 && userClass == 1)
     {
                  cout << "You are a Human/Wizard!\n";
                  cout << "Okay, "<< charName << " your race is Human and your class is Wizard. This information is very important! - You can refer to it at any time by typing 'stats'.";
                  SetConsoleTextAttribute (hOut, FOREGROUND_RED);
                  cout << "8 Health - 17 Mana - 5 Attack\n";
                  SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN);
     }
}
void Cheats()
{
     
     HANDLE hOut;
     hOut = GetStdHandle (STD_OUTPUT_HANDLE);
     
     char cheat;
     char charRace2;
     char charClass2;
     char charPro2;
     
     cout << "Cheat Code:\n";
     cin >> cheat;
     
     if (cheat == 236)
     {
               cout << "You found the Pick Your Own Class and Race cheat!\n";
               cout << "Choose a Race and Class and Profession from below.\n";
               SetConsoleTextAttribute (hOut, FOREGROUND_RED);
               cout << "Races:\n";
               SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | BACKGROUND_RED | BACKGROUND_GREEN);
               cout << "Human\n";
               cout << "Angel\n";
               cout << "Dwarf\n";
               cout << "Troll\n";
               cout << "Demon\n";
               cout << "Goblin\n";
               cout << "Orc\n";
               cout << "Elf\n";
               cin >> charRace2;
               SetConsoleTextAttribute (hOut, FOREGROUND_RED);
               cout << "Classes:\n";
               SetConsoleTextAttribute (hOut, FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN | BACKGROUND_RED | BACKGROUND_GREEN);
               cout << "Wizard\n";
               cout << "Warrior\n";
               cout << "Marksman\n";
               cout << "Thief\n";
               cout << "Rebel\n";
               cout << "Paladin\n";
               cin >> charClass2;
     }
}
Ancient Dragon commented: Thanks for using code tags correctly in your very first post! :) +36

The problem with your menu is that you're reading into a char but testing against an integer. Change gmOption to an int.

I'd finish the rest of the program first before worrying about how you will integrate cheats into it.

BTW, I'd make some consts for the colors, make the console handle global, and use a function to set the color, like so:

HANDLE hOut;

const WORD WHITE = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN;
const WORD BWHITE = BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_GREEN;
const WORD YELLOW = FOREGROUND_RED | FOREGROUND_GREEN;
const WORD BYELLOW = BACKGROUND_RED | BACKGROUND_GREEN;
//etc.

void color(WORD col) {
    SetConsoleTextAttribute (hOut, col);
}

// Call it like this:
color(WHITE|BYELLOW);

Hold on but if i use char gmOption and then have like.

if (gmOption == New Game)
     {
                  RaceClass();
     }
     if (gmOption == Cheats)
     {
                  Cheats();
     }

Would that work? Cuase it doesnt.

if (gmOption == 1) change it to '1' not 1 since gmOption is a char not a int.

cin >> cheat;
if (cheat == 236)

I think the cheat is 236 right? So it should be a string. Define your cheat as char cheat[3 ] and not simply as a char and use the strcmp() in the if statement as: if(strcmp(chear,"236")!=0) While the best way remains to use std::string like this:

string cheat;
cin>>cheat
if (cheat == "236")
{
}

Learn that there is a hell lot of difference between 1 and '1' or between 236 and "236"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.