This is my first topic, since I've started reading these forums a while ago.
So I finally felt ready to start a little "game" project in C++; I've been using this language on and off for a bit, and I thought a project would help me understand it and practice it more.
What I want to do is a text-based RPG (focusing more on combat system, like Pokémon for example) and for now I'm just trying to get the basics to work.
You can make a character, name him and the game will randomly generate an amount of HP for you.
So I made this for the enemy:
class Enemy
{
public:
int health;
int curhealth, atk1;
string name;
int GetHealth();
void SetHealth();
int TakeDamage(int);
};
Everything is going fine, but when I tried damaging one of those enemies with this function:
[SPOILER]
void Player::Attack(Enemy enemy)
{
int atk = urand(10, 30);
enemy.TakeDamage(atk);
cout << endl << "Attacked for: " << atk << "." << endl;
cout << "Enemy HP: " << enemy.GetHealth() << "." << endl;
}
// Enemy
void Enemy::SetHealth()
{
health = urand(100, 120);
curhealth = health;
}
int Enemy::GetHealth()
{
return curhealth;
}
int Enemy::TakeDamage(int damage)
{
curhealth -= damage;
}
[/SPOILER]
The first time I damage the enemy the health returns fine( ex. Enemy health is 100, I attack for 20 it returns 80);
now, the second time instead of taking the current health value of 80 and reducing, say another attack of 10, it'll reduce to the total health, returning 90.
I think that's because it's always re-setting curhealth to the value of maxhealth, therefore everytime I damage him it ignores the times before.
This is probably a silly mistake, and I'll try to fix it tonight if I have time, but a little insight wouldn't hurt .
Apart from that, if you have any ideas as to what I could put in the game, let me know!
Cheers
EDIT: It now works just fine, thanks to Servant of the Lord and Sollum!