#include "ClapTrap.hpp" #include ClapTrap::ClapTrap(): _name(""), _life(10), _energy(10), _damage(0) { std::cout << "ClapTrap()" << std::endl; } ClapTrap::ClapTrap(const std::string& name): _name(name), _life(10), _energy(10), _damage(0) { std::cout << "ClapTrap(" << name << ")" << std::endl; } ClapTrap::ClapTrap(const ClapTrap& src) { std::cout << "ClapTrap(ClapTrap)" << std::endl; *this = src; } ClapTrap::~ClapTrap() { std::cout << "~ClapTrap()" << std::endl; } ClapTrap& ClapTrap::operator=(const ClapTrap& src) { this->_name = src._name; this->_life = src._life; this->_energy = src._energy; this->_damage = src._damage; return *this; } void ClapTrap::beRepaired(unsigned int amount) { if (this->_life == 0 || this->_energy == 0) { std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl; return; } this->_life += amount; this->_energy--; std::cout << "ClapTrap " << this->_name << " beRepaired causing life is now " << this->_life << std::endl; } void ClapTrap::takeDamage(unsigned int amount) { if (this->_life == 0 || this->_energy == 0) { std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl; return; } this->_life -= amount; std::cout << "ClapTrap " << this->_name << " be attacked causing " << amount << " points of damage!" << std::endl; } void ClapTrap::attack(const std::string &target) { if (this->_life == 0 || this->_energy == 0) { std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl; return; } this->_energy--; std::cout << "ClapTrap " << this->_name << " attacks " << target << ", causing " << this->_damage << " points of damage!" << std::endl; } const std::string& ClapTrap::getName() const { return this->_name; } int ClapTrap::getLife() const { return this->_life; } int ClapTrap::getEnergy() const { return this->_energy; } int ClapTrap::getDamage() const { return this->_damage; }