74 lines
2.4 KiB
C++
74 lines
2.4 KiB
C++
/* ************************************************************************** */
|
||
/* */
|
||
/* ::: :::::::: */
|
||
/* ScavTrap.cpp :+: :+: :+: */
|
||
/* +:+ +:+ +:+ */
|
||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||
/* +#+#+#+#+#+ +#+ */
|
||
/* Created: 2024/11/27 12:53:46 by adjoly #+# #+# */
|
||
/* Updated: 2024/11/29 16:01:32 by adjoly ### ########.fr */
|
||
/* */
|
||
/* ************************************************************************** */
|
||
|
||
#include "ScavTrap.hpp"
|
||
#include <iostream>
|
||
#include <sched.h>
|
||
|
||
void logScav(std::string emoji, std::string who, std::string str) {
|
||
std::cout << "「" << emoji << "」ScavTrap(" << who << "): " << str << std::endl;
|
||
}
|
||
|
||
void logScav(std::string emoji, std::string str) {
|
||
std::cout << "「" << emoji << "」ScavTrap: " << str << std::endl;
|
||
}
|
||
|
||
ScavTrap::ScavTrap(void) : ClapTrap() {
|
||
logScav("➕", "default constructor called");
|
||
_health = 100;
|
||
_energyPoints = 50;
|
||
_attackDamage = 20;
|
||
}
|
||
|
||
ScavTrap::~ScavTrap(void) {
|
||
logScav("➖", "destructor called");
|
||
}
|
||
|
||
ScavTrap::ScavTrap(std::string name) : ClapTrap(name) {
|
||
logScav("➕", name, "constructor called");
|
||
_health = 100;
|
||
_energyPoints = 50;
|
||
_attackDamage = 20;
|
||
}
|
||
|
||
ScavTrap::ScavTrap(const ScavTrap &other) {
|
||
*this = other;
|
||
logScav("➕", _name, "copy constructor called");
|
||
}
|
||
|
||
ScavTrap &ScavTrap::operator=(const ScavTrap &cpy) {
|
||
logScav("🟰", _name, "copy assignement constructor called");
|
||
if (this != &cpy) {
|
||
_name = cpy.getName();
|
||
_health = cpy.getHealth();
|
||
_energyPoints = cpy.getEnergyPoints();
|
||
_attackDamage = cpy.getAttackDamage();
|
||
}
|
||
return (*this);
|
||
}
|
||
|
||
void ScavTrap::attack(const std::string& target) {
|
||
if (_health == 0) {
|
||
logScav("💀", _name, "can't attack already dead");
|
||
return ;
|
||
} else if (_energyPoints == 0) {
|
||
logScav("💤", _name, "can't attack no energy left GO TO SLEEP!");
|
||
return ;
|
||
}
|
||
logScav("💥", _name, "attacks " + target + " causing " + iToS(_attackDamage) + " points of damage!");
|
||
_energyPoints--;
|
||
}
|
||
|
||
void ScavTrap::guardGate(void) {
|
||
logScav("🛡️", _name, "is now in Gate keeper mode");
|
||
}
|