1
0
This repository has been archived on 2025-01-26. You can view files and clone it, but cannot push or open issues or pull requests.
CPP_Module_03/ex01/ScavTrap.cpp

69 lines
2.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ScavTrap.cpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/27 12:53:46 by adjoly #+# #+# */
/* Updated: 2024/11/29 15:39:05 by adjoly ### ########.fr */
/* */
/* ************************************************************************** */
#include "ScavTrap.hpp"
#include <iostream>
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!");
setEnergyPoints(getEnergyPoints() - 1);
}