Files
cpp03/ex02/FragTrap.cpp
T
2026-09-06 18:54:24 +02:00

54 lines
1.7 KiB
C++

#include "FragTrap.hpp"
FragTrap::FragTrap(): ClapTrap()
{
this->_hit_pts = 100;
this->_energy_pts = 100;
this->_attack_dmg = 30;
std::cout << "FragTrap Default Constructor called" << std::endl;
}
FragTrap::FragTrap(const FragTrap &copy): ClapTrap(copy)
{
std::cout << "FragTrap Copy Constructor called" << std::endl;
}
FragTrap::FragTrap(std::string name): ClapTrap(name)
{
this->_hit_pts = 100;
this->_energy_pts = 100;
this->_attack_dmg = 30;
std::cout << "FragTrap Constructor " << this->_name << " called" << std::endl;
}
FragTrap::~FragTrap()
{
std::cout << "FragTrap Deconstructor " << this->_name << " called" << std::endl;
}
FragTrap &FragTrap::operator=(const FragTrap &src)
{
std::cout << "FragTrap Assignation operator called" << std::endl;
this->_name = src._name;
this->_hit_pts = src._hit_pts;
this->_energy_pts = src._energy_pts;
this->_attack_dmg = src._attack_dmg;
return *this;
}
void FragTrap::attack(const std::string &target)
{
if (this->_energy_pts > 0 && this->_hit_pts > 0)
{
std::cout << "FragTrap " << this->_name << " attacks " << target << ", causing " << this->_attack_dmg << " damage!" << std::endl;
this->_energy_pts--;
}
else if (this->_energy_pts == 0)
std::cout << "FragTrap " << this->_name << " is not able to attack " << target << ", because he has no energy points left." << std::endl;
else
std::cout << "FragTrap " << this->_name << " is not able to attack " << target << ", because he is dead" << std::endl;
}
void FragTrap::highFivesGuys() {
std::cout << "FragTrap " << this->_name << " requests a positive high-five! ✋" << std::endl;
}