Message when repair ClapTrap

This commit is contained in:
2025-09-17 09:31:39 +02:00
parent 244932f905
commit 52b6a47ffa

View File

@@ -22,7 +22,10 @@ ClapTrap::ClapTrap() :
ClapTrap::ClapTrap(std::string name) :
name(name), health(10),
energy(10), attackDamage(0)
{}
{
std::cout << "Default constructor called for "
<< name << std::endl;
}
ClapTrap::ClapTrap(const ClapTrap &target)
{
@@ -46,7 +49,8 @@ ClapTrap& ClapTrap::operator=(const ClapTrap &target)
ClapTrap::~ClapTrap()
{
std::cout << "Destructor called" << std::endl;
std::cout << "Destructor called for "
<< this->name << std::endl;
}
void ClapTrap::attack(const std::string &target)
@@ -70,13 +74,20 @@ void ClapTrap::takeDamage(unsigned int amount)
std::cout << "ClapTrap " << this->name
<< " recieves " << amount
<< " points of damage!" << std::endl;
this->health -= amount;
if (amount >= this->health)
this->health = 0;
else
this->health -= amount;
}
void ClapTrap::beRepaired(unsigned int amount)
{
if (this->energy > 0)
{
std::cout << "ClapTrap " << this->name
<< " repairs itself, recovering " << amount
<< " hit points!" << std::endl;
this->health += amount;
this->energy -= 1;
} else {