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

57 lines
1.8 KiB
C++

#include "ScavTrap.hpp"
ScavTrap::ScavTrap(): ClapTrap()
{
this->_hit_pts = 100;
this->_energy_pts = 50;
this->_attack_dmg = 20;
this->_guarding_gate = false;
std::cout << "ScavTrap Default Constructor called" << std::endl;
}
ScavTrap::ScavTrap(const ScavTrap &copy): ClapTrap(copy)
{
this->_guarding_gate = copy._guarding_gate;
std::cout << "ScavTrap Copy Constructor called" << std::endl;
}
ScavTrap::ScavTrap(std::string name): ClapTrap(name)
{
this->_hit_pts = 100;
this->_energy_pts = 50;
this->_attack_dmg = 20;
this->_guarding_gate = false;
std::cout << "ScavTrap Constructor " << this->_name << " called" << std::endl;
}
ScavTrap::~ScavTrap()
{
std::cout << "ScavTrap Deconstructor " << this->_name << " called" << std::endl;
}
ScavTrap &ScavTrap::operator=(const ScavTrap &src)
{
std::cout << "ScavTrap 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 ScavTrap::attack(const std::string &target)
{
if (this->_energy_pts > 0 && this->_hit_pts > 0)
{
std::cout << "ScavTrap " << this->_name << " attacks " << target << ", causing " << this->_attack_dmg << " damage!" << std::endl;
this->_energy_pts--;
}
else if (this->_energy_pts == 0)
std::cout << "ScavTrap " << this->_name << " is not able to attack " << target << ", because he has no energy points left." << std::endl;
else
std::cout << "ScavTrap " << this->_name << " is not able to attack " << target << ", because he is dead" << std::endl;
}
void ScavTrap::guardGate() {
std::cout << "ScavTrap " << this->_name << " is now in Gate keeper mode!" << std::endl;
}