I thought i would make a simple text game before continuing with SDL
And well, i have problems xD.
Now, everytime i try to attack Slagor hes HP is always "reset"(not good), BUT i can decrese his HP in the main function.(but i want it to work in the attack function)
And here is the WHOLE code:) :
Code: Select all
#include <iostream>
using namespace std;
class Player
{
private:
bool IsAlive;
int exp, hp, mp, power;
public:
char name;
int GetHP()
{
return hp;
}
void AddHP(int h)
{
hp += h;
}
void Die(){
IsAlive = false;
}
void Attack(Player e)
{
e.SubHP(exp*power);
cout << "You attacked " << "another player" << " with " << exp*power << " damage!\n";
cout << "Enemy hp left: " << e.GetHP() << "!\n";
}
void Default()
{
IsAlive = true;
exp = 1;
hp = 100;
power = 1;
mp = 50;
}
void SubHP(int p)
{
hp = hp - p;
}
};
int main()
{
cout << "Welcome!\n\n\n";
Player Zer0XoL;
Zer0XoL.Default();
Player Slagor;
Slagor.Default();
Zer0XoL.Attack(Slagor);
Zer0XoL.Attack(Slagor);
Zer0XoL.Attack(Slagor);
Zer0XoL.Attack(Slagor);
Slagor.Attack(Zer0XoL);
Zer0XoL.Attack(Slagor);
Zer0XoL.Attack(Slagor);
Slagor.SubHP(66);
cout << "New hp:" << Slagor.GetHP() <<endl;
Zer0XoL.Attack(Slagor);
Zer0XoL.Attack(Slagor);
Zer0XoL.Attack(Slagor);
Slagor.SubHP(-1);
cout << "New hp: " << Slagor.GetHP() <<endl;
Zer0XoL.Attack(Slagor);
Zer0XoL.Attack(Slagor);
Zer0XoL.Attack(Slagor);
cin.get();
cin.get();
}
*Edit:
this is the output of the program(im using Dev-Cpp)
:
Code: Select all
Welcome!
You attacked another player with 1 damage!
Enemy hp left: 99!
You attacked another player with 1 damage!
Enemy hp left: 99!
You attacked another player with 1 damage!
Enemy hp left: 99!
You attacked another player with 1 damage!
Enemy hp left: 99!
You attacked another player with 1 damage!
Enemy hp left: 99!
You attacked another player with 1 damage!
Enemy hp left: 99!
You attacked another player with 1 damage!
Enemy hp left: 99!
New hp:34
You attacked another player with 1 damage!
Enemy hp left: 33!
You attacked another player with 1 damage!
Enemy hp left: 33!
You attacked another player with 1 damage!
Enemy hp left: 33!
New hp: 35
You attacked another player with 1 damage!
Enemy hp left: 34!
You attacked another player with 1 damage!
Enemy hp left: 34!
You attacked another player with 1 damage!
Enemy hp left: 34!