I need to implement inheritance and abstract class functions my C++ rpg fantasy combat program. What are some suggestions for enhancing the code?

  abstract, c++, inheritance, virtual-functions

Here is the code for the project, I need to work at implementing inheritance for it.
I would like to have some virtual functions and make it a class driven program which uses derived classes and has a base class. The derived clase should inherit the features from the base class and utilize the extra features.

#include <iostream>
#include <cmath>
#include <climits>
#include <string>
#include "Mastermega.h"
#include "EquipmentStore.h"
using namespace std;

int main()
{
    cout<<"Welcome to Master Mage Tournamentn";
    Mastermega m;
    EquipmentStore eq;
    m.gamesimulation();
    eq.equip_store();
    return 0;
}

////mastermega.h

#ifndef MASTERMEGA_H
#define MASTERMEGA_H
#include <string>
using namespace std;

class Mastermega
{
    public:
        string PlayerName;
        int PlayerHealth = 10;
        int PlayerHealthArmor = 0;
        int PlayerArmor = 0;
        int PlayerExperience = 0;
        int PlayerLevel = 1;
        int PlayerMoney = 2100;
        int PlayerWeapon = 1;
        int PlayerDamage = 1;
    void gamesimulation();
    void intro();
    void mainmenu();
    void arena();
    void fight();
    void store();
    void stats();
    void about();
    void experiencecheck();
    void weaponcheck();
    void savegame();
    void loadgame();
    void newPlayer();
};

#endif

/////mastermega.cpp

#include <iostream>
#include <cmath>
#include <climits>
#include <string>
#include <time.h>       /* time */
#include <unistd.h>
#include <stdio.h>
#include <string>
#include <conio.h>
#include <fstream>
#include <sstream>
using namespace std;
#include "Mastermega.h"
#include "arena.h"
Arena a;

