diff --git a/d03/ex00/ClapTrap.cpp b/d03/ex00/ClapTrap.cpp new file mode 100644 index 0000000..0a6ec83 --- /dev/null +++ b/d03/ex00/ClapTrap.cpp @@ -0,0 +1,102 @@ +#include "ClapTrap.hpp" + +/* + * default/parametric constructor + */ + +ClapTrap::ClapTrap( void ) { + return; +} + +/* + * destructor + */ + +ClapTrap::~ClapTrap( void ) { + return; +} + +/* + * copy constructor + */ + +ClapTrap::ClapTrap( ClapTrap const & src ) { + *this = src; + return; +} + +/* + * assignement operator + */ + +ClapTrap & ClapTrap::operator=( ClapTrap const & rhs ) { + + if ( this != &rhs ) + { + this->_hit = rhs.getHit(); + this->_energy = rhs.getEnergy(); + this->_attack = rhs.getAttack(); + } + + return *this; + +} + +/* + * constructor + */ + +ClapTrap::ClapTrap( std::string name ) : _name(name) { + _hit = 10; + _energy = 10; + _attack = 1; + return; +} + +/* + * getters + */ + +std::string ClapTrap::getName() const {return _name;} +int ClapTrap::getHit() const {return _hit;} +int ClapTrap::getEnergy() const {return _energy;} +int ClapTrap::getAttack() const {return _attack;} + +/* + * robots + */ + +void ClapTrap::attack(const std::string & target) { + std::cout << B_CYAN "[" B_PURPLE "h,e,a" B_CYAN ":" B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "->"; + + _energy--; + + std::cout << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET + << " ClapTrap " << _name + << " attacked " << target + << ", causing " B_YELLOW << _attack << RESET + << " points of damage!" << '\n'; +} + +void ClapTrap::takeDamage(unsigned int amount) { + std::cout << B_CYAN "[" B_PURPLE "h,e,a" B_CYAN ":" B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "->"; + + _hit -= amount; + + std::cout << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET + << " ClapTrap " << _name + << " looses " B_YELLOW << amount << RESET + << " points of damage :/" << '\n'; +} + +void ClapTrap::beRepaired(unsigned int amount) { + std::cout << B_CYAN "[" B_PURPLE "h,e,a" B_CYAN ":" B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "->"; + + _energy--; + _hit += amount; + + std::cout << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET + << " ClapTrap " << _name + << " repaired itself and gained " B_YELLOW << amount << RESET + << " points of life :)" << '\n'; +} diff --git a/d03/ex00/ClapTrap.hpp b/d03/ex00/ClapTrap.hpp new file mode 100644 index 0000000..d5cb57d --- /dev/null +++ b/d03/ex00/ClapTrap.hpp @@ -0,0 +1,39 @@ +#ifndef CLAPTRAP_HPP +# define CLAPTRAP_HPP + +#include +#include +#include + +class ClapTrap { + +public: + + ClapTrap( std::string name ); // default/parametric constructor + ClapTrap( ClapTrap const & src ); // copy constructor + ~ClapTrap( void ); // destructor + + ClapTrap & operator=( ClapTrap const & rhs ); // assignement operator + + void attack(const std::string & target); + void takeDamage(unsigned int amount); + void beRepaired(unsigned int amount); + + std::string getName() const; + int getHit() const; + int getEnergy() const; + int getAttack() const; + +private: + + ClapTrap( void ); // default/parametric constructor + + std::string const _name; + int _hit; + int _energy; + int _attack; + +}; + +#endif + diff --git a/d03/ex00/Makefile b/d03/ex00/Makefile index 9708dcd..930ba65 100644 --- a/d03/ex00/Makefile +++ b/d03/ex00/Makefile @@ -16,10 +16,11 @@ LIBS = INCLUDES = -I$(D_HEADERS) D_SRCS = . -SRCS = main.cpp +SRCS = main.cpp \ + ClapTrap.cpp D_HEADERS = . -HEADERS = +HEADERS = ClapTrap.hpp D_OBJS = builds OBJS = $(SRCS:%.cpp=$(D_OBJS)/%.o) diff --git a/d03/ex00/action b/d03/ex00/action new file mode 100755 index 0000000..eadfc6c Binary files /dev/null and b/d03/ex00/action differ diff --git a/d03/ex00/color.h b/d03/ex00/color.h new file mode 100644 index 0000000..e313f5f --- /dev/null +++ b/d03/ex00/color.h @@ -0,0 +1,24 @@ +#ifndef COLOR_H +# define COLOR_H + +# define GRAY "\e[0;30m" +# define RED "\e[0;31m" +# define GREEN "\e[0;32m" +# define YELLOW "\e[0;33m" +# define BLUE "\e[0;34m" +# define PURPLE "\e[0;35m" +# define CYAN "\e[0;36m" +# define WHITE "\e[0;37m" + +# define B_GRAY "\e[1;30m" +# define B_RED "\e[1;31m" +# define B_GREEN "\e[1;32m" +# define B_YELLOW "\e[1;33m" +# define B_BLUE "\e[1;34m" +# define B_PURPLE "\e[1;35m" +# define B_CYAN "\e[1;36m" +# define B_WHITE "\e[1;37m" + +# define RESET "\e[0m" + +#endif diff --git a/d03/ex00/main.cpp b/d03/ex00/main.cpp new file mode 100644 index 0000000..b6ca94c --- /dev/null +++ b/d03/ex00/main.cpp @@ -0,0 +1,13 @@ +#include "ClapTrap.hpp" + +int main() { + + ClapTrap robot1("robot1"); + ClapTrap robot2("robot2"); + + robot1.attack(robot2.getName()); + robot2.takeDamage(robot1.getAttack()); + robot2.beRepaired(robot1.getAttack()); + + return 0; +}