0

hi all, this is the same game (if you can call it that yet) that I asked for help with last time (but I sorted it out myself) this time the problem is getting hp off of a monster/character in the combat header Ive already got a damage function that works out how much hp to take off, and wether its a critical hit, the problem is that they are all in different headers and I cant get the referance function to work properly (I think) the fuction that Im tring to get to work is in comment so it will compile anyway. any help appreciated
PS same as last time, to view the files, right click save as, otherwise they dont seem to work!!!

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;};
        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;
        int exp;
        int str;
        int mp;
        int lvl;
        int def;
};
character::character()
{
     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 amount;
    character me;
    monster it;
    int sel;
        cout<<"It has "<<it.getHP2()<<"hp "<<it.getMP2()<<"mp "<<it.getStr2()<<"str "<<it.getDef2()<<"defense"<<endl;
    cout<<"FIGHT!!!!"<<endl;
    cout<<"(press return)"<<endl;

    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();
        amount=rand() %me.getStr()+dif;
        if (amount>=me.getStr())
        {
            cout<<"CRITICAL HIT!!"<<endl;
        };
        cout<<"You viciously lunge"<<endl;
        cout<<"doing "<<amount<<" damage"<<endl;
        //it.setHP2()=it.getHP2()-amount; if (it.getHP2()>=0){return 0;}; //this is my idea of how to get it off, but it doesnt work :S
        cout<<"Monster now has "<<it.getHP2()<<" hp"<<endl;//this is proving that hp isnt coming off



    };
    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[])
{
    string name;

    cout << "Welcome to the Game"<<endl;

    character me;
    cout<<"Please give your character a name: "<<endl;
    cin>>name;
    cout << "Welcome "<<name <<" ,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 "<<name <<" 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 "<<name << " 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;

combat();





    return 0;
}
#ifndef MONSTER_H_INCLUDED
#define MONSTER_H_INCLUDED


using namespace std;

class monster
{
    public:
        monster();
        ~monster(){};
       int getHP2(){return hp2;};
       void setHP2(int _hp2){_hp2=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
1
Contributor
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Raptoricus
0

Ive done it again :), kindof a noobie error problem 1:
didnt make a takeHP function in monster class
2: After I did I had some learning to do about how to add new variables into an existing function

in conclusion:

made function: takeHP2(int amount){setHP2()-amount};
//set hp sets a new amount of hp
then used it like so in combat function:
takeHP2(amount); //Id already worked out a damage amount function

hope some of my self solved posts help some people sometime, its been a learning experience for me :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.