/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ClapTrap.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: adjoly +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/20 14:29:16 by adjoly #+# #+# */ /* Updated: 2024/11/27 11:55:35 by adjoly ### ########.fr */ /* */ /* ************************************************************************** */ #include "ClapTrap.hpp" #include #include #include ClapTrap::ClapTrap(void) : _name("Kanel"), _health(10), _energyPoints(10), _attackDamage(0) { log("➕", "default constructor called"); } ClapTrap::~ClapTrap(void) { log("➖", "destructor called"); } ClapTrap::ClapTrap(std::string name) : _name(name), _health(10), _energyPoints(10), _attackDamage(0) { log("➕", _name, "constructor called"); } ClapTrap::ClapTrap(const ClapTrap &other) { *this = other; log("➕", _name, "copy constructor called"); } ClapTrap &ClapTrap::operator=(const ClapTrap &cpy) { log("🟰", _name, "copy assignement constructor called"); if (this != &cpy) { _name = cpy.getName(); _health = cpy.getHealth(); _energyPoints = cpy.getEnergyPoints(); _attackDamage= cpy.getAttackDamage(); } return (*this); } void ClapTrap::attack(const std::string& target) { if (_health == 0) { log("💀", _name, "can't attack already dead"); return ; } else if (_energyPoints == 0) { log("💤", _name, "can't attack no energy left GO TO SLEEP!"); return ; } log("💥", _name, "attacks " + target + " causing " + iToS(getAttackDamage()) + " points of damage!"); _energyPoints--; } void ClapTrap::takeDamage(unsigned int amount) { log("🥊", _name, "take " + iToS(amount) + " damage"); if (_health >= amount) { log("💀", _name, "is dead HAHA"); _health = 0; } else { _health -= amount; } } void ClapTrap::beRepaired(uint amount) { if (_health == 0) { log("💀", _name, "can't repair already dead"); return ; } else if (_energyPoints == 0) { log("💤", _name, "can't repair no energy left GO TO SLEEP!"); return ; } log("🩹", _name, iToS(amount) + ""); _health += amount; _energyPoints--; } uint ClapTrap::getAttackDamage(void) const { return (_attackDamage); } uint ClapTrap::getEnergyPoints(void) const { return (_energyPoints); } uint ClapTrap::getHealth(void) const { return (_health); } std::string ClapTrap::getName(void) const { return (_name); } void ClapTrap::setAttackDamage(uint in) { log("🟰", _name, "set attack damage"); _attackDamage = in; } void ClapTrap::setEnergyPoints(uint in) { log("🟰", _name, "set energy points"); _energyPoints = in; } void ClapTrap::setHealth(uint in) { log("🟰", _name, "set health"); _health = in; } void ClapTrap::setName(std::string in) { log("🟰", _name, "set a new name"); _name = in; }