class player
{
public:
player():
strength(5),
health(100),
experience(0)
{
}
void info();
void attack();
void heal();
void experience();
private:
int age;
string name;
int strength;
int health;
int experience;
int level;
};s
then there's another class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
class enemy
{
public:
enemy(int enemyStrength, int enemyHealth):
strength(enemyStrength),
health(enemyHealth)
{
}
void attack();
private:
int strength;
int health;
};
now I would like to use the class enemy with the class player but the thing about that is, I don't know how :( pls help me with that, sorry if I sound like a noob...
Well if you don't know the relation you want between an ennemy and a player, we can't help much.
Can a player be an ennemy? Does a player have one ennemy? Or multiple ennemies? Do you need to access the ennemy's data from the player, or the opposite?
the player is not an enemy, he's supposed to fight the enemy, there are going to be multiple enemies, and I need to access the player from the enemy and the enemy from the player, because I have to somehow make the enemy's health drain once he get's hit by the player and the same the other way around, it would be great if I could get an answer to this.
will that also work if I put enemy in enemy.h and player in player.h?
I tried using #include "player.h" and #include "enemy.h" in both .h files but it didn't seem to work out :(
1.declaration of the function member must be known before you set it as a friend of another class.
to be able to do that include that class into header of another class.
2.also declaration of the class must be known before you set it as a friend of another class.
3.structure of the class must be known for member function which want to access class members
codekiddy said this like a golden trophy that shown the world who is first. (He said it excellent). And now if you follow what he said, bubp! You fixed yourself a problem!
so, lol, do I use the #include statement to include the enemy class from enemy.h into player.h?
Or do I just include the enemy class into player.h with copy and paste?
sorry for so many questions.
The player is supposed to attack the enemy, once the enemy gets hit his health drains, let's say the player has 12 strength, then I want the enemy's health to drain by 12 every time he get's hit
and when the player gets hit, his health drains...
that's about as good as I could explain it.
You have great stuff here, truly informative. Very well written I shall be bookmarking your blog and subscribing to your feed so i can regularly read posts of this quality.
You have great stuff here, truly informative. Very well written I shall be bookmarking your blog and subscribing to your feed so i can regularly read posts of this quality.
#include <iostream>
#include <string>
#include "enemy.h"
usingnamespace std;
class player
{
public:
player();
void info();
void attack();
void heal();
void levelup();
void playerhit();
private:
int age;
string name;
int strength;
int health;
int experiencePoints;
int level;
int healStrength;
int maxHealth;
};
then the enemy class:
1 2 3 4 5 6 7 8 9 10 11 12 13
class enemy
{
public:
enemy(int enemyStrength, int enemyHealth);
void attack(int playerHealth);
void enemyhit(int playerStrength);
void strengthenemy();
void healthenemy();
private:
int strength;
int health;
};
#include "stdafx.h"
#include "player.h"
int main()
{
cout << "hello, and welcome to the Arena stranger!\n";
player me;
me.info();
do
{
cout << "a - attack\n";
cout << "h - heal\n";
cout << "p - playerstats\n";
cout << "x - quit\n";
char x;
cin >> x;
if(x == 'a')
{
me.attack();
}
}
while(5);
return 0;
}
I first included enemy.h into player.h, then I included player.h into the main .cpp file and the other class .cpp files but that's not important now and now I am going to add parameters to both the enemy and the player classes, thanks for the help! :D
(I added the do{} while(5) just so that I wouldn't have to give it anything that could end the game in an inconvenient time :))