I keep getting a logic error when I go to fight a monster.
It says the life must be initialized and then I get a runtime error. So I put a value to it and it runs fine. But the question is, what happens after the fight. I don't want my character to to take all this damage and then win and then all of a sudden he has one hundred hit points again. I would just like to know the correct way to access the life class variable so that it shows up in the fight funtion and works how it is supposed to.
ENTITY.h
private:
int life;
------------------------------------------------------------------------
ENTITY.cpp
void ENTITY::SetLife(int newLife)
{
if (life < 0)
life = 0;
}
int ENTITY::GetLife()
{
return life;
}
}
---------------------------------------------------------------------------------
PLAYER::PLAYER()//derived from ENTITY class
{
SetLife(100);//Here the value of SetLife is stated
}
---------------------------------------------------------------------------------------
void fight()
{
PLAYER player;// derived from ENTITY
int life = 100;// I don't think I should have to put a value to this variable if it's already stated in a class.
player.SetLife(life);
}