d03 ex00 ok
This commit is contained in:
102
d03/ex00/ClapTrap.cpp
Normal file
102
d03/ex00/ClapTrap.cpp
Normal file
@@ -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';
|
||||||
|
}
|
||||||
39
d03/ex00/ClapTrap.hpp
Normal file
39
d03/ex00/ClapTrap.hpp
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#ifndef CLAPTRAP_HPP
|
||||||
|
# define CLAPTRAP_HPP
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <color.h>
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
@@ -16,10 +16,11 @@ LIBS =
|
|||||||
INCLUDES = -I$(D_HEADERS)
|
INCLUDES = -I$(D_HEADERS)
|
||||||
|
|
||||||
D_SRCS = .
|
D_SRCS = .
|
||||||
SRCS = main.cpp
|
SRCS = main.cpp \
|
||||||
|
ClapTrap.cpp
|
||||||
|
|
||||||
D_HEADERS = .
|
D_HEADERS = .
|
||||||
HEADERS =
|
HEADERS = ClapTrap.hpp
|
||||||
|
|
||||||
D_OBJS = builds
|
D_OBJS = builds
|
||||||
OBJS = $(SRCS:%.cpp=$(D_OBJS)/%.o)
|
OBJS = $(SRCS:%.cpp=$(D_OBJS)/%.o)
|
||||||
|
|||||||
BIN
d03/ex00/action
Executable file
BIN
d03/ex00/action
Executable file
Binary file not shown.
24
d03/ex00/color.h
Normal file
24
d03/ex00/color.h
Normal file
@@ -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
|
||||||
13
d03/ex00/main.cpp
Normal file
13
d03/ex00/main.cpp
Normal file
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user