d03 ex03 a priori ok
This commit is contained in:
@@ -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
|
||||
*********************************************/
|
||||
|
||||
@@ -5,6 +5,17 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
# 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:
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -5,6 +5,17 @@
|
||||
#include <string>
|
||||
#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:
|
||||
|
||||
|
||||
BIN
d03/ex01/robots
Executable file
BIN
d03/ex01/robots
Executable file
Binary file not shown.
@@ -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
|
||||
*********************************************/
|
||||
|
||||
@@ -5,6 +5,17 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
# 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:
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -5,6 +5,17 @@
|
||||
#include <string>
|
||||
#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:
|
||||
|
||||
|
||||
BIN
d03/ex02/robots
BIN
d03/ex02/robots
Binary file not shown.
@@ -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
|
||||
*********************************************/
|
||||
|
||||
@@ -5,6 +5,22 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#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:
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -5,6 +5,22 @@
|
||||
#include <string>
|
||||
#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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
BIN
d03/ex03/robots
BIN
d03/ex03/robots
Binary file not shown.
Reference in New Issue
Block a user