ex02 done and modified 42header on files
This commit is contained in:
73
ex02/ScavTrap/ScavTrap.cpp
Normal file
73
ex02/ScavTrap/ScavTrap.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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)")
|
||||
{
|
||||
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)
|
||||
{
|
||||
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
|
||||
<< " cant attack anymore..." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void ScavTrap::guardGate()
|
||||
{
|
||||
std::cout << "ScavTrap " << this->name << " is in Gate keeper mode"
|
||||
<< std::endl;
|
||||
}
|
||||
34
ex02/ScavTrap/ScavTrap.hpp
Normal file
34
ex02/ScavTrap/ScavTrap.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ScavTrap.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* 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 */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef SCAVTRAP_HPP
|
||||
|
||||
# define SCAVTRAP_HPP
|
||||
|
||||
# include <iostream>
|
||||
# include "../ClapTrap/ClapTrap.hpp"
|
||||
|
||||
class ScavTrap : public ClapTrap
|
||||
{
|
||||
public:
|
||||
ScavTrap();
|
||||
ScavTrap(std::string name);
|
||||
ScavTrap(const ScavTrap &other);
|
||||
ScavTrap& operator=(const ScavTrap &other);
|
||||
~ScavTrap();
|
||||
|
||||
void attack(const std::string &target);
|
||||
|
||||
void guardGate();
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user