Files
cpp03/ex01/ScavTrap/ScavTrap.cpp
Angel Ortigosa Perez 46b7b99abb Min fixes
2025-10-26 20:20:14 +01:00

84 lines
2.4 KiB
C++

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ScavTrap.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aortigos <aortigos@student.42malaga.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/06 02:27:27 by aortigos #+# #+# */
/* Updated: 2025/09/06 02:28:09 by aortigos ### ########.fr */
/* */
/* ************************************************************************** */
#include "ScavTrap.hpp"
ScavTrap::ScavTrap() : ClapTrap("(NULL)"), guarding_gate(false)
{
this->health = 100;
this->energy = 50;
this->attackDamage = 20;
std::cout << "ScavTrap default constructor called " << this->name
<< std::endl;
}
ScavTrap::ScavTrap(std::string name) : ClapTrap(name), guarding_gate(false)
{
this->health = 100;
this->energy = 50;
this->attackDamage = 20;
std::cout << "ScavTrap constructor for " << this->name
<< std::endl;
}
ScavTrap::ScavTrap(const ScavTrap &other) : ClapTrap(other) { }
ScavTrap& ScavTrap::operator=(const ScavTrap &other)
{
if (this != &other)
{
this->name = other.name;
this->health = other.health;
this->energy = other.energy;
this->attackDamage = other.attackDamage;
}
return (*this);
}
ScavTrap::~ScavTrap()
{
std::cout << "ScavTrap destructor called for "
<< this->name << std::endl;
}
void ScavTrap::attack(const std::string &target)
{
if (this->health > 0 && this->energy > 0)
{
std::cout << "ScavTrap " << this->name
<< " attacks " << target
<< ", causing " << this->attackDamage
<< " points of damage!" << std::endl;
this->energy -= 1;
} else {
std::cout << "ScavTrap " << this->name
<< " can't attack anymore..." << std::endl;
}
}
void ScavTrap::guardGate()
{
if (!this->guarding_gate)
{
this->guarding_gate = true;
std::cout << "ScavTrap " << this->name << " is in Gate keeper mode"
<< std::endl;
}
else
{
std::cout << "ScavTrap " << this->name << " is already in Gate keeper mode"
<< std::endl;
}
}