diff --git a/d03/ex01/ClapTrap.cpp b/d03/ex01/ClapTrap.cpp index 54a4994..2a00cc4 100644 --- a/d03/ex01/ClapTrap.cpp +++ b/d03/ex01/ClapTrap.cpp @@ -1,16 +1,5 @@ #include "ClapTrap.hpp" -# 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" - /********************************************* * CONSTRUCTORS *********************************************/ diff --git a/d03/ex01/ClapTrap.hpp b/d03/ex01/ClapTrap.hpp index a0beeca..fa8d411 100644 --- a/d03/ex01/ClapTrap.hpp +++ b/d03/ex01/ClapTrap.hpp @@ -5,6 +5,17 @@ #include #include +# 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" + class ClapTrap { public: diff --git a/d03/ex01/ScavTrap.cpp b/d03/ex01/ScavTrap.cpp index fa611e7..6ceacd4 100644 --- a/d03/ex01/ScavTrap.cpp +++ b/d03/ex01/ScavTrap.cpp @@ -43,6 +43,34 @@ ScavTrap & ScavTrap::operator=( ScavTrap const & rhs ) { * PUBLIC MEMBER FUNCTIONS *********************************************/ +void ScavTrap::attack(const std::string & target) { + + std::ostringstream action; + 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 "->"; + action << _class << " " << _name << "-" << _number << B_CYAN " SPECIAL SCAV" RESET; + + if (_energy > 0 && _hit > 0) + { + _energy--; + if (_energy < 0) + _energy = 0; + action << " attacked " << target << ", causing " B_YELLOW << _attack << RESET << " points of damage" << '\n'; + } + else + { + _attack = 0; + if (_energy <= 0) + action << " cannot attack because " B_RED " is out of energy" RESET"\n"; + else if (_hit <= 0) + action << " cannot attack because " B_RED " is out of hit" RESET "\n"; + } + + state << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET; + std::cout << state.str() << action.str(); +} + void ScavTrap::guardGate() { std::cout << _class << " " << _name << "-" << _number << " entered special mode Gate Keeper\n"; } diff --git a/d03/ex01/ScavTrap.hpp b/d03/ex01/ScavTrap.hpp index 7a627fc..2fe17f4 100644 --- a/d03/ex01/ScavTrap.hpp +++ b/d03/ex01/ScavTrap.hpp @@ -5,6 +5,17 @@ #include #include "ClapTrap.hpp" +# 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" + class ScavTrap : public ClapTrap { public: @@ -16,6 +27,7 @@ public: ScavTrap & operator=( ScavTrap const & rhs ); // assignement operator void guardGate(); + void attack(const std::string & target); private: diff --git a/d03/ex01/robots b/d03/ex01/robots new file mode 100755 index 0000000..a69d2a5 Binary files /dev/null and b/d03/ex01/robots differ diff --git a/d03/ex02/ClapTrap.cpp b/d03/ex02/ClapTrap.cpp index 54a4994..2a00cc4 100644 --- a/d03/ex02/ClapTrap.cpp +++ b/d03/ex02/ClapTrap.cpp @@ -1,16 +1,5 @@ #include "ClapTrap.hpp" -# 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" - /********************************************* * CONSTRUCTORS *********************************************/ diff --git a/d03/ex02/ClapTrap.hpp b/d03/ex02/ClapTrap.hpp index a0beeca..fa8d411 100644 --- a/d03/ex02/ClapTrap.hpp +++ b/d03/ex02/ClapTrap.hpp @@ -5,6 +5,17 @@ #include #include +# 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" + class ClapTrap { public: diff --git a/d03/ex02/ScavTrap.cpp b/d03/ex02/ScavTrap.cpp index fa611e7..6ceacd4 100644 --- a/d03/ex02/ScavTrap.cpp +++ b/d03/ex02/ScavTrap.cpp @@ -43,6 +43,34 @@ ScavTrap & ScavTrap::operator=( ScavTrap const & rhs ) { * PUBLIC MEMBER FUNCTIONS *********************************************/ +void ScavTrap::attack(const std::string & target) { + + std::ostringstream action; + 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 "->"; + action << _class << " " << _name << "-" << _number << B_CYAN " SPECIAL SCAV" RESET; + + if (_energy > 0 && _hit > 0) + { + _energy--; + if (_energy < 0) + _energy = 0; + action << " attacked " << target << ", causing " B_YELLOW << _attack << RESET << " points of damage" << '\n'; + } + else + { + _attack = 0; + if (_energy <= 0) + action << " cannot attack because " B_RED " is out of energy" RESET"\n"; + else if (_hit <= 0) + action << " cannot attack because " B_RED " is out of hit" RESET "\n"; + } + + state << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET; + std::cout << state.str() << action.str(); +} + void ScavTrap::guardGate() { std::cout << _class << " " << _name << "-" << _number << " entered special mode Gate Keeper\n"; } diff --git a/d03/ex02/ScavTrap.hpp b/d03/ex02/ScavTrap.hpp index 7a627fc..2fe17f4 100644 --- a/d03/ex02/ScavTrap.hpp +++ b/d03/ex02/ScavTrap.hpp @@ -5,6 +5,17 @@ #include #include "ClapTrap.hpp" +# 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" + class ScavTrap : public ClapTrap { public: @@ -16,6 +27,7 @@ public: ScavTrap & operator=( ScavTrap const & rhs ); // assignement operator void guardGate(); + void attack(const std::string & target); private: diff --git a/d03/ex02/robots b/d03/ex02/robots index 5dbb391..9a7e859 100755 Binary files a/d03/ex02/robots and b/d03/ex02/robots differ diff --git a/d03/ex03/ClapTrap.cpp b/d03/ex03/ClapTrap.cpp index 54a4994..2a00cc4 100644 --- a/d03/ex03/ClapTrap.cpp +++ b/d03/ex03/ClapTrap.cpp @@ -1,16 +1,5 @@ #include "ClapTrap.hpp" -# 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" - /********************************************* * CONSTRUCTORS *********************************************/ diff --git a/d03/ex03/ClapTrap.hpp b/d03/ex03/ClapTrap.hpp index a0beeca..e4a586c 100644 --- a/d03/ex03/ClapTrap.hpp +++ b/d03/ex03/ClapTrap.hpp @@ -5,6 +5,22 @@ #include #include +#ifndef COLORS_MACRO +# define COLORS_MACRO + +# 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 + class ClapTrap { public: diff --git a/d03/ex03/DiamondTrap.cpp b/d03/ex03/DiamondTrap.cpp index e8a344d..666f12d 100644 --- a/d03/ex03/DiamondTrap.cpp +++ b/d03/ex03/DiamondTrap.cpp @@ -28,7 +28,7 @@ DiamondTrap::DiamondTrap( DiamondTrap const & src ) { *********************************************/ DiamondTrap::~DiamondTrap( void ) { - std::cout << _class << " " << DiamondTrap::_name << " destructed\n"; + std::cout << _class << " " << _name << "-" << _number << " destructed\n"; return; } @@ -46,7 +46,8 @@ DiamondTrap & DiamondTrap::operator=( DiamondTrap const & rhs ) { *********************************************/ void DiamondTrap::whoAmI() { - std::cout << _class << " " << DiamondTrap::_name << " wait for a high fives, common guys\n"; + std::cout << _class << B_CYAN " I AM DIAMOND" RESET << " " << _name << "-" << _number; + std::cout << B_CYAN " and clap" RESET << " " << ClapTrap::_name << "-" << _number << "\n"; } /********************************************* @@ -55,7 +56,7 @@ void DiamondTrap::whoAmI() { std::string const DiamondTrap::_dName = "robot"; std::string const DiamondTrap::_dClass = "DiamondTrap"; -int const DiamondTrap::_dHit = 100; -int const DiamondTrap::_dEnergy = 100; -int const DiamondTrap::_dAttack = 50; +int const DiamondTrap::_dHit = FragTrap::_dHit; +int const DiamondTrap::_dEnergy = ScavTrap::_dEnergy; +int const DiamondTrap::_dAttack = FragTrap::_dAttack; diff --git a/d03/ex03/DiamondTrap.hpp b/d03/ex03/DiamondTrap.hpp index 63cd4a0..6f78ddd 100644 --- a/d03/ex03/DiamondTrap.hpp +++ b/d03/ex03/DiamondTrap.hpp @@ -7,6 +7,22 @@ # include "FragTrap.hpp" # include "ScavTrap.hpp" +#ifndef COLORS_MACRO +# define COLORS_MACRO + +# 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 + class DiamondTrap : public FragTrap, public ScavTrap { public: @@ -19,6 +35,8 @@ public: void whoAmI(); + using ScavTrap::attack; + private: std::string _name; diff --git a/d03/ex03/FragTrap.cpp b/d03/ex03/FragTrap.cpp index c8b4285..16c32be 100644 --- a/d03/ex03/FragTrap.cpp +++ b/d03/ex03/FragTrap.cpp @@ -26,7 +26,7 @@ FragTrap::FragTrap( FragTrap const & src ) { *********************************************/ FragTrap::~FragTrap( void ) { - std::cout << _class << " " << FragTrap::_name << " destructed\n"; + std::cout << _class << " " << _name << "-" << _number << " destructed\n"; return; } @@ -43,8 +43,36 @@ FragTrap & FragTrap::operator=( FragTrap const & rhs ) { * PUBLIC MEMBER FUNCTIONS *********************************************/ +//void FragTrap::attack(const std::string & target) { +// +// std::ostringstream action; +// 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 "->"; +// action << _class << " " << _name << "-" << _number << B_CYAN " SPECIAL FRAG" RESET; +// +// if (_energy > 0 && _hit > 0) +// { +// _energy--; +// if (_energy < 0) +// _energy = 0; +// action << " attacked " << target << ", causing " B_YELLOW << _attack << RESET << " points of damage" << '\n'; +// } +// else +// { +// _attack = 0; +// if (_energy <= 0) +// action << " cannot attack because " B_RED " is out of energy" RESET"\n"; +// else if (_hit <= 0) +// action << " cannot attack because " B_RED " is out of hit" RESET "\n"; +// } +// +// state << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET; +// std::cout << state.str() << action.str(); +//} + void FragTrap::highFivesGuys() { - std::cout << _class << " " << FragTrap::_name << " wait for a high fives, common guys\n"; + std::cout << _class << " " << _name << "-" << _number << " wait for a high fives, common guys\n"; } /********************************************* @@ -55,5 +83,5 @@ 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; +int const FragTrap::_dAttack = 30; diff --git a/d03/ex03/FragTrap.hpp b/d03/ex03/FragTrap.hpp index b1abd7a..0fbfe71 100644 --- a/d03/ex03/FragTrap.hpp +++ b/d03/ex03/FragTrap.hpp @@ -16,8 +16,9 @@ public: FragTrap & operator=( FragTrap const & rhs ); // assignement operator void highFivesGuys(); +// void attack(const std::string & target); -private: +protected: static const std::string _dName; static const std::string _dClass; diff --git a/d03/ex03/Makefile b/d03/ex03/Makefile index a616a9a..b31dfea 100644 --- a/d03/ex03/Makefile +++ b/d03/ex03/Makefile @@ -7,7 +7,10 @@ NAME = robots CC = c++ -CFLAGS = -Wall -Wextra -Werror $(INCLUDES) -std=c++98 +CFLAGS = -Wall -Wextra -Werror \ + -Wshadow \ + $(INCLUDES) \ + -std=c++98 VPATH = $(D_SRCS) diff --git a/d03/ex03/ScavTrap.cpp b/d03/ex03/ScavTrap.cpp index fa611e7..6ceacd4 100644 --- a/d03/ex03/ScavTrap.cpp +++ b/d03/ex03/ScavTrap.cpp @@ -43,6 +43,34 @@ ScavTrap & ScavTrap::operator=( ScavTrap const & rhs ) { * PUBLIC MEMBER FUNCTIONS *********************************************/ +void ScavTrap::attack(const std::string & target) { + + std::ostringstream action; + 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 "->"; + action << _class << " " << _name << "-" << _number << B_CYAN " SPECIAL SCAV" RESET; + + if (_energy > 0 && _hit > 0) + { + _energy--; + if (_energy < 0) + _energy = 0; + action << " attacked " << target << ", causing " B_YELLOW << _attack << RESET << " points of damage" << '\n'; + } + else + { + _attack = 0; + if (_energy <= 0) + action << " cannot attack because " B_RED " is out of energy" RESET"\n"; + else if (_hit <= 0) + action << " cannot attack because " B_RED " is out of hit" RESET "\n"; + } + + state << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET; + std::cout << state.str() << action.str(); +} + void ScavTrap::guardGate() { std::cout << _class << " " << _name << "-" << _number << " entered special mode Gate Keeper\n"; } diff --git a/d03/ex03/ScavTrap.hpp b/d03/ex03/ScavTrap.hpp index adb914c..0c25ee4 100644 --- a/d03/ex03/ScavTrap.hpp +++ b/d03/ex03/ScavTrap.hpp @@ -5,6 +5,22 @@ #include #include "ClapTrap.hpp" +#ifndef COLORS_MACRO +# define COLORS_MACRO + +# 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 + class ScavTrap : public virtual ClapTrap { public: @@ -16,8 +32,9 @@ public: ScavTrap & operator=( ScavTrap const & rhs ); // assignement operator void guardGate(); + void attack(const std::string & target); -private: +protected: static const std::string _dName; static const std::string _dClass; diff --git a/d03/ex03/main.cpp b/d03/ex03/main.cpp index 1297e29..25a3413 100644 --- a/d03/ex03/main.cpp +++ b/d03/ex03/main.cpp @@ -22,9 +22,9 @@ int main() { FragTrap robot1("robot1"); ClapTrap robot2("robot2"); ScavTrap robot3("robot3"); - std::cout << "tout\n"; + std::cout << "start\n"; DiamondTrap robot4("robot4"); - std::cout << "tend\n"; + std::cout << "end\n"; ClapTrap robot5("robot5"); ScavTrap robot6("robot6"); FragTrap robot7("robot7"); @@ -54,7 +54,7 @@ robot3.guardGate(); goAttack(robot1, robot9); goAttack(robot9, robot6); goAttack(robot9, robot2); -robot4.guardGate(); +robot6.guardGate(); robot1.highFivesGuys(); robot7.highFivesGuys(); goAttack(robot3, robot4); @@ -65,6 +65,7 @@ robot7.highFivesGuys(); goAttack(robot2, robot4); goAttack(robot9, robot6); goAttack(robot3, robot2); +robot4.whoAmI(); goAttack(robot6, robot5); goAttack(robot4, robot9); goAttack(robot7, robot6); diff --git a/d03/ex03/robots b/d03/ex03/robots index 5e22321..23d4c8b 100755 Binary files a/d03/ex03/robots and b/d03/ex03/robots differ