From 52b6a47ffad7124089e355f835bb204f3c0f7887 Mon Sep 17 00:00:00 2001 From: aortigos Date: Wed, 17 Sep 2025 09:31:39 +0200 Subject: [PATCH] Message when repair ClapTrap --- ex00/ClapTrap/ClapTrap.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ex00/ClapTrap/ClapTrap.cpp b/ex00/ClapTrap/ClapTrap.cpp index cdaeb16..4fba4a6 100644 --- a/ex00/ClapTrap/ClapTrap.cpp +++ b/ex00/ClapTrap/ClapTrap.cpp @@ -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 {