/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ClapTrap.cpp :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/13 05:22:49 by apommier #+# #+# */ /* Updated: 2022/08/01 13:12:47 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ #include "ClapTrap.hpp" //constructor destructor and assignation ClapTrap::ClapTrap(std::string name) { std::cout << "ClapTrap " << name << " Default constructor called" << std::endl; this->_name = name; this->_hitPoints = 10; this->_energyPoints = 10; this->_attackDamage = 0; } ClapTrap::ClapTrap(const ClapTrap& copy) { std::cout << "ClapTrap Copy constructor called" << std::endl; this->_name = copy.getName(); this->_hitPoints = copy.getHitPoints(); this->_energyPoints = copy.getEnergyPoints(); this->_attackDamage = copy.getAttackDamage(); } ClapTrap::~ClapTrap() { std::cout << "ClapTrap " << this->_name << " Destructor called" << std::endl; } ClapTrap &ClapTrap::operator=(const ClapTrap& rhs) { std::cout << "ClapTrap " << this->_name << " Assignation operator called" << std::endl; this->_name = rhs.getName(); this->_hitPoints = rhs.getHitPoints(); this->_energyPoints = rhs.getEnergyPoints(); this->_attackDamage = rhs.getAttackDamage(); return *this; } //accessor std::string ClapTrap::getName(void) const { return (this->_name); } int ClapTrap::getHitPoints(void) const { return (this->_hitPoints); } int ClapTrap::getEnergyPoints(void) const { return (this->_energyPoints); } int ClapTrap::getAttackDamage(void) const { return (this->_attackDamage); } //member function void ClapTrap::attack(const std::string& target) { if (this->_hitPoints <= 0) std::cout << "ClapTrap " << this->_name << " could not attack because he died" << std::endl; else if (this->_energyPoints <= 0) std::cout << "ClapTrap " << this->_name << " could not attack because he don't have energy" << std::endl; else { std::cout << "ClapTrap " << this->_name << " attacks " << target << ", causing " << this->_attackDamage << " points of damage!" << std::endl; this->_energyPoints--; } } void ClapTrap::takeDamage(unsigned int amount) { std::cout << "ClapTrap " << this->_name << " take " << amount << " points of damage!" << std::endl; if (this->_hitPoints <= 0) std::cout << "ClapTrap " << this->_name << " is dead stop hitting a dead corpse" << std::endl; else if (this->_hitPoints - amount <= 0) std::cout << "ClapTrap " << this->_name << " died" << std::endl; this->_hitPoints -= amount; if (this->_hitPoints > 0) std::cout << "ClapTrap " << this->_name << " have " << this->_hitPoints << " hit points" << std::endl; } void ClapTrap::beRepaired(unsigned int amount) { if (this->_hitPoints <= 0) std::cout << "ClapTrap " << this->_name << " could not repair because he died" << std::endl; else if (this->_energyPoints <= 0) std::cout << "ClapTrap " << this->_name << " could not repair because he don't have energy" << std::endl; else { std::cout << "ClapTrap " << this->_name << " regain " << amount << " hit point(s)!" << std::endl; this->_hitPoints += amount; std::cout << "ClapTrap " << this->_name << " have " << this->_hitPoints << " hit points" << std::endl; this->_energyPoints--; } }