I'm trying to create a small RPG and I'm having trouble figurig out how to attach an inventory to a being when it's being created.
Please take a look at my code
Being.h
Code:
class Being
{
public:
void makeInv(Being& target);
void atk(Being& target, Being& attacker);
void takeDmg(Being& attaker, Being& target);
void setHp(int HP){hp = HP;}
void setSp(int SP){sp = SP;}
void setFlee(int FLEE){flee = FLEE;}
void setHit(int HIT){hit = HIT;}
void setAtkPower(int ATKPOWER){atkPower = ATKPOWER;}
void setMultip(int MULTIP){multip = MULTIP;}
void setInvNumSet(int INVNUMSET){invNumSet = INVNUMSET;}
int getHp(){return hp;}
int getSp(){return sp;}
int getFlee(){return flee;}
int getHit(){return hit;}
int getAtkPower(){return atkPower;}
int getMultip(){return multip;}
int getInvNum(){return invNumSet;}
protected:
int hp;
int sp;
int flee;
int hit;
int atkPower;
int multip;
int invNumSet;
};
#endif
Being.cpp
Code:
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
#include "Enemy.h"
#include "Hero.h"
void Being::makeInv(Being& target)
{
string *pInvNum;
pInvNum = new string[target.getInvNum()];
for(int i = 0; target.getInvNum() > i; i++)
{
pInvNum[i] = "\nEmpty Slot !!";
cout << pInvNum[i] << endl;
}
}
void Being::atk(Being& target, Being& attacker)
{
int fleeRoll, fleeRoll2;
fleeRoll = (target.getFlee() - attacker.getHit() );
time_t seconds;
time(&seconds);
srand((unsigned int) seconds);
fleeRoll2 = rand() % 100;
if(fleeRoll < fleeRoll2)
{
cout << "\nHit !!";
takeDmg(attacker, target);
}
else
cout << "\nMiss !!";
}
void Being::takeDmg(Being& attacker, Being& target)
{
int temp;
temp = target.getHp();
temp -= (attacker.getAtkPower() * attacker.getMultip() );
target.setHp(temp);
}
Enemies are the same as this class, so I won't waste space posting it twice.
Hero.h
Code:
#ifndef HERO_H
#define HERO_H
#include <iostream>
#include "Being.h"
class Warrior : public Being
{
public:
Warrior()
{hp = 100, sp = 10, flee = 120, hit = 100,
invNumSet = 10, atkPower = 10, multip = 2; };
void warriorAtk();
};
Anyone got any tips on how to attach the inventory to the instance when the constructor is called?