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/ex02/robots
BIN
d03/ex02/robots
Binary file not shown.
Reference in New Issue
Block a user