d03 code refonte ex00 01 et 02

This commit is contained in:
Hugo LAMY
2022-02-22 19:05:24 +01:00
parent 088a54d036
commit 8c9d50dd68
12 changed files with 349 additions and 330 deletions

View File

@@ -1,96 +1,109 @@
#include "ClapTrap.hpp" #include "ClapTrap.hpp"
/* # define B_GRAY "\e[1;30m"
* default/parametric constructor # 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"
ClapTrap::ClapTrap( void ) { # define RESET "\e[0m"
std::cout << "claptrap created without name\n";
/*********************************************
* CONSTRUCTORS
*********************************************/
ClapTrap::ClapTrap( std::string name ) {
ClapTrap::_increaseNumber();
_class = _dClass;
_name = name;
_hit = _dHit;
_energy = _dEnergy;
_attack = _dAttack;
_number = getTotalNumber();
std::cout << _class << " " << _name << "-" << _number << " created\n";
return; return;
} }
/*
* destructor
*/
ClapTrap::~ClapTrap( void ) {
std::cout << "claptrap " << _name << " destructed\n";
return;
}
/*
* copy constructor
*/
ClapTrap::ClapTrap( ClapTrap const & src ) { ClapTrap::ClapTrap( ClapTrap const & src ) {
std::cout << "claptrap " << _name << " copied\n"; ClapTrap::_increaseNumber();
_class = _dClass;
*this = src; *this = src;
_number = getTotalNumber();
std::cout << _class << " " << _name << "-" << _number << " copied from " << src._class << " " << src._name << "-" << src._number << "\n";
return; return;
} }
/* /*********************************************
* assignement operator * DESTRUCTORS
*/ *********************************************/
ClapTrap::~ClapTrap( void ) {
std::cout << _class << " " << _name << "-" << _number << " destructed\n";
return;
}
/*********************************************
* OPERATORS
*********************************************/
ClapTrap & ClapTrap::operator=( ClapTrap const & rhs ) { ClapTrap & ClapTrap::operator=( ClapTrap const & rhs ) {
std::cout << "claptrap " << _name << " assigned\n";
if ( this != &rhs ) if ( this != &rhs )
{ {
this->_hit = rhs.getHit(); _name = rhs.getName();
this->_energy = rhs.getEnergy(); _hit = rhs.getHit();
this->_attack = rhs.getAttack(); _energy = rhs.getEnergy();
_attack = rhs.getAttack();
_number = rhs.getNumber();
} }
std::cout << _class << " " << _name << "-" << _number << " assigned\n";
return *this; return *this;
} }
/* /*********************************************
* constructor * ACCESSORS
*/ *********************************************/
ClapTrap::ClapTrap( std::string name ) : _name(name) {
std::cout << "claptrap " << _name << " created\n";
_hit = 10;
_energy = 10;
_attack = 1;
return;
}
/*
* getters
*/
std::string ClapTrap::getName() const {return _name;} std::string ClapTrap::getName() const {return _name;}
std::string ClapTrap::getClass() const {return _class;}
int ClapTrap::getHit() const {return _hit;} int ClapTrap::getHit() const {return _hit;}
int ClapTrap::getEnergy() const {return _energy;} int ClapTrap::getEnergy() const {return _energy;}
int ClapTrap::getAttack() const {return _attack;} int ClapTrap::getAttack() const {return _attack;}
int ClapTrap::getNumber() const {return _number;}
int ClapTrap::getTotalNumber() const {return _totalNumber;}
void ClapTrap::_increaseNumber() {ClapTrap::_totalNumber++;}
/* /*********************************************
* robots * PUBLIC MEMBER FUNCTIONS
*/ *********************************************/
void ClapTrap::attack(const std::string & target) { void ClapTrap::attack(const std::string & target) {
std::ostringstream action; std::ostringstream action;
std::ostringstream state; std::ostringstream state;
state << B_CYAN "[" B_PURPLE "h,e,a" B_CYAN ":" B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "->"; state << B_CYAN "[" B_GREEN << _class[0] << _number << B_PURPLE "h,e,a" B_CYAN ":" B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "->";
action << " ClapTrap " << _name; action << _class << " " << _name << "-" << _number;
if (_energy && _hit) if (_energy > 0 && _hit > 0)
{ {
_energy--; _energy--;
action << " attacked " << target << ", causing " B_YELLOW << _attack << RESET << " points of damage!" << '\n'; if (_energy < 0)
_energy = 0;
action << " attacked " << target << ", causing " B_YELLOW << _attack << RESET << " points of damage" << '\n';
} }
else else
{ {
_attack = 0; _attack = 0;
if (!_energy) if (_energy <= 0)
action << "cannot attack because " B_RED " is out of energy\n" RESET; action << " cannot attack because " B_RED " is out of energy" RESET"\n";
else if (!_hit) else if (_hit <= 0)
action << "cannot attack because " B_RED " is out of hit\n" RESET; action << " cannot attack because " B_RED " is out of hit" RESET "\n";
} }
state << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET; state << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET;
@@ -102,21 +115,18 @@ void ClapTrap::takeDamage(unsigned int amount) {
std::ostringstream action; std::ostringstream action;
std::ostringstream state; std::ostringstream state;
state << B_CYAN "[" B_PURPLE "h,e,a" B_CYAN ":" B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "->"; state << B_CYAN "[" B_GREEN << _class[0] << _number << B_PURPLE "h,e,a" B_CYAN ":" B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "->";
action << " ClapTrap " << _name; action << _class << " " << _name << "-" << _number;
if (_energy && _hit) if (_hit > 0)
{ {
_hit -= amount; _hit -= amount;
action << " looses " B_YELLOW << amount << RESET << " points of damage :/" << '\n'; if (_hit < 0)
} _hit = 0;
else action << " looses " B_YELLOW << amount << RESET << " hit points" << '\n';
{
if (!_energy)
action << "cannot take damage because " B_RED " is out of energy\n" RESET;
else if (!_hit)
action << "cannot take damage because " B_RED " is out of hit\n" RESET;
} }
else if (_hit <= 0)
action << " cannot take damage because " B_RED " is out of hit" RESET "\n";
state << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET; state << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET;
std::cout << state.str() << action.str(); std::cout << state.str() << action.str();
@@ -127,23 +137,38 @@ void ClapTrap::beRepaired(unsigned int amount) {
std::ostringstream action; std::ostringstream action;
std::ostringstream state; std::ostringstream state;
state << B_CYAN "[" B_PURPLE "h,e,a" B_CYAN ":" B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "->"; state << B_CYAN "[" B_GREEN << _class[0] << _number << B_PURPLE "h,e,a" B_CYAN ":" B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "->";
action << " ClapTrap " << _name; action << _class << " " << _name << "-" << _number;
if (_energy && _hit) if (_energy > 0 && _hit > 0)
{ {
_energy--; _energy--;
if (_energy < 0)
_energy = 0;
_hit += amount; _hit += amount;
action << " repaired itself and gained " B_YELLOW << amount << RESET << " points of life :)" << '\n'; action << " repaired itself and gained " B_YELLOW << amount << RESET << " points of life" << '\n';
} }
else else
{ {
if (!_energy) if (_energy <= 0)
action << "cannot repair itself because " B_RED " is out of energy\n" RESET; action << " cannot repair itself because " B_RED " is out of energy" RESET "\n";
else if (!_hit) else if (_hit <= 0)
action << "cannot repair itself because " B_RED " is out of hit\n" RESET; action << " cannot repair itself because " B_RED " is out of hit" RESET "\n";
} }
state << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET; state << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET;
std::cout << state.str() << action.str(); std::cout << state.str() << action.str();
} }
/*********************************************
* STATICS
*********************************************/
int ClapTrap::_totalNumber = 0;
std::string const ClapTrap::_dName = "robot";
std::string const ClapTrap::_dClass = "ClapTrap";
int const ClapTrap::_dHit = 10;
int const ClapTrap::_dEnergy = 10;
int const ClapTrap::_dAttack = 0;

View File

@@ -4,14 +4,13 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <color.h>
class ClapTrap { class ClapTrap {
public: public:
ClapTrap( std::string name ); // default/parametric constructor ClapTrap( std::string name = ClapTrap::_dName );
ClapTrap( ClapTrap const & src ); // copy constructor ClapTrap( ClapTrap const & src ); // copy constructor
~ClapTrap( void ); // destructor ~ClapTrap( void ); // destructor
ClapTrap & operator=( ClapTrap const & rhs ); // assignement operator ClapTrap & operator=( ClapTrap const & rhs ); // assignement operator
@@ -21,18 +20,36 @@ public:
void beRepaired(unsigned int amount); void beRepaired(unsigned int amount);
std::string getName() const; std::string getName() const;
std::string getClass() const;
int getHit() const; int getHit() const;
int getEnergy() const; int getEnergy() const;
int getAttack() const; int getAttack() const;
int getNumber() const;
protected:
int getTotalNumber() const;
std::string _name;
std::string _class;
int _hit;
int _energy;
int _attack;
int _number;
void _increaseNumber();
private: private:
ClapTrap( void ); // default/parametric constructor void assignValues(ClapTrap & src);
static int _totalNumber;
std::string const _name; static const std::string _dName;
int _hit; static const std::string _dClass;
int _energy; static const int _dHit;
int _attack; static const int _dEnergy;
static const int _dAttack;
static const int _dNumber;
}; };

View File

@@ -1,24 +0,0 @@
#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

View File

@@ -1,90 +1,86 @@
#include "ClapTrap.hpp" #include "ClapTrap.hpp"
/* # define B_GRAY "\e[1;30m"
* statics # 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"
int ClapTrap::_totalNumber = 0; # define RESET "\e[0m"
/* /*********************************************
* default/parametric constructor * CONSTRUCTORS
*/ *********************************************/
ClapTrap::ClapTrap( void ) { ClapTrap::ClapTrap( std::string name ) {
ClapTrap::_increaseNumber();
std::cout << "claptrap created without name\n"; _class = _dClass;
_name = name;
_hit = _dHit;
_energy = _dEnergy;
_attack = _dAttack;
_number = getTotalNumber();
std::cout << _class << " " << _name << "-" << _number << " created\n";
return; return;
} }
/*
* destructor
*/
ClapTrap::~ClapTrap( void ) {
std::cout << _class << " " << _name << " destructed\n";
return;
}
/*
* copy constructor
*/
ClapTrap::ClapTrap( ClapTrap const & src ) { ClapTrap::ClapTrap( ClapTrap const & src ) {
std::cout << _class << " " << _name << " copied\n"; ClapTrap::_increaseNumber();
_class = _dClass;
*this = src; *this = src;
_number = getTotalNumber();
std::cout << _class << " " << _name << "-" << _number << " copied from " << src._class << " " << src._name << "-" << src._number << "\n";
return; return;
} }
/* /*********************************************
* assignement operator * DESTRUCTORS
*/ *********************************************/
ClapTrap::~ClapTrap( void ) {
std::cout << _class << " " << _name << "-" << _number << " destructed\n";
return;
}
/*********************************************
* OPERATORS
*********************************************/
ClapTrap & ClapTrap::operator=( ClapTrap const & rhs ) { ClapTrap & ClapTrap::operator=( ClapTrap const & rhs ) {
if ( this != &rhs ) if ( this != &rhs )
{ {
this->_hit = rhs.getHit(); _name = rhs.getName();
this->_energy = rhs.getEnergy(); _hit = rhs.getHit();
this->_attack = rhs.getAttack(); _energy = rhs.getEnergy();
_attack = rhs.getAttack();
_number = rhs.getNumber();
} }
std::cout << _class << " " << _name << " assigned\n"; std::cout << _class << " " << _name << "-" << _number << " assigned\n";
return *this; return *this;
} }
/* /*********************************************
* constructor * ACCESSORS
*/ *********************************************/
ClapTrap::ClapTrap( std::string name ) : _name(name) {
ClapTrap::_increaseNumber();
_class = "ClapTrap";
_hit = 10;
_energy = 10;
_attack = 1;
_number = _getNumber();
std::cout << _class << " " << _name << " created with number " << _number << "\n";
return;
}
/*
* getters
*/
std::string ClapTrap::getName() const {return _name;} std::string ClapTrap::getName() const {return _name;}
std::string ClapTrap::getClass() const {return _class;}
int ClapTrap::getHit() const {return _hit;} int ClapTrap::getHit() const {return _hit;}
int ClapTrap::getEnergy() const {return _energy;} int ClapTrap::getEnergy() const {return _energy;}
int ClapTrap::getAttack() const {return _attack;} int ClapTrap::getAttack() const {return _attack;}
int ClapTrap::_getNumber() {return ClapTrap::_totalNumber;} int ClapTrap::getNumber() const {return _number;}
int ClapTrap::getTotalNumber() const {return _totalNumber;}
void ClapTrap::_increaseNumber() {ClapTrap::_totalNumber++;} void ClapTrap::_increaseNumber() {ClapTrap::_totalNumber++;}
/* /*********************************************
* robots * PUBLIC MEMBER FUNCTIONS
*/ *********************************************/
void ClapTrap::attack(const std::string & target) { void ClapTrap::attack(const std::string & target) {
@@ -92,7 +88,7 @@ void ClapTrap::attack(const std::string & target) {
std::ostringstream state; std::ostringstream state;
state << B_CYAN "[" B_GREEN << _class[0] << _number << B_PURPLE "h,e,a" B_CYAN ":" B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "->"; state << B_CYAN "[" B_GREEN << _class[0] << _number << B_PURPLE "h,e,a" B_CYAN ":" B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "->";
action << _class << " " << _name; action << _class << " " << _name << "-" << _number;
if (_energy > 0 && _hit > 0) if (_energy > 0 && _hit > 0)
{ {
@@ -120,22 +116,17 @@ void ClapTrap::takeDamage(unsigned int amount) {
std::ostringstream state; std::ostringstream state;
state << B_CYAN "[" B_GREEN << _class[0] << _number << B_PURPLE "h,e,a" B_CYAN ":" B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "->"; state << B_CYAN "[" B_GREEN << _class[0] << _number << B_PURPLE "h,e,a" B_CYAN ":" B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "->";
action << _class << " " << _name; action << _class << " " << _name << "-" << _number;
if (_energy > 0 && _hit > 0) if (_hit > 0)
{ {
_hit -= amount; _hit -= amount;
if (_hit < 0) if (_hit < 0)
_hit = 0; _hit = 0;
action << " looses " B_YELLOW << amount << RESET << " hit points" << '\n'; action << " looses " B_YELLOW << amount << RESET << " hit points" << '\n';
} }
else else if (_hit <= 0)
{ action << " cannot take damage because " B_RED " is out of hit" RESET "\n";
if (_energy <= 0)
action << " cannot take damage because " B_RED " is out of energy" RESET "\n";
else if (_hit <= 0)
action << " cannot take damage because " B_RED " is out of hit" RESET "\n";
}
state << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET; state << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET;
std::cout << state.str() << action.str(); std::cout << state.str() << action.str();
@@ -147,7 +138,7 @@ void ClapTrap::beRepaired(unsigned int amount) {
std::ostringstream state; std::ostringstream state;
state << B_CYAN "[" B_GREEN << _class[0] << _number << B_PURPLE "h,e,a" B_CYAN ":" B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "->"; state << B_CYAN "[" B_GREEN << _class[0] << _number << B_PURPLE "h,e,a" B_CYAN ":" B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "->";
action << _class << " " << _name; action << _class << " " << _name << "-" << _number;
if (_energy > 0 && _hit > 0) if (_energy > 0 && _hit > 0)
{ {
@@ -168,3 +159,16 @@ void ClapTrap::beRepaired(unsigned int amount) {
state << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET; state << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET;
std::cout << state.str() << action.str(); std::cout << state.str() << action.str();
} }
/*********************************************
* STATICS
*********************************************/
int ClapTrap::_totalNumber = 0;
std::string const ClapTrap::_dName = "robot";
std::string const ClapTrap::_dClass = "ClapTrap";
int const ClapTrap::_dHit = 10;
int const ClapTrap::_dEnergy = 10;
int const ClapTrap::_dAttack = 0;

View File

@@ -4,13 +4,12 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <color.h>
class ClapTrap { class ClapTrap {
public: public:
ClapTrap( std::string name ); // default/parametric constructor ClapTrap( std::string name = ClapTrap::_dName );
ClapTrap( ClapTrap const & src ); // copy constructor ClapTrap( ClapTrap const & src ); // copy constructor
~ClapTrap( void ); // destructor ~ClapTrap( void ); // destructor
@@ -21,28 +20,37 @@ public:
void beRepaired(unsigned int amount); void beRepaired(unsigned int amount);
std::string getName() const; std::string getName() const;
std::string getClass() const;
int getHit() const; int getHit() const;
int getEnergy() const; int getEnergy() const;
int getAttack() const; int getAttack() const;
int getNumber() const;
protected: protected:
std::string const _name; int getTotalNumber() const;
std::string _class;
int _hit; std::string _name;
int _energy; std::string _class;
int _attack; int _hit;
int _number; int _energy;
int _attack;
int _number;
int _getNumber();
void _increaseNumber(); void _increaseNumber();
private: private:
ClapTrap( void ); // default/parametric constructor void assignValues(ClapTrap & src);
static int _totalNumber; static int _totalNumber;
static const std::string _dName;
static const std::string _dClass;
static const int _dHit;
static const int _dEnergy;
static const int _dAttack;
static const int _dNumber;
}; };
#endif #endif

View File

@@ -1,30 +1,59 @@
#include "FragTrap.hpp" #include "FragTrap.hpp"
/*********************************************
* CONSTRUCTORS
*********************************************/
FragTrap::FragTrap( std::string name ) : ClapTrap(name) { FragTrap::FragTrap( std::string name ) : ClapTrap(name) {
_class = _dClass;
_class = "FragTrap"; _hit = _dHit;
_hit = 100; _energy = _dEnergy;
_energy = 100; _attack = _dAttack;
_attack = 30; std::cout << _class << " " << _name << "-" << _number << " created\n";
std::cout << _class << " " << FragTrap::_name << " created with number " << _number << "\n";
return; return;
} }
/* FragTrap::FragTrap( FragTrap const & src ) {
* destructor _class = _dClass;
*/ *this = src;
_number = getTotalNumber();
std::cout << _class << " " << _name << "-" << _number << " copied from " << src._class << "-" << src._name << "-" << src._number << "\n";
return;
}
/*********************************************
* DESTRUCTORS
*********************************************/
FragTrap::~FragTrap( void ) { FragTrap::~FragTrap( void ) {
std::cout << _class << " " << FragTrap::_name << " destructed\n"; std::cout << _class << " " << FragTrap::_name << " destructed\n";
return; return;
} }
/* /*********************************************
* special capacity * OPERATORS
*/ *********************************************/
FragTrap & FragTrap::operator=( FragTrap const & rhs ) {
ClapTrap::operator=(rhs);
return *this;
}
/*********************************************
* PUBLIC MEMBER FUNCTIONS
*********************************************/
void FragTrap::highFivesGuys() { void FragTrap::highFivesGuys() {
std::cout << _class << " " << FragTrap::_name << " wait for a high fives, common guys\n"; std::cout << _class << " " << FragTrap::_name << " wait for a high fives, common guys\n";
} }
/*********************************************
* STATICS
*********************************************/
std::string const FragTrap::_dName = "robot";
std::string const FragTrap::_dClass = "FragTrap";
int const FragTrap::_dHit = 100;
int const FragTrap::_dEnergy = 100;
int const FragTrap::_dAttack = 50;

View File

@@ -8,12 +8,23 @@
class FragTrap : public ClapTrap { class FragTrap : public ClapTrap {
public: public:
FragTrap( std::string name = FragTrap::_dName );
FragTrap( FragTrap const & src ); // copy constructor
~FragTrap(); // destructor
FragTrap(std::string name); FragTrap & operator=( FragTrap const & rhs ); // assignement operator
~FragTrap( void );
void highFivesGuys(); void highFivesGuys();
private:
static const std::string _dName;
static const std::string _dClass;
static const int _dHit;
static const int _dEnergy;
static const int _dAttack;
static const int _dNumber;
}; };
#endif #endif

View File

@@ -1,30 +1,59 @@
#include "ScavTrap.hpp" #include "ScavTrap.hpp"
/*********************************************
* CONSTRUCTORS
*********************************************/
ScavTrap::ScavTrap( std::string name ) : ClapTrap(name) { ScavTrap::ScavTrap( std::string name ) : ClapTrap(name) {
_class = _dClass;
_class = "ScavTrap"; _hit = _dHit;
_hit = 100; _energy = _dEnergy;
_energy = 50; _attack = _dAttack;
_attack = 20; std::cout << _class << " " << _name << "-" << _number << " created\n";
std::cout << _class << " " << ScavTrap::_name << " created with number " << _number << "\n";
return; return;
} }
/* ScavTrap::ScavTrap( ScavTrap const & src ) {
* destructor _class = _dClass;
*/ *this = src;
_number = getTotalNumber();
std::cout << _class << " " << _name << "-" << _number << " copied from " << src._class << "-" << src._name << "-" << src._number << "\n";
return;
}
/*********************************************
* DESTRUCTORS
*********************************************/
ScavTrap::~ScavTrap( void ) { ScavTrap::~ScavTrap( void ) {
std::cout << _class << " " << ScavTrap::_name << " destructed\n"; std::cout << _class << " " << _name << "-" << _number << " destructed\n";
return; return;
} }
/* /*********************************************
* special capacity * OPERATORS
*/ *********************************************/
ScavTrap & ScavTrap::operator=( ScavTrap const & rhs ) {
ClapTrap::operator=(rhs);
return *this;
}
/*********************************************
* PUBLIC MEMBER FUNCTIONS
*********************************************/
void ScavTrap::guardGate() { void ScavTrap::guardGate() {
std::cout << _class << " " << ScavTrap::_name << " entered special mode Gate Keeper\n"; std::cout << _class << " " << _name << "-" << _number << " entered special mode Gate Keeper\n";
} }
/*********************************************
* STATICS
*********************************************/
std::string const ScavTrap::_dName = "robot";
std::string const ScavTrap::_dClass = "ScavTrap";
int const ScavTrap::_dHit = 100;
int const ScavTrap::_dEnergy = 50;
int const ScavTrap::_dAttack = 20;

View File

@@ -9,11 +9,23 @@ class ScavTrap : public ClapTrap {
public: public:
ScavTrap(std::string name); ScavTrap( std::string name = ScavTrap::_dName );
~ScavTrap(); ScavTrap( ScavTrap const & src ); // copy constructor
~ScavTrap(); // destructor
ScavTrap & operator=( ScavTrap const & rhs ); // assignement operator
void guardGate(); void guardGate();
private:
static const std::string _dName;
static const std::string _dClass;
static const int _dHit;
static const int _dEnergy;
static const int _dAttack;
static const int _dNumber;
}; };
#endif #endif

View File

@@ -1,24 +0,0 @@
#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

View File

@@ -1,103 +1,35 @@
#include "ClapTrap.hpp"
#include "ScavTrap.hpp" #include "ScavTrap.hpp"
#include "FragTrap.hpp" #include "FragTrap.hpp"
void goAttack(ClapTrap & robot1, ClapTrap & robot2) { #include <iostream>
#include <sstream>
# 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"
# define COLOR1 B_YELLOW
template < typename U, typename V >
void goAttack(U & robot1, V & robot2) {
std::stringstream ss;
std::string num;
ss << robot2.getNumber();
ss >> num;
std::cout << "."; std::cout << ".";
robot1.attack(robot2.getName()); robot1.attack(robot2.getName() + "-" + num);
std::cout << " "; std::cout << " ";
robot2.takeDamage(robot1.getAttack()); robot2.takeDamage(robot1.getAttack());
std::cout << " "; std::cout << " ";
robot2.beRepaired(robot1.getAttack()); robot2.beRepaired(robot1.getAttack());
}
void goAttack(ClapTrap & robot1, ScavTrap & robot2) {
std::cout << ".";
robot1.attack(robot2.getName());
std::cout << " ";
robot2.takeDamage(robot1.getAttack());
std::cout << " ";
robot2.beRepaired(robot1.getAttack());
}
void goAttack(ClapTrap & robot1, FragTrap & robot2) {
std::cout << ".";
robot1.attack(robot2.getName());
std::cout << " ";
robot2.takeDamage(robot1.getAttack());
std::cout << " ";
robot2.beRepaired(robot1.getAttack());
}
void goAttack(ScavTrap & robot1, ScavTrap & robot2) {
std::cout << ".";
robot1.attack(robot2.getName());
std::cout << " ";
robot2.takeDamage(robot1.getAttack());
std::cout << " ";
robot2.beRepaired(robot1.getAttack());
}
void goAttack(ScavTrap & robot1, ClapTrap & robot2) {
std::cout << ".";
robot1.attack(robot2.getName());
std::cout << " ";
robot2.takeDamage(robot1.getAttack());
std::cout << " ";
robot2.beRepaired(robot1.getAttack());
}
void goAttack(ScavTrap & robot1, FragTrap & robot2) {
std::cout << ".";
robot1.attack(robot2.getName());
std::cout << " ";
robot2.takeDamage(robot1.getAttack());
std::cout << " ";
robot2.beRepaired(robot1.getAttack());
}
void goAttack(FragTrap & robot1, FragTrap & robot2) {
std::cout << ".";
robot1.attack(robot2.getName());
std::cout << " ";
robot2.takeDamage(robot1.getAttack());
std::cout << " ";
robot2.beRepaired(robot1.getAttack());
}
void goAttack(FragTrap & robot1, ClapTrap & robot2) {
std::cout << ".";
robot1.attack(robot2.getName());
std::cout << " ";
robot2.takeDamage(robot1.getAttack());
std::cout << " ";
robot2.beRepaired(robot1.getAttack());
}
void goAttack(FragTrap & robot1, ScavTrap & robot2) {
std::cout << ".";
robot1.attack(robot2.getName());
std::cout << " ";
robot2.takeDamage(robot1.getAttack());
std::cout << " ";
robot2.beRepaired(robot1.getAttack());
} }
int main() { int main() {

Binary file not shown.