void Mastermega::gamesimulation()
{
    intro();
    mainmenu();
}
void Mastermega::intro()
{
cout << "3[2J3[1;1H";//clear screen in onlinggdb
system("cls");//clear screen in codeblocks compiler
    cout<<"ntt#     #                                                                "<< endl;
 cout<<" tt##   ##   ##    ####  ##### ###### #####                               "<< endl;
 cout<<" tt# # # #  #  #  #        #   #      #    #                              "<< endl;
 cout<<" tt#  #  # #    #  ####    #   #####  #    #                              "<< endl;
 cout<<" tt#     # ######      #   #   #      #####                               "<< endl;
 cout<<" tt#     # #    # #    #   #   #      #   #                               "<< endl;
 cout<<" tt#     # #    #  ####    #   ###### #    #                              "<< endl;
 cout<<"                                                                        "<< endl;
 cout<<" #######                                                                "<< endl;
 cout<<"    #     ####  #    # #####  #    #   ##   #    # ###### #    # #####  "<< endl;
 cout<<"    #    #    # #    # #    # ##   #  #  #  ##  ## #      ##   #   #    "<< endl;
 cout<<"    #    #    # #    # #    # # #  # #    # # ## # #####  # #  #   #    "<< endl;
 cout<<"    #    #    # #    # #####  #  # # ###### #    # #      #  # #   #    "<< endl;
 cout<<"    #    #    # #    # #   #  #   ## #    # #    # #      #   ##   #    "<< endl;
 cout<<"    #     ####   ####  #    # #    # #    # #    # ###### #    #   #    "<< endl;
 cout<<"                                                                        "<< endl;
 cout<<"tt    #                                                                   "<< endl;
 cout<<"tt   # #   #####  ###### #    #   ##                                      "<< endl;
 cout<<"tt  #   #  #    # #      ##   #  #  #                                     "<< endl;
 cout<<"tt #     # #    # #####  # #  # #    #                                    "<< endl;
 cout<<"tt ####### #####  #      #  # # ######                                    "<< endl;
 cout<<"tt #     # #   #  #      #   ## #    #                                    "<< endl;
 cout<<"tt #     # #    # ###### #    # #    #                                    n"<< endl;


  cout << R"(
Master Mage Arena                 |>>>
----------------                  |
                    |>>>      _  _|_  _         |>>>
                    |        |;| |;| |;|        |
                _  _|_  _    .    .  /    _  _|_  _
               |;|_|;|_|;|    :. ,  /    |;|_|;|_|;|
               ..      /    ||;   . |    .    .  /
                .  ,  /     ||:  .  |     :  .  /
                 ||:   |_   _ ||_ . _ | _   _||:   |
                 ||:  .|||_|;|_|;|_|;|_|;|_|;||:.  |
                 ||:   ||.    .     .      . ||:  .|
                 ||: . || .     . .   .  ,   ||:   |       ,/
                 ||:   ||:  ,  _______   .   ||: , |            /`
                 ||:   || .   /+++++++    . ||:   |
                 ||:   ||.    |+++++++| .    ||: . |
              __ ||: . ||: ,  |+++++++|.  . _||_   |
     ____--`~    '--~~__|.    |+++++__|----~    ~`---,              ___
-~--~                   ~---__|,--~'                  ~~----_____-~'   `~----~~

    )" << endl;
 cout << "n Press enter to fight in the Arena..." << endl;
 std::cin.get();
}

void Mastermega::mainmenu()
{
    experiencecheck();
//  a.getinfo();
cout << "n Press enter to go to the Main Menu..." << endl;
 std::cin.get();
    short int choice;
 system("clear");
    cout << "nnttWelcome to the arena " << PlayerName << "!nn";

    //MENU
        cout << "n0) New Player n1) Arena n2) Store n3) Statistics n4) Aboutn5) Save Gamen6) Load Gamen7) Exitnn";
    cout << "Menu Choice: ";
    cin >> choice;



    //CHECKS MENU CHOICE
    
    if (choice == 1)
    {

        arena();
    }
    else if (choice == 2)
    {

        store();
    }
    else if (choice == 3)
    {

        stats();
    }
    else if (choice == 4)
    {

        about();
    }
    else if (choice == 5)
    {

        savegame();
    }
    else if (choice == 6)
    {

        loadgame();
    }
    else if (choice == 7)
    {
exit(0);
        
    }
    else if (choice == 0)
    {

        newPlayer();
    }



}

void Mastermega::newPlayer(){
    cout <<"n-New Player-n" << endl;
    cout <<"What is your player's name?"<<endl;
    cin >> PlayerName;
    system("clear");
    cout <<"nHere are your stats:n";
    //get name
    // make name
    //PlayerName = 
    //show stats
    stats();
    std::cin.get();
    
}

void Mastermega::store()
{
    int menuchoice;

    cout << "---Welcome to the Store--- nnn";

    cout << "Your Gold: "<< PlayerMoney <<"nn";

    cout << "Weapons Available: nn";
    cout << "1)  Fire Staff +1: $40n"; // Extra Damage: 1
    cout << "2)  Poison Staff +2: $50n";  // Extra Damage: 2
    cout << "3)  Lightning Staff +3: $80n";  // Extra Damage: 3
    cout << "4)  Ice Staff +4: $150nn";  // Extra Damage: 4

    cout << "Armor: nn";
    cout << "5)  +5 Armor: $50n"; // Reduce damage to self by 5
    cout << "6)  +10 Armor: $100nn"; // Reduce damage to self by 10

    cout << "7) Play Menu: 7nnn"; // Goes back to prior menu

    cout << "Select an option: ";
    cin >>menuchoice;

    //balance check
    if(menuchoice == 1)
    {
        if(PlayerMoney < 40)
        {

            cout << "Not enough money, returning to main menu";
            system("PAUSE");

            mainmenu();
        }
        else
        {

            cout << "Thanks for you business!nn";
            system("PAUSE");

            PlayerMoney -= 40;
            PlayerWeapon = 1;
            mainmenu();

        }
    }
    else if(menuchoice == 2)
    {
        if(PlayerMoney < 50)
        {

            cout << "Sorry, not enough cash";
            system("PAUSE");

            mainmenu();
        }
        else
        {

            cout << "Transaction made!nn";
            system("PAUSE");

            PlayerMoney -= 50;
            PlayerWeapon = 2;
            mainmenu();
        }
    }
    else if(menuchoice == 3)
    {
        if(PlayerMoney < 80)
        {

            cout << "Sorry, not enough cash";
            system("PAUSE");

            mainmenu();
        }
        else
        {

            cout << "Transaction made!nn";
            system("PAUSE");

            PlayerMoney -= 80;
            PlayerWeapon = 3;
            mainmenu();
        }
    }
    else if(menuchoice == 4)
    {
        if(PlayerMoney < 150)
        {

            cout << "Transaction made";
            system("PAUSE");

            mainmenu();
        }
        else
        {

            cout << "Transaction made!nn";
            system("PAUSE");

            PlayerMoney -= 150;
            PlayerWeapon = 4;
            mainmenu();
        }
    }
    else if(menuchoice == 5)
    {
        if(PlayerMoney < 50)
        {

            cout << "Sorry, not enough cash";
            system("PAUSE");

            mainmenu();
        }
        else
        {

            cout << "Transaction made!nn";
            system("PAUSE");

            PlayerMoney -= 50;
            PlayerArmor += 5;
            mainmenu();
        }

    }
    else if(menuchoice == 5)
    {
        if(PlayerMoney < 100)
        {

            cout << "Sorry, not enough cash";
            system("PAUSE");

            mainmenu();
        }
        else
        {

            cout << "Transaction made!nn";
            system("PAUSE");

            PlayerMoney -= 100;
            PlayerArmor += 10;
            mainmenu();
        }
    }
    if (menuchoice == 7)
    {

        cout << "You are through shopping.nn";
        system("PAUSE");

        mainmenu();
    }
}

void Mastermega::stats()
{
    experiencecheck();
    weaponcheck();

    cout << "Stats: nnn";

    cout << "Name: " << PlayerName<<"n";
    cout << "Health: " << PlayerHealth<<"n";
    cout << "Armor: " << PlayerArmor<<"n";
    cout << "EXP: " << PlayerExperience<<"n";
    cout << "Level: " << PlayerLevel << "n";
    cout << "Money: " << PlayerMoney<<"n";
    cout << "Damage: " << PlayerDamage << "n";

    //Shows Weapon
    if (PlayerWeapon == 1)
    {
        cout << "Weapon: fire staffnn";
    }
    else if (PlayerWeapon == 2)
    {
        cout << "Weapon: poison staffnn";
    }
    else if (PlayerWeapon == 3)
    {
        cout << "Weapon: lightning staffnn";
    }
    else if (PlayerWeapon == 4)
    {
        cout << "Weapon: ice staffnn";
    }
    else if (PlayerWeapon == 5)
    {
        cout << "Weapon: megastaffnn";
    }
cout << "Press Enter..."<<endl;
    //back to menu
std::cin.get();
//  system("PAUSE");

    mainmenu();
}

void Mastermega::about()
{
        cout << "Game by Gabriel Sharp.. In order to play you must choose an option:nn";
cout << "Arena: You will fight a random monsternn";
cout << "Store: You can upgrade your weapons and armor which cause more damage and protect younn";
cout << "Experience is gained by killing monsters and you will cause more damage:nn";


printf("Press enter to continue...n"); 
std::cin.get();
//  system("PAUSE");

    mainmenu();
}

void Mastermega::savegame()
{
    cout << "n-1) Save New Game -n2) Overwrite Save Game -" << endl;
    
        cout << "Menu Choice: ";
        short int choice;
    cin >> choice;

    // menu options
    
    if (choice == 1)
    {
ofstream myfile ("savefile.txt"); 

  if (myfile.is_open()) 

  { 

myfile<< "ttt" << PlayerName << " " << PlayerHealth << " " << PlayerArmor <<" " << PlayerExperience <<" " << PlayerLevel <<" " << PlayerDamage <<" " << PlayerWeapon <<  "n"; 

    myfile.close(); 
    cout << "nt--Game Saved--t" << endl;
    //cout << "n Press enter to go to the Main Menu..." << endl;
 std::cin.get();

  } 

  else cout << "Unable to open file"; 
  //cout << "n Press enter to go to the Main Menu..." << endl;
 std::cin.get();
 
 mainmenu();
        
    }
    else if (choice == 2)
    {
cout << "Truncate" << endl;

/////////
 std::ofstream ofs("savefile.txt", std::ofstream::trunc);

   ofs << PlayerName << " " << PlayerHealth << " " << PlayerArmor <<" " << PlayerExperience <<" " << PlayerLevel <<" " << PlayerDamage <<" " << PlayerWeapon <<  "n"; 


   ofs.close();
////////
cout << "nttGame Saved" << endl;
std::cin.get();
mainmenu();
        
    }
    
    
    
    
 
}

void Mastermega::loadgame() 
{
    cout <<"n- Load Game? -" << endl;
    
    ifstream inputFile("savefile.txt");
    string line;

    while (getline(inputFile, line))
    {
        istringstream ss(line);

        string name;
         ss >> PlayerName >> PlayerHealth >> PlayerArmor >> PlayerExperience >> PlayerLevel >> PlayerDamage >> PlayerWeapon ; 

        cout << PlayerName << ", " << PlayerHealth << ", " << PlayerArmor <<", " << PlayerExperience <<", " << PlayerLevel <<", " << PlayerDamage <<", " << PlayerWeapon << endl; 

    } 
    cout <<"ntt--Game Loaded--n"<<endl;
    cout << "n Press enter to go to the Main Menu..." << endl;
 std::cin.get();
 
    mainmenu();
}




//experiencecheck
void Mastermega::experiencecheck()
{/*

    }*/
}

void Mastermega::weaponcheck()
{
    if (PlayerWeapon == 1)
    {
        PlayerDamage = 5;
    }
    else if (PlayerWeapon == 2)
    {
        PlayerDamage = 10;
    }
    else if (PlayerWeapon == 3)
    {
        PlayerDamage = 15;
    }
    else if (PlayerWeapon == 4)
    {
        PlayerDamage = 20;
    }
    else if (PlayerWeapon == 5)
    {
        PlayerDamage = 25;
    }
}

///FIGHT
void Mastermega::arena()
{
    short int menuchoice;



    //Starting Battle
    cout << "nnHere you will fight nn";
    cout << "Fight: 1";
    cout << "nMain Menu: 2nnChoice: ";
    cin >> menuchoice;
    if(menuchoice == 1)
    {
        fight();
    }
    else if(menuchoice == 2)
    {

        mainmenu();
    }
}

void Mastermega::fight()
{
//
//
    short int monster = 1;
    int monsterhealth = 0;
    int monsterdamage = 0;

    weaponcheck();

    PlayerHealthArmor = PlayerHealth + (PlayerArmor/2); //Armor Rating


srand (time(NULL));
monster = rand() % 5 + 1;     // v2 in the range 1 to 100
//  monster = 1;

    if (monster == 1)//
    {
        cout << "A goblin attacks...nn";
         cout << R"(
              ,      ,
            /(.-""-.)
        |  /      /  /|
        |  / =.  .=  / |
        (    o/o   / )/
         _, '-/  -' ,_/
           /   __/   
            __/__/ /
         ___ |--|/ /___
       /`          /    `
      /       '----'       
    )" << endl; //
        system("PAUSE");


        monsterhealth = 5;
        monsterdamage = 5;

        cout << "Goblin defeated!nn";
        system("PAUSE");


        PlayerExperience += 20;
        PlayerMoney += 50;
cout << "Experience" << PlayerExperience << "--> " << endl;
cout << "Money" <<  PlayerMoney << "--> " << endl;
        arena();
    }
    else if(monster == 2)//
    {
        cout << "Fight a giant scorpion...nn";
         cout << R"(
                ___ __
     _{___{__}
    {_}      `)
   {_}        `            _.-''''--.._
   {_}                    //'.--.  ___`.
    { }__,_.--~~~-~~~-~~-::.---. `-.  `.)
     `-.{_{_{_{_{_{_{_{_//  -- 8;=- `
        `-:,_.:,_:,_:,.`._ ..'=- ,
            // // // //`-.``   .-'/
           << << << <<     `--'  /----)
            ^  ^  ^  ^     `-.....--'''

    )" << endl; //
        system("PAUSE");


        monsterhealth = 10;
        monsterdamage = 10;

        cout << "Scorpion dies!nn";
        system("PAUSE");


        PlayerExperience += 25;
        PlayerMoney += 100;
cout << "Experience" << PlayerExperience << "--> " << endl;
cout << "Money" <<  PlayerMoney << "--> " << endl;
        arena();
    }
    else if(monster == 3)//
    {
        cout << "Fight a giant spider...nn";
         cout << R"(

        /  .-"""-.  /
       ///  ,,,  //
       |/| ,;;;;;, |/|
       //\;-"""-;///
      //  /   .   /  
     (| ,-_|  | / |_-, |)
       //`__.-.-./__`
      // /.-(() ())-. 
     ( |)   '---'   (| /)
      ` (|           |) `
        )           (/

    )" << endl; //
        system("PAUSE");


        monsterhealth = 10;
        monsterdamage = 10;

        cout << "Spider Dies!nn";
        system("PAUSE");


        PlayerExperience += 25;
        PlayerMoney += 100;
cout << "Experience" << PlayerExperience << "--> " <<  endl;
cout << "Money" <<  PlayerMoney << "--> " << endl;
        arena();
    }
    else if(monster == 4)//
    {
        cout << "Ork attacks...nn";
         cout << R"(
                   (    )
                  ((((()))
                  |o /o)|
                  ( (  _')
                   (._.  /__
                  ,___,/ '  ')
    '.,_,,       (  .- .   .    )
             ( '        )(    )
             .  _.__ ____( .  |
         /   .(   .'  /  '.  )
        (  .-' ( /    /    )
         '  ()) _'.-|/////|
             ' .( |/////|
               '((      /    /
               ((((  '.__/__.')
                ((,) /   ((()   )
                 "..-,  (()("   /
            pils  _//.   ((() ."
          _____ //,/" ___ ((( ', ___
                           ((  )
                            / /
                          _/,/'
                        /,/,"

    )" << endl; //
        system("PAUSE");


        monsterhealth = 10;
        monsterdamage = 10;

        cout << "Ork Dies!nn";
        system("PAUSE");


        PlayerExperience += 25;
        PlayerMoney += 100;
cout << "Experience" << PlayerExperience << "--> " <<  endl;
cout << "Money" <<  PlayerMoney << "--> " << endl;
        arena();
    }
    else if(monster == 5)//
    {
        cout << "Fight a necromancer...nn";
         cout << R"(
              _,._
  .||,       /_ _
 .`',/      |'L'| |
 = ,. =      | -,| L
 / ||     ,-'"/,'`.
   ||     ,'   `,,. `.
   ,|____,' , ,;' | |
  (3|    _/|/'   _| |
   ||/,-''  | >-'' _,
   ||'      == ,-'  ,'
   ||       |  V  ,|
   ||       |    |` |
   ||       |    |   
   ||       |        
   ||       |     |    
   ||       |      _,-'
   ||       |___,,--")_
   ||         |_|   ccc/
   ||        ccc/
    )" << endl; //
        system("PAUSE");


        monsterhealth = 10;
        monsterdamage = 10;

        cout << "Necromancer dies!nn";
        system("PAUSE");


        PlayerExperience += 25;
        PlayerMoney += 100;
cout << "Experience" << PlayerExperience << "--> " <<  endl;
cout << "Money" <<  PlayerMoney << "--> " << endl;
        arena();
    }
}

////EquipmentStore.h
#ifndef EQUIPMENTSTORE_H
#define EQUIPMENTSTORE_H
#include <string>
using namespace std;
#include "Mastermega.h"

class EquipmentStore: public Mastermega {
    public:
        void equip_store();
};

#endif
/////EquipmentStore.cpp

#include <iostream>
#include <cmath>
#include <climits>
#include <string>
using namespace std;
#include "EquipmentStore.h"
#include "Mastermega.h"

void EquipmentStore::equip_store()
{

    cout << "nn---Welcome to the Store--- nnn";
    cout << "Your Gold: "<< PlayerMoney <<"nn";
    cout << "Weapons Available: nn";
    cout << "1)  Fire Staff +1: $40n"; // Extra Damage: 1
    cout << "1)  Poison Staff +2: $50n";  // Extra Damage: 2
    cout << "2)  Lightning Staff +3: $80n";  // Extra Damage: 3
    cout << "3)  Ice Staff +4: $150nn";  // Extra Damage: 4

    cout << "Armor: nn";
    cout << "4)  +10 Armor: $50n"; // Reduce damage to self by 5
    cout << "5)  +20 Armor: $100nn"; // Reduce damage to self by 10

    cout << "7) Play Menu: 7nnn"; // Goes back to prior menu
    int menuchoice;
    cout << "Select an option: ";
    cin >>menuchoice;

    //balance check
    if(menuchoice == 1)
    {
        if(PlayerMoney < 40)
        {

            cout << "Sorry, you do not have enough Gold, return to play menu.";
            cin.get(); // Pause Screen
            mainmenu();
        }
    }
    else if(menuchoice == 2)
    {
        if(PlayerMoney < 50)
        {

            cout << "Sorry, you do not have enough Gold, return to play menu.";
            cin.get(); // Pause Screen
            mainmenu();
        }
    }
    else if(menuchoice == 3)
    {
        if(PlayerMoney < 80)
        {

            cout << "Sorry, you do not have enough Gold, return to play menu.";
            cin.get(); // Pause Screen
            mainmenu();
        }
    }
    else if(menuchoice == 4)
    {
        if(PlayerMoney < 150)
        {

            cout << "Sorry, you do not have enough Gold, return to play menu.";
            cin.get(); // Pause Screen
            mainmenu();
        }
    }
    else if(menuchoice == 5)
    {
        if(PlayerMoney < 50)
        {

            cout << "Sorry, you do not have enough Gold, return to play menu.";
            cin.get(); // Pause Screen
            mainmenu();
        }
    }
    else if(menuchoice == 6)
    {
        if(PlayerMoney < 100)
        {

            cout << "Sorry, you do not have enough Gold, return to play menu.";
            cin.get(); // Pause Screen
            mainmenu();
        }
    }

    if (menuchoice == 7)
    {

        cout << "Exit to Play Menu.nn";
        cin.get(); // Pause Screen


        mainmenu();
    }
    if(menuchoice == 1)
    {
        system("CLS");
        cout << "Fire Staff Purchased!nn";
        cin.get(); // Pause Screen
        system("CLS");

        PlayerMoney -= 40;//money is reduced
        PlayerWeapon = 2;//damage will be 2 from now on

        mainmenu();
    }
    else if(menuchoice == 2)
    {
        system("CLS");
        cout << "Poison Staff Purchased!nn";
        cin.get(); // Pause Screen
        system("CLS");

        PlayerMoney -= 50;
        PlayerWeapon = 3;

        mainmenu();
    }
    else if(menuchoice == 3)
    {
        system("CLS");
        cout << "Lightning Staff Purchased!nn";
        cin.get(); // Pause Screen
        system("CLS");

        PlayerMoney -= 80;
        PlayerWeapon = 4;

        mainmenu();
    }
    else if(menuchoice == 4)
    {
        system("CLS");
        cout << "Ice Staff Purchased!nn";
        cin.get(); // Pause Screen
        system("CLS");

        PlayerMoney -= 150;
        PlayerWeapon = 5;

        mainmenu();
    }
    else if(menuchoice == 5 || 6 )//armor
    {
        system("CLS");
        cout << "Armor Purchased!nn";
        cin.get(); // Pause Screen
        system("CLS");

        if(menuchoice == 5)
        {
            PlayerMoney -= 50;
            PlayerArmor += 5; // damage reduced by 2
        }
        else if(menuchoice == 6)
        {
            PlayerMoney -= 100;
            PlayerArmor += 10; //damage reduced by 5
        }

        mainmenu();
    }
}

Source: Windows Questions C++

LEAVE A COMMENT