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