d03 ex00 messages et actions plus au point
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ClapTrap::ClapTrap( void ) {
|
ClapTrap::ClapTrap( void ) {
|
||||||
|
std::cout << "claptrap created without name\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -13,6 +14,7 @@ ClapTrap::ClapTrap( void ) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ClapTrap::~ClapTrap( void ) {
|
ClapTrap::~ClapTrap( void ) {
|
||||||
|
std::cout << "claptrap " << _name << " destructed\n";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,6 +23,7 @@ ClapTrap::~ClapTrap( void ) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ClapTrap::ClapTrap( ClapTrap const & src ) {
|
ClapTrap::ClapTrap( ClapTrap const & src ) {
|
||||||
|
std::cout << "claptrap " << _name << " copied\n";
|
||||||
*this = src;
|
*this = src;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -30,6 +33,7 @@ ClapTrap::ClapTrap( ClapTrap const & src ) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ClapTrap & ClapTrap::operator=( ClapTrap const & rhs ) {
|
ClapTrap & ClapTrap::operator=( ClapTrap const & rhs ) {
|
||||||
|
std::cout << "claptrap " << _name << " assigned\n";
|
||||||
|
|
||||||
if ( this != &rhs )
|
if ( this != &rhs )
|
||||||
{
|
{
|
||||||
@@ -47,6 +51,7 @@ ClapTrap & ClapTrap::operator=( ClapTrap const & rhs ) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
ClapTrap::ClapTrap( std::string name ) : _name(name) {
|
ClapTrap::ClapTrap( std::string name ) : _name(name) {
|
||||||
|
std::cout << "claptrap " << _name << " created\n";
|
||||||
_hit = 10;
|
_hit = 10;
|
||||||
_energy = 10;
|
_energy = 10;
|
||||||
_attack = 1;
|
_attack = 1;
|
||||||
@@ -67,36 +72,78 @@ int ClapTrap::getAttack() const {return _attack;}
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
void ClapTrap::attack(const std::string & target) {
|
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::ostringstream action;
|
||||||
|
std::ostringstream state;
|
||||||
|
|
||||||
std::cout << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET
|
state << B_CYAN "[" B_PURPLE "h,e,a" B_CYAN ":" B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "->";
|
||||||
<< " ClapTrap " << _name
|
action << " ClapTrap " << _name;
|
||||||
<< " attacked " << target
|
|
||||||
<< ", causing " B_YELLOW << _attack << RESET
|
if (_energy && _hit)
|
||||||
<< " points of damage!" << '\n';
|
{
|
||||||
|
_energy--;
|
||||||
|
action << " attacked " << target << ", causing " B_YELLOW << _attack << RESET << " points of damage!" << '\n';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_attack = 0;
|
||||||
|
if (!_energy)
|
||||||
|
action << "cannot attack because " B_RED " is out of energy\n" RESET;
|
||||||
|
else if (!_hit)
|
||||||
|
action << "cannot attack because " B_RED " is out of hit\n" RESET;
|
||||||
|
}
|
||||||
|
|
||||||
|
state << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET;
|
||||||
|
std::cout << state.str() << action.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClapTrap::takeDamage(unsigned int amount) {
|
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::ostringstream action;
|
||||||
|
std::ostringstream state;
|
||||||
|
|
||||||
std::cout << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET
|
state << B_CYAN "[" B_PURPLE "h,e,a" B_CYAN ":" B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "->";
|
||||||
<< " ClapTrap " << _name
|
action << " ClapTrap " << _name;
|
||||||
<< " looses " B_YELLOW << amount << RESET
|
|
||||||
<< " points of damage :/" << '\n';
|
if (_energy && _hit)
|
||||||
|
{
|
||||||
|
_hit -= amount;
|
||||||
|
action << " looses " B_YELLOW << amount << RESET << " points of damage :/" << '\n';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
state << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET;
|
||||||
|
std::cout << state.str() << action.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClapTrap::beRepaired(unsigned int amount) {
|
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--;
|
std::ostringstream action;
|
||||||
_hit += amount;
|
std::ostringstream state;
|
||||||
|
|
||||||
std::cout << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET
|
state << B_CYAN "[" B_PURPLE "h,e,a" B_CYAN ":" B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "->";
|
||||||
<< " ClapTrap " << _name
|
action << " ClapTrap " << _name;
|
||||||
<< " repaired itself and gained " B_YELLOW << amount << RESET
|
|
||||||
<< " points of life :)" << '\n';
|
if (_energy && _hit)
|
||||||
|
{
|
||||||
|
_energy--;
|
||||||
|
_hit += amount;
|
||||||
|
action << " repaired itself and gained " B_YELLOW << amount << RESET << " points of life :)" << '\n';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!_energy)
|
||||||
|
action << "cannot repair itself because " B_RED " is out of energy\n" RESET;
|
||||||
|
else if (!_hit)
|
||||||
|
action << "cannot repair itself because " B_RED " is out of hit\n" RESET;
|
||||||
|
}
|
||||||
|
|
||||||
|
state << B_BLUE << _hit << "," << _energy << "," << _attack << B_CYAN "]" RESET;
|
||||||
|
std::cout << state.str() << action.str();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
# define CLAPTRAP_HPP
|
# define CLAPTRAP_HPP
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <color.h>
|
#include <color.h>
|
||||||
|
|
||||||
|
|||||||
BIN
d03/ex00/action
BIN
d03/ex00/action
Binary file not shown.
@@ -9,5 +9,45 @@ int main() {
|
|||||||
robot2.takeDamage(robot1.getAttack());
|
robot2.takeDamage(robot1.getAttack());
|
||||||
robot2.beRepaired(robot1.getAttack());
|
robot2.beRepaired(robot1.getAttack());
|
||||||
|
|
||||||
|
robot2.attack(robot1.getName());
|
||||||
|
robot1.takeDamage(robot2.getAttack());
|
||||||
|
robot1.beRepaired(robot2.getAttack());
|
||||||
|
|
||||||
|
robot1.attack(robot2.getName());
|
||||||
|
robot2.takeDamage(robot1.getAttack());
|
||||||
|
robot2.beRepaired(robot1.getAttack());
|
||||||
|
|
||||||
|
robot2.attack(robot1.getName());
|
||||||
|
robot1.takeDamage(robot2.getAttack());
|
||||||
|
robot1.beRepaired(robot2.getAttack());
|
||||||
|
|
||||||
|
robot1.attack(robot2.getName());
|
||||||
|
robot2.takeDamage(robot1.getAttack());
|
||||||
|
robot2.beRepaired(robot1.getAttack());
|
||||||
|
|
||||||
|
robot2.attack(robot1.getName());
|
||||||
|
robot1.takeDamage(robot2.getAttack());
|
||||||
|
robot1.beRepaired(robot2.getAttack());
|
||||||
|
|
||||||
|
robot1.attack(robot2.getName());
|
||||||
|
robot2.takeDamage(robot1.getAttack());
|
||||||
|
robot2.beRepaired(robot1.getAttack());
|
||||||
|
|
||||||
|
robot2.attack(robot1.getName());
|
||||||
|
robot1.takeDamage(robot2.getAttack());
|
||||||
|
robot1.beRepaired(robot2.getAttack());
|
||||||
|
|
||||||
|
robot1.attack(robot2.getName());
|
||||||
|
robot2.takeDamage(robot1.getAttack());
|
||||||
|
robot2.beRepaired(robot1.getAttack());
|
||||||
|
|
||||||
|
robot2.attack(robot1.getName());
|
||||||
|
robot1.takeDamage(robot2.getAttack());
|
||||||
|
robot1.beRepaired(robot2.getAttack());
|
||||||
|
|
||||||
|
robot1.attack(robot2.getName());
|
||||||
|
robot2.takeDamage(robot1.getAttack());
|
||||||
|
robot2.beRepaired(robot1.getAttack());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user