#include "Library.h" // Just std libs and SDL stuff and the H file below
ENEMY::ENEMY(ENEMY* enemy)
{
setName(enemy->getName());
setHealth(enemy->getHealth());
setMoney(enemy->getMoney());
}
ENEMY::void createEnemy(char* name, int health, int money, int damage, int x, int y)
{
setDamage(damage);
setMoney(money);
setHealth(health);
setName(name);
}
ENEMY::void setPosition(int xPosition, int yPosition)
{
xPos = xPosition;
yPos = yPosition;
}
ENEMY::int getX()
{
return xPos;
}
ENEMY::int getY()
{
return xPos;
}
Source for Enemy.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Based off of Stats.h
class ENEMY: public STATS
{
private:
char damage;
int armor;
int xPos;
int yPos;
public:
//ENEMY();
ENEMY(ENEMY*);
void createEnemy(char*, int, int, int, int, int);
void setPosition(int xPosition, int yPosition);
int getX();
int getY();
};
and because this is related to stats i'll throw that in too
#include "Library.h" // Holds all our libraries
// This is based off Stats.h
// For more documentation see Stats.h
void STATS::setWeapon(char *name)
{
weapon = name;
}
char* STATS::getWeapon()
{
return weapon;
}
bool STATS::setName(char* newName)
{
// If empty string return false
if (strlen(newName) == 0)
returnfalse;
// If string is bigger than allocated size (30) return false
if (strlen(newName) > 32)
returnfalse;
strcpy(name, newName); // If we get past the above apply name settings
returntrue;
}
char* STATS::getName()
{
return name;
}
void STATS::setMoney(int amount)
{
money = amount;
}
int STATS::getMoney()
{
return money;
}
void STATS::setHealth(int amount)
{
health = amount;
}
int STATS::getHealth()
{
return health;
}
// This class is the foundation for both the player & enemies
class STATS
{
private:
char name [50]; // A bit more allowing on the allocation
// The rest are self explanatory if you've ever played a game
int money;
int health;
char weapon[30];
public:
void setWeapon();
char* getWeapon;
bool setName(char* newName);
char* getName();
void setMoney(int amount);
int getMoney();
void setHealth (int amount);
int getHealth ();
};
Can someone help me solve this, I've been on google for about 2 hours now, and I can't seem to figure this out. I have a feeling it's the way my classes are setup, but .. I'm not so sure..
Constructors don't return values, so do what AleaIactaEst said for every function except the constructor.
Also, I hope that Enemy.cpp somehow includes Enemy.h (it should be including it directly, not relying on
Library.h, if indeed that is gratuitously including it for you).