cpp/cpp03/ex03/FragTrap.cpp
2022-08-03 18:24:07 +02:00

74 lines
2.7 KiB
C++

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* FragTrap.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apommier <apommier@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 01:24:31 by apommier #+# #+# */
/* Updated: 2022/08/03 18:07:52 by apommier ### ########.fr */
/* */
/* ************************************************************************** */
#include "FragTrap.hpp"
FragTrap::FragTrap()
{
std::cout << "FragTrap Default constructor called" << std::endl;
this->_hitPoints = 100;
this->_energyPoints = 100;
this->_attackDamage = 30;
}
FragTrap::FragTrap(std::string name) : ClapTrap(name)
{
std::cout << "FragTrap " << this->_name << " Name constructor called" << std::endl;
this->_hitPoints = 100;
this->_energyPoints = 100;
this->_attackDamage = 30;
}
FragTrap::FragTrap(const FragTrap& copy) : ClapTrap(copy)
{
std::cout << "FragTrap Copy constructor called" << std::endl;
this->_name = copy.getName();
this->_hitPoints = copy.getHitPoints();
this->_energyPoints = copy.getEnergyPoints();
this->_attackDamage = copy.getAttackDamage();
}
FragTrap::~FragTrap()
{
std::cout << "FragTrap " << this->_name << " Destructor called" << std::endl;
}
void FragTrap::attack(const std::string& target)
{
if (this->_hitPoints <= 0)
std::cout << "FragTrap " << this->_name << " could not attack because he died" << std::endl;
else if (this->_energyPoints <= 0)
std::cout << "FragTrap " << this->_name << " could not attack because he don't have energy" << std::endl;
else
{
std::cout << "FragTrap " << this->_name << " attacks " << target << ", causing " << this->_attackDamage << " points of damage!" << std::endl;
this->_energyPoints--;
}
}
FragTrap &FragTrap::operator=(const FragTrap& rhs)
{
std::cout << "FragTrap " << 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;
}
void FragTrap::highFivesGuys(void)
{
if (this->_hitPoints <= 0)
std::cout << "FragTrap " << this->_name << " could not ask you for a highfive because he died" << std::endl;
else
std::cout << "FragTrap " << this->_name << " ask you for a highfive\n";
}