Hi I have been programming for about 3 weeks now and am really starting to get somewhere with it, but I have encountered a problem with this text rpg that I am making, the problem is I have made 3 header files being 1.character(contains character class)
2. monster(another class file for setting stats for monsters) and 3. combat (this is a file that has the combat program in it) and of course my main.cpp.
now the problem I have is that I have set the character variable in the main file (e.g character me;) this lets you give the character a name to the class, but to include character and monster in the combat file I have to set them again at the beginning of it (forcing you to rename your character! grrr), is there any way that I can still include the information in character without having to make a new one??? Ill include all parts as a text file, as itd take alot of room to type it all out. P.S the combat function is no where near being finished as Id like to get this sorted first also Ive tried to use referance but I dont know wether it worked.

Any help appreciated :icon_cool:

PSS youll have to right click save target as to get the files for some reason, sorry about that

Attachments
#ifndef CHARACTER_H_INCLUDED
#define CHARACTER_H_INCLUDED

#include <string>
#include <iostream>

using namespace std;

class character
{
    public:
        character();
        ~character(){};
        int getHP() {return hp;};
        void setHP(int _hp) {hp= _hp;};
        string getName(){return name;};
        int getExp(){return exp;};
        void setExp(int _exp){exp=_exp;};
        int getStr(){return str;};
        void sendStr(int& _str){_str=str;};
        void setStr(int _str){str= _str;};
        int getMP() {return mp;};
        void setMP(int _mp) {mp= _mp;};
        int getLvl(){return lvl;};
        void setLvl(int _lvl) {lvl= _lvl;};
        int getDef(){return def;};
        void sendDef(int& _def){_def=def;};
        void setDef(int _def) {def= _def;};
    protected:
        int hp;
        string name;
        int exp;
        int str;
        int mp;
        int lvl;
        int def;
};
character::character()
{
    cout<<"Please give your character a name: "<<endl;
    cin>>name;
     hp=100;
     exp=0;
     str=20;
     mp=20;
     lvl=1;
     def=10;
}

#endif
#ifndef COMBAT_H_INCLUDED
#define COMBAT_H_INCLUDED
#include "monster.h"
#include "character.h"
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

using namespace std;

int combat()
{   int dif;
    int damage;
    character me;
    monster it;
    int sel;

    cin.get();
    cout<<"1.attack\n";
    cout<<"2.defend\n";
    cout<<"3.magic\n";
    cout<<"4.item\n";
    cin>>sel;



    if (sel==1)
    {
        srand ( time(NULL) );
        dif= me.getStr() - it.getDef2();
        damage=rand() %me.getStr()+dif;
        cout<<"You viciously lunge"<<endl;
        cout<<"doing "<<damage<<" damage"<<endl;


    };
    if (sel==2)
    {
        cout<<"You brace yourself for an attack"<<endl;
    };
    if (sel==3)
    {
    };
    if (sel==4)
    {
    };

};



#endif // COMBAT_H_INCLUDED
#include <iostream>
#include "character.h"
#include "monster.h"
#include "combat.h"

using namespace std;

int main(int argc, char* argv[])
{
    cout << "Welcome to the Game"<<endl;

    character me;
    cout << "Welcome "<<me.getName() <<" ,you have been given.\n"<<
    me.getHP()<<" hp.\n"<< me.getStr()<<" strength.\n"<<me.getMP()<<" mp\n"<<me.getDef()<<" defense\n"<<endl;

    cout << "You begin your quest in the training academy, in Ashveldt.\n"<<
    "Today is a big day for you as you are finally going to pass your training.\n"<<
    "But you still have one final test waiting for you, a fight with a beast chosen\n"<<
    "by your instructor Ivor to be the greatest challenge yet."<<endl;
    cin.get();

        int ansA;

    cout<< "Ivor: Good morning "<<me.getName() <<" are you ready for the trial?"<<endl;
    cout<< "1. Yes, I was born ready!!\n"<< "2. Im feeling a bit apprehensive.\n" <<
    "3. No not at all."<<endl;
    cin>>ansA;

    if (ansA==1)
    {
        cout<<"Ivor: Good glad to hear it, but beware this is not going to be easy\n"<<
        "Ivor: Get ready, you have 10 minutes Good luck"<<endl;
    }

    else if (ansA==2)
    {
        cout<<"Ivor: Dont worry "<<me.getName() << " I have trained you best I can\n"<<
        "you are ready for this, you have 10 minutes. Good luck"<<endl;
    }

    else if (ansA==3)
    {
        cout<<"Ivor: Thats not a good sign. \\Ivor looks at you with a slight hint of shame\\ \n"<<
        "you have 10 minutes. Good luck"<<endl;
    }

cin.get();

    cout<<"You enter the training arena, the gates open...\n"<<endl;
    cout<<"(press return)"<<endl;
    monster it;

    cout<<"It has "<<it.getHP2()<<"hp "<<it.getMP2()<<"mp "<<it.getStr2()<<"str "<<it.getDef2()<<"defense"<<endl;
    cout<<"FIGHT!!!!"<<endl;

combat();





    return 0;
}
#ifndef MONSTER_H_INCLUDED
#define MONSTER_H_INCLUDED

using namespace std;

class monster
{
    public:
        monster();
        ~monster(){};
       int getHP2(){return hp2;};
       void sendHP2(int& _hp2){_hp2=hp2;};
       int getMP2(){return mp2;};
       void sendMP2(int& _mp2) {_mp2=mp2;};
       int getStr2(){return str2;};
       void sendStr2(int& _str2){_str2= str2;};
       void setStr2(int _str2){_str2=str2;};
       string getName2(){return name2;};
       void sendDef2(int& _def2){_def2=def2;};
       void setDef2(int _def2){_def2=def2;};
       int getDef2(){return def2;};

    protected:
        int hp2;
        int mp2;
        int str2;
        string name2;
        int def2;

};

monster::monster()
{
    cout<<"\n";
    cin.get();
    cout<<"You are faced by a vicious beast"<<endl;
    hp2=30;
    mp2=10;
    str2=10;
    def2=10;
};



#endif // MONSTER_H_INCLUDED

sorry guys solved this one myself :) for those that are interested, I moved the naming line into the main cpp andd declared it as a variable there so getting rid of the problem

This question has already been answered. Start a new discussion instead.