69 lines
2.3 KiB
C++
69 lines
2.3 KiB
C++
|
/* ************************************************************************** */
|
|||
|
/* */
|
|||
|
/* ::: :::::::: */
|
|||
|
/* FragTrap.cpp :+: :+: :+: */
|
|||
|
/* +:+ +:+ +:+ */
|
|||
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
|||
|
/* +#+#+#+#+#+ +#+ */
|
|||
|
/* Created: 2024/11/29 15:40:29 by adjoly #+# #+# */
|
|||
|
/* Updated: 2024/11/29 16:15:12 by adjoly ### ########.fr */
|
|||
|
/* */
|
|||
|
/* ************************************************************************** */
|
|||
|
|
|||
|
#include "FragTrap.hpp"
|
|||
|
#include "ClapTrap.hpp"
|
|||
|
#include <iostream>
|
|||
|
|
|||
|
void logFrag(std::string emoji, std::string who, std::string str) {
|
|||
|
std::cout << "「" << emoji << "」FragTrap(" << who << "): " << str << std::endl;
|
|||
|
}
|
|||
|
|
|||
|
void logFrag(std::string emoji, std::string str) {
|
|||
|
std::cout << "「" << emoji << "」FragTrap: " << str << std::endl;
|
|||
|
}
|
|||
|
|
|||
|
FragTrap::FragTrap(void) : ClapTrap() {
|
|||
|
logFrag("➕", "default constructor called");
|
|||
|
_health = 100;
|
|||
|
_energyPoints = 100;
|
|||
|
_attackDamage = 30;
|
|||
|
}
|
|||
|
|
|||
|
FragTrap::~FragTrap(void) {
|
|||
|
logFrag("➖", "destructor called");
|
|||
|
}
|
|||
|
|
|||
|
FragTrap::FragTrap(std::string name) : ClapTrap(name) {
|
|||
|
logFrag("➕", name, "constructor called");
|
|||
|
_health = 100;
|
|||
|
_energyPoints = 100;
|
|||
|
_attackDamage = 30;
|
|||
|
}
|
|||
|
|
|||
|
FragTrap &FragTrap::operator=(const FragTrap &cpy) {
|
|||
|
logFrag("🟰", _name, "copy assignement constructor called");
|
|||
|
if (this != &cpy) {
|
|||
|
_name = cpy.getName();
|
|||
|
_health = cpy.getHealth();
|
|||
|
_energyPoints = cpy.getEnergyPoints();
|
|||
|
_attackDamage = cpy.getAttackDamage();
|
|||
|
}
|
|||
|
return (*this);
|
|||
|
}
|
|||
|
|
|||
|
void FragTrap::attack(const std::string& target) {
|
|||
|
if (_health == 0) {
|
|||
|
logFrag("💀", _name, "can't attack already dead");
|
|||
|
return ;
|
|||
|
} else if (_energyPoints == 0) {
|
|||
|
logFrag("💤", _name, "can't attack no energy left GO TO SLEEP!");
|
|||
|
return ;
|
|||
|
}
|
|||
|
logFrag("💥", _name, "attacks " + target + " causing " + iToS(_attackDamage) + " points of damage!");
|
|||
|
_energyPoints--;
|
|||
|
}
|
|||
|
|
|||
|
void FragTrap::highFivesGuys(void) {
|
|||
|
logFrag("✋", _name, "send a high five request");
|
|||
|
}
|