diff --git a/CPP01/ex05/Harl.cpp b/CPP01/ex05/Harl.cpp index f4029f1..151aa22 100644 --- a/CPP01/ex05/Harl.cpp +++ b/CPP01/ex05/Harl.cpp @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/17 11:14:29 by narnaud #+# #+# */ -/* Updated: 2022/06/17 13:29:12 by narnaud ### ########.fr */ +/* Updated: 2022/06/20 09:30:23 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,17 +16,6 @@ Harl::Harl (void) { std::cout << "Harl default constructor called " << std::endl; } -Harl::Harl (Harl const & src) { - - std::cout << "Harl copy constructor called" << std::endl; -} - -Harl & Harl::operator= (Harl const & src) { - - std::cout << "Harl assignment operator called" << std::endl; - return (*this); -} - Harl::~Harl (void) { std::cout << "Harl default destructor called" << std::endl; @@ -54,13 +43,13 @@ void Harl::_error(void) void Harl::_complain(string level) { - void (Harl::*fcts[])(void) = { + void (Harl::*fct[4])(void) = { &Harl::_debug, &Harl::_info, &Harl::_warning, &Harl::_error}; string ids = "DIWE"; int i = 0; while (ids[i] && ids[i] != level[0]) i++; if (ids[i]) - (Harl::*fcts[i])(); + (this->*fct[i])(); } diff --git a/CPP01/ex05/Harl.hpp b/CPP01/ex05/Harl.hpp index 8d3d069..96baed2 100644 --- a/CPP01/ex05/Harl.hpp +++ b/CPP01/ex05/Harl.hpp @@ -6,7 +6,7 @@ /* By: narnaud +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/06/17 11:13:50 by narnaud #+# #+# */ -/* Updated: 2022/06/17 13:12:45 by narnaud ### ########.fr */ +/* Updated: 2022/06/20 09:30:38 by narnaud ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,9 +20,7 @@ class Harl { public: Harl (void); - Harl (Harl const & src); ~Harl (void); - Harl & operator= (Harl const & src); void _complain(string level); private: diff --git a/CPP01/ex05/Makefile b/CPP01/ex05/Makefile new file mode 100644 index 0000000..b1ed238 --- /dev/null +++ b/CPP01/ex05/Makefile @@ -0,0 +1,20 @@ +NAME = harl +SRCS = main.cpp Harl.cpp +OBJS = ${SRCS:.cpp=.o} + +CXXFLAGS = -std=c++98 -Werror -Wextra -Wall + +$(NAME): $(OBJS) + c++ $(OBJS) -o $(NAME) + +all: $(NAME) + +clean: + rm -rf $(OBJS) + +fclean: clean + rm -rf $(NAME) + +re: fclean all + +.PHONY: all clean fclean re diff --git a/CPP02/ex00/Fixed.cpp b/CPP02/ex00/Fixed.cpp new file mode 100644 index 0000000..c964831 --- /dev/null +++ b/CPP02/ex00/Fixed.cpp @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Fixed.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/20 10:07:44 by narnaud #+# #+# */ +/* Updated: 2022/06/20 10:42:53 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Fixed.hpp" + +const int Fixed::_fract_bits = 8; + +Fixed::Fixed (void) { + + std::cout << "Fixed default constructor called " << std::endl; + _raw_bits = 0; +} + +Fixed::Fixed (const int init_val):_raw_bits(init_val) { + + std::cout << "Fixed parameter constructor called" << std::endl; +} + +Fixed::Fixed (Fixed const & src) { + + std::cout << "Fixed copy constructor called" << std::endl; + _raw_bits = src.getRawBits(); +} + +Fixed & Fixed::operator= (Fixed const & src) { + + std::cout << "Fixed assignment operator called" << std::endl; + _raw_bits = src.getRawBits(); + return (*this); +} + +Fixed::~Fixed (void) { + + std::cout << "Fixed default destructor called" << std::endl; +} + +int Fixed::getRawBits(void) const +{ + std::cout << "getRawBits member function called" << std::endl; + return (_raw_bits); +} + +void Fixed::setRawBits(int const raw) +{ + std::cout << "setRawBits member function called" << std::endl; + _raw_bits = raw; +} diff --git a/CPP02/ex00/Fixed.hpp b/CPP02/ex00/Fixed.hpp new file mode 100644 index 0000000..3478a53 --- /dev/null +++ b/CPP02/ex00/Fixed.hpp @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Fixed.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/20 10:06:37 by narnaud #+# #+# */ +/* Updated: 2022/06/20 10:38:33 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include + +class Fixed { + + public: + + Fixed (void); + Fixed (const int init_val); + Fixed (Fixed const & src); + ~Fixed (void); + Fixed & operator= (Fixed const & src); + int getRawBits(void) const; + void setRawBits(int const raw); + private: + int _raw_bits; + static const int _fract_bits; + +}; diff --git a/CPP02/ex00/Makefile b/CPP02/ex00/Makefile new file mode 100644 index 0000000..4f38769 --- /dev/null +++ b/CPP02/ex00/Makefile @@ -0,0 +1,20 @@ +NAME = fixed +SRCS = main.cpp Fixed.cpp +OBJS = $(SRCS:.cpp=.o) + +CXXFLAGS = -std=c++98 -Werror -Wextra -Wall + +$(NAME): $(OBJS) + c++ $(OBJS) -o $(NAME) + +all: $(NAME) + +clean: + rm -rf $(OBJS) + +fclean: clean + rm -rf $(NAME) + +re: fclean all + +.PHONY: all clean fclean re diff --git a/CPP02/ex00/main.cpp b/CPP02/ex00/main.cpp new file mode 100644 index 0000000..2060f26 --- /dev/null +++ b/CPP02/ex00/main.cpp @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/20 10:07:23 by narnaud #+# #+# */ +/* Updated: 2022/06/20 10:37:27 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Fixed.hpp" + +int main(void) +{ + Fixed a; + Fixed b(a); + Fixed c; + + c = b; + std::cout << a.getRawBits() << std::endl; + std::cout << b.getRawBits() << std::endl; + std::cout << c.getRawBits() << std::endl; + return 0; +} diff --git a/CPP02/ex01/Fixed.cpp b/CPP02/ex01/Fixed.cpp new file mode 100644 index 0000000..6658e4c --- /dev/null +++ b/CPP02/ex01/Fixed.cpp @@ -0,0 +1,80 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Fixed.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/20 10:07:44 by narnaud #+# #+# */ +/* Updated: 2022/06/20 14:15:11 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Fixed.hpp" + +const int Fixed::_fract_bits = 8; + +Fixed::Fixed (void) { + + std::cout << "Fixed default constructor called " << std::endl; + _raw_bits = 0; +} + +Fixed::Fixed (const int init_int) { + + std::cout << "Fixed constructor from interger called " << std::endl; + _raw_bits = init_int * (1 << _fract_bits); +} + +Fixed::Fixed (const float init_float) { + + std::cout << "Fixed constructor from float called " << std::endl; + _raw_bits = std::roundf(init_float * (1 << _fract_bits)); +} + +Fixed::Fixed (Fixed const & src) { + + std::cout << "Fixed copy constructor called" << std::endl; + _raw_bits = src.getRawBits(); +} + +Fixed & Fixed::operator= (Fixed const & src) { + + std::cout << "Fixed assignment operator called" << std::endl; + _raw_bits = src.getRawBits(); + return (*this); +} + +Fixed::~Fixed (void) { + + std::cout << "Fixed default destructor called" << std::endl; +} + +int Fixed::getRawBits(void) const +{ + std::cout << "getRawBits member function called" << std::endl; + return (_raw_bits); +} + +void Fixed::setRawBits(int const raw) +{ + std::cout << "setRawBits member function called" << std::endl; + _raw_bits = raw; +} + +float Fixed::toFloat(void) const { + + //std::cout << "toFloat member function called" << std::endl; + return ((float)((float)_raw_bits / (float)(1 << _fract_bits))); +} + +int Fixed::toInt(void) const { + + //std::cout << "toInt member function called" << std::endl; + return ((int)((float)_raw_bits / (float)(1 << _fract_bits))); +} + +std::ostream & operator << (std::ostream &out, const Fixed &f){ + out << f.toFloat(); + return (out); +} diff --git a/CPP02/ex01/Fixed.hpp b/CPP02/ex01/Fixed.hpp new file mode 100644 index 0000000..349d173 --- /dev/null +++ b/CPP02/ex01/Fixed.hpp @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Fixed.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/20 10:06:37 by narnaud #+# #+# */ +/* Updated: 2022/06/20 14:49:38 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include +#include + +class Fixed { + + public: + + Fixed (void); + Fixed (const int init_int); + Fixed (const float init_float); + Fixed (Fixed const & src); + ~Fixed (void); + Fixed & operator= (Fixed const & src); + int getRawBits(void) const; + void setRawBits(int const raw); + float toFloat(void) const; + int toInt(void) const; + private: + int _raw_bits; + static const int _fract_bits; + +}; +std::ostream & operator << (std::ostream &out, const Fixed &f); diff --git a/CPP02/ex01/Makefile b/CPP02/ex01/Makefile new file mode 100644 index 0000000..4f38769 --- /dev/null +++ b/CPP02/ex01/Makefile @@ -0,0 +1,20 @@ +NAME = fixed +SRCS = main.cpp Fixed.cpp +OBJS = $(SRCS:.cpp=.o) + +CXXFLAGS = -std=c++98 -Werror -Wextra -Wall + +$(NAME): $(OBJS) + c++ $(OBJS) -o $(NAME) + +all: $(NAME) + +clean: + rm -rf $(OBJS) + +fclean: clean + rm -rf $(NAME) + +re: fclean all + +.PHONY: all clean fclean re diff --git a/CPP02/ex01/main.cpp b/CPP02/ex01/main.cpp new file mode 100644 index 0000000..944f370 --- /dev/null +++ b/CPP02/ex01/main.cpp @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/20 10:07:23 by narnaud #+# #+# */ +/* Updated: 2022/06/20 13:35:26 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Fixed.hpp" + +int main(void) +{ + + Fixed a; + Fixed const b( 10 ); + Fixed const c( 42.42f ); + Fixed const d( b ); + Fixed e; + e = d; + + a = Fixed( 1234.4321f ); + + std::cout << a.getRawBits() << std::endl; + std::cout << b.getRawBits() << std::endl; + std::cout << c.getRawBits() << std::endl; + + std::cout << "a is " << a << std::endl; + std::cout << "b is " << b << std::endl; + std::cout << "c is " << c << std::endl; + std::cout << "d is " << d << std::endl; + + std::cout << "a is " << a.toInt() << " as integer" << std::endl; + std::cout << "b is " << b.toInt() << " as integer" << std::endl; + std::cout << "c is " << c.toInt() << " as integer" << std::endl; + std::cout << "d is " << d.toInt() << " as integer" << std::endl; +} diff --git a/CPP02/ex02/Fixed.cpp b/CPP02/ex02/Fixed.cpp new file mode 100644 index 0000000..41ce2b9 --- /dev/null +++ b/CPP02/ex02/Fixed.cpp @@ -0,0 +1,149 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Fixed.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/20 10:07:44 by narnaud #+# #+# */ +/* Updated: 2022/06/23 10:41:09 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Fixed.hpp" + +const int Fixed::_fract_bits = 8; + +Fixed::Fixed (void) { + _raw_bits = 0; +} + +Fixed::Fixed (const int init_int) { + _raw_bits = init_int * (1 << _fract_bits); +} + +Fixed::Fixed (const float init_float) { + _raw_bits = std::roundf(init_float * (1 << _fract_bits)); +} + +Fixed::Fixed (Fixed const & src) { + _raw_bits = src.getRawBits(); +} + +Fixed::~Fixed (void) { +} + +int Fixed::getRawBits(void) const { + return (_raw_bits); +} + +void Fixed::setRawBits(int const raw) { + _raw_bits = raw; +} + +float Fixed::toFloat(void) const { + return ((float)((float)_raw_bits / (float)(1 << _fract_bits))); +} + +int Fixed::toInt(void) const { + return ((int)((float)_raw_bits / (float)(1 << _fract_bits))); +} + +Fixed & Fixed::operator= (Fixed const & src) { + _raw_bits = src.getRawBits(); + return (*this); +} + +Fixed Fixed::operator+ (Fixed const & src) { + return (Fixed(_raw_bits + src.getRawBits())); +} + +Fixed Fixed::operator- (Fixed const & src) { + return (Fixed(_raw_bits - src.getRawBits())); +} + +Fixed Fixed::operator * (Fixed const & src) { + return (Fixed(this->toFloat() * src.toFloat())); +} + +Fixed Fixed::operator / (Fixed const & src) { + return (Fixed(this->toFloat() / src.toFloat())); +} + +Fixed & Fixed::operator++ (void) { + _raw_bits++; + return (*this); +} + +Fixed & Fixed::operator-- (void) { + _raw_bits--; + return (*this); +} +Fixed Fixed::operator++ (int) { + Fixed ret; + ret.setRawBits(_raw_bits++); + return (ret); +} + +Fixed Fixed::operator-- (int) { + Fixed ret; + ret.setRawBits(_raw_bits++); + return (ret); +} + +bool Fixed::operator< (Fixed const & src) { + return (_raw_bits < src.getRawBits()); +} + +bool Fixed::operator> (Fixed const & src) { + return (_raw_bits > src.getRawBits()); +} + +bool Fixed::operator<= (Fixed const & src) { + return (_raw_bits <= src.getRawBits()); +} + +bool Fixed::operator>= (Fixed const & src) { + return (_raw_bits >= src.getRawBits()); +} + +bool Fixed::operator== (Fixed const & src) { + return (_raw_bits == src.getRawBits()); +} + +bool Fixed::operator!= (Fixed const & src) { + return (_raw_bits != src.getRawBits()); +} + +std::ostream & operator << (std::ostream &out, const Fixed &f){ + out << f.toFloat(); + return (out); +} + +Fixed & Fixed::min(Fixed & a, Fixed & b) { + if (a < b) + return (a); + else + return (b); +} + +Fixed & Fixed::max(Fixed & a, Fixed & b) { + if (a > b) + return (a); + else + return (b); +} + +const Fixed & Fixed::min(Fixed const & a, Fixed const & b){ + if (a.getRawBits() < b.getRawBits()) + return (a); + else + return (b); +} + +const Fixed & Fixed::max(Fixed const & a, Fixed const & b){ + if (a.getRawBits() > b.getRawBits()) + return (a); + else + return (b); +} diff --git a/CPP02/ex02/Fixed.hpp b/CPP02/ex02/Fixed.hpp new file mode 100644 index 0000000..67d27f7 --- /dev/null +++ b/CPP02/ex02/Fixed.hpp @@ -0,0 +1,53 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* Fixed.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/20 10:06:37 by narnaud #+# #+# */ +/* Updated: 2022/06/23 10:33:51 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once + +#include +#include + +class Fixed { + + public: + Fixed (void); + Fixed (const int init_int); + Fixed (const float init_float); + Fixed (Fixed const & src); + ~Fixed (void); + Fixed & operator= (Fixed const & src); + Fixed operator+ (Fixed const & src); + Fixed operator- (Fixed const & src); + Fixed operator* (Fixed const & src); + Fixed operator/ (Fixed const & src); + Fixed & operator++ (); + Fixed & operator-- (); + Fixed operator++ (int); + Fixed operator-- (int); + bool operator< (Fixed const & src); + bool operator> (Fixed const & src); + bool operator<= (Fixed const & src); + bool operator>= (Fixed const & src); + bool operator== (Fixed const & src); + bool operator!= (Fixed const & src); + int getRawBits(void) const; + void setRawBits(int const raw); + float toFloat(void) const; + int toInt(void) const; + static Fixed & min(Fixed & a, Fixed & b); + static Fixed & max(Fixed & a, Fixed & b); + static const Fixed & min(Fixed const & a, Fixed const & b); + static const Fixed & max(Fixed const & a, Fixed const & b); + private: + int _raw_bits; + static const int _fract_bits; +}; +std::ostream & operator << (std::ostream &out, const Fixed &f); diff --git a/CPP02/ex02/Makefile b/CPP02/ex02/Makefile new file mode 100644 index 0000000..4f38769 --- /dev/null +++ b/CPP02/ex02/Makefile @@ -0,0 +1,20 @@ +NAME = fixed +SRCS = main.cpp Fixed.cpp +OBJS = $(SRCS:.cpp=.o) + +CXXFLAGS = -std=c++98 -Werror -Wextra -Wall + +$(NAME): $(OBJS) + c++ $(OBJS) -o $(NAME) + +all: $(NAME) + +clean: + rm -rf $(OBJS) + +fclean: clean + rm -rf $(NAME) + +re: fclean all + +.PHONY: all clean fclean re diff --git a/CPP02/ex02/main.cpp b/CPP02/ex02/main.cpp new file mode 100644 index 0000000..9e57c0a --- /dev/null +++ b/CPP02/ex02/main.cpp @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/20 10:07:23 by narnaud #+# #+# */ +/* Updated: 2022/06/23 09:47:47 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "Fixed.hpp" + +int main(void) +{ + Fixed a; + Fixed const b( Fixed( 5.05f ) * Fixed( 2 ) ); + + std::cout << a << std::endl; + std::cout << ++a << std::endl; + std::cout << a << std::endl; + std::cout << a++ << std::endl; + std::cout << a << std::endl; + std::cout << b << std::endl; + std::cout << Fixed::max( a, b ) << std::endl; + return 0; +} diff --git a/CPP03/ex00/ClapTrap.cpp b/CPP03/ex00/ClapTrap.cpp new file mode 100644 index 0000000..e07c0c5 --- /dev/null +++ b/CPP03/ex00/ClapTrap.cpp @@ -0,0 +1,96 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ClapTrap.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/23 10:53:50 by narnaud #+# #+# */ +/* Updated: 2022/06/23 17:47:34 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ClapTrap.hpp" + +int ClapTrap::amount = 0; +ClapTrap *ClapTrap::registery[128] = {NULL}; + + +ClapTrap::ClapTrap (void) { + + std::cout << "ClapTrap default constructor called " << endl; +} + +ClapTrap::ClapTrap (std::string name, size_t hp, size_t ep, size_t atk) + : _name(name), _health(hp), _energy(ep), _attack(atk) { + if (ClapTrap::amount >= 128) + { + delete ClapTrap::registery[amount % 128]; + cout << "There are too many Traps " << ClapTrap::registery[amount % 128]->getName() << " destroyed\n"; + } + cout << "ClapTrap " << name << " was created" << endl; + _id = ClapTrap::amount % 128; + ClapTrap::registery[ClapTrap::amount % 128] = this; + ClapTrap::amount++; +} + +ClapTrap::ClapTrap (ClapTrap const & src) { + _name = src.getName(); +} + +ClapTrap & ClapTrap::operator= (ClapTrap const & src) { + std::cout << "ClapTrap assignment operator called" << endl; + _name = src.getName(); + return (*this); +} + +ClapTrap::~ClapTrap (void) { + + std::cout << "ClapTrap " << _name << " was destroyed" << endl; +} + +void ClapTrap::attack(const std::string& target) { + if (_energy == 0 || _health == 0) + cout << _name << " is no more able to attack anyone" << endl; + else + { + cout << _name << " attacked " << target << endl; + getClapTrap(target)->takeDamage(_attack); + _energy--; + } +} + +void ClapTrap::takeDamage(unsigned int amount) { + if (_health == 0) + cout << _name << " is already death" << endl; + else + cout << _name << " lose " << amount << " hp" << endl; + if (amount >= _health) + _health = 0; + else + _health -= amount; +} + +void ClapTrap::beRepaired(unsigned int amount) { + if (_energy == 0 || _health == 0) + cout << _name << " is no more able to repair anyone" << endl; + else + { + cout << _name << " was repaired for " << amount << " hp" << endl; + _health += amount; + _energy--; + } +} + +std::string ClapTrap::getName(void) const { + return (_name); +} + +ClapTrap *ClapTrap::getClapTrap(std::string name) { + for (int i = 0; i < 128; i++) + { + if (name == ClapTrap::registery[i]->getName()) + return (ClapTrap::registery[i]); + } + return (NULL); +} diff --git a/CPP03/ex00/ClapTrap.hpp b/CPP03/ex00/ClapTrap.hpp new file mode 100644 index 0000000..a234c0a --- /dev/null +++ b/CPP03/ex00/ClapTrap.hpp @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ClapTrap.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/23 10:54:07 by narnaud #+# #+# */ +/* Updated: 2022/06/23 17:21:48 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once +#define CT_HEALTH 10 +#define CT_ENERGY 10 +#define CT_DMG 1 + +#include +#include +using std::cout; +using std::endl; + +class ClapTrap { + + public: + static ClapTrap *registery[128]; + static int amount; + ClapTrap (void); + ClapTrap (std::string name, size_t hp = CT_HEALTH,\ + size_t ep = CT_ENERGY, size_t atk = CT_DMG); + ClapTrap (ClapTrap const & src); + virtual ~ClapTrap (void); + ClapTrap & operator= (ClapTrap const & src); + virtual void attack(const std::string& target); + void takeDamage(unsigned int amount); + void beRepaired(unsigned int amount); + std::string getName(void) const; + static ClapTrap *getClapTrap(std::string name); + + protected: + std::string _name; + unsigned int _health; + unsigned int _energy; + unsigned int _attack; + unsigned int _id; +}; diff --git a/CPP03/ex00/Makefile b/CPP03/ex00/Makefile new file mode 100644 index 0000000..f61906d --- /dev/null +++ b/CPP03/ex00/Makefile @@ -0,0 +1,20 @@ +NAME = claptrap +SRCS = main.cpp ClapTrap.cpp +OBJS = $(SRCS:.cpp=.o) + +CXXFLAGS = -std=c++98 -Werror -Wextra -Wall + +$(NAME): $(OBJS) + c++ $(OBJS) -o $(NAME) + +all : $(NAME) + +clean : + rm -rf $(OBJS) + +fclean : clean + rm -rf $(NAME) + +re : fclean all + +.PHONY: all clean fclean re diff --git a/CPP03/ex00/main.cpp b/CPP03/ex00/main.cpp new file mode 100644 index 0000000..fa60112 --- /dev/null +++ b/CPP03/ex00/main.cpp @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/23 10:53:16 by narnaud #+# #+# */ +/* Updated: 2022/06/23 12:46:19 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ClapTrap.hpp" + +int main(void) +{ + ClapTrap a("A"); + ClapTrap b("B"); + + a.attack("B"); +} diff --git a/CPP03/ex01/ClapTrap.cpp b/CPP03/ex01/ClapTrap.cpp new file mode 100644 index 0000000..e07c0c5 --- /dev/null +++ b/CPP03/ex01/ClapTrap.cpp @@ -0,0 +1,96 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ClapTrap.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/23 10:53:50 by narnaud #+# #+# */ +/* Updated: 2022/06/23 17:47:34 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ClapTrap.hpp" + +int ClapTrap::amount = 0; +ClapTrap *ClapTrap::registery[128] = {NULL}; + + +ClapTrap::ClapTrap (void) { + + std::cout << "ClapTrap default constructor called " << endl; +} + +ClapTrap::ClapTrap (std::string name, size_t hp, size_t ep, size_t atk) + : _name(name), _health(hp), _energy(ep), _attack(atk) { + if (ClapTrap::amount >= 128) + { + delete ClapTrap::registery[amount % 128]; + cout << "There are too many Traps " << ClapTrap::registery[amount % 128]->getName() << " destroyed\n"; + } + cout << "ClapTrap " << name << " was created" << endl; + _id = ClapTrap::amount % 128; + ClapTrap::registery[ClapTrap::amount % 128] = this; + ClapTrap::amount++; +} + +ClapTrap::ClapTrap (ClapTrap const & src) { + _name = src.getName(); +} + +ClapTrap & ClapTrap::operator= (ClapTrap const & src) { + std::cout << "ClapTrap assignment operator called" << endl; + _name = src.getName(); + return (*this); +} + +ClapTrap::~ClapTrap (void) { + + std::cout << "ClapTrap " << _name << " was destroyed" << endl; +} + +void ClapTrap::attack(const std::string& target) { + if (_energy == 0 || _health == 0) + cout << _name << " is no more able to attack anyone" << endl; + else + { + cout << _name << " attacked " << target << endl; + getClapTrap(target)->takeDamage(_attack); + _energy--; + } +} + +void ClapTrap::takeDamage(unsigned int amount) { + if (_health == 0) + cout << _name << " is already death" << endl; + else + cout << _name << " lose " << amount << " hp" << endl; + if (amount >= _health) + _health = 0; + else + _health -= amount; +} + +void ClapTrap::beRepaired(unsigned int amount) { + if (_energy == 0 || _health == 0) + cout << _name << " is no more able to repair anyone" << endl; + else + { + cout << _name << " was repaired for " << amount << " hp" << endl; + _health += amount; + _energy--; + } +} + +std::string ClapTrap::getName(void) const { + return (_name); +} + +ClapTrap *ClapTrap::getClapTrap(std::string name) { + for (int i = 0; i < 128; i++) + { + if (name == ClapTrap::registery[i]->getName()) + return (ClapTrap::registery[i]); + } + return (NULL); +} diff --git a/CPP03/ex01/ClapTrap.hpp b/CPP03/ex01/ClapTrap.hpp new file mode 100644 index 0000000..a234c0a --- /dev/null +++ b/CPP03/ex01/ClapTrap.hpp @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ClapTrap.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/23 10:54:07 by narnaud #+# #+# */ +/* Updated: 2022/06/23 17:21:48 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once +#define CT_HEALTH 10 +#define CT_ENERGY 10 +#define CT_DMG 1 + +#include +#include +using std::cout; +using std::endl; + +class ClapTrap { + + public: + static ClapTrap *registery[128]; + static int amount; + ClapTrap (void); + ClapTrap (std::string name, size_t hp = CT_HEALTH,\ + size_t ep = CT_ENERGY, size_t atk = CT_DMG); + ClapTrap (ClapTrap const & src); + virtual ~ClapTrap (void); + ClapTrap & operator= (ClapTrap const & src); + virtual void attack(const std::string& target); + void takeDamage(unsigned int amount); + void beRepaired(unsigned int amount); + std::string getName(void) const; + static ClapTrap *getClapTrap(std::string name); + + protected: + std::string _name; + unsigned int _health; + unsigned int _energy; + unsigned int _attack; + unsigned int _id; +}; diff --git a/CPP03/ex01/Makefile b/CPP03/ex01/Makefile new file mode 100644 index 0000000..053b6bd --- /dev/null +++ b/CPP03/ex01/Makefile @@ -0,0 +1,20 @@ +NAME = scavtrap +SRCS = main.cpp ClapTrap.cpp ScavTrap.cpp +OBJS = $(SRCS:.cpp=.o) + +CXXFLAGS = -std=c++98 -Werror -Wextra -Wall + +$(NAME): $(OBJS) + c++ $(OBJS) -o $(NAME) + +all : $(NAME) + +clean : + rm -rf $(OBJS) + +fclean : clean + rm -rf $(NAME) + +re : fclean all + +.PHONY: all clean fclean re diff --git a/CPP03/ex01/ScavTrap.cpp b/CPP03/ex01/ScavTrap.cpp new file mode 100644 index 0000000..26914d0 --- /dev/null +++ b/CPP03/ex01/ScavTrap.cpp @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ScavTrap.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/23 15:19:54 by narnaud #+# #+# */ +/* Updated: 2022/06/23 17:55:34 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ScavTrap.hpp" + +ScavTrap::ScavTrap (std::string name, size_t hp, size_t ep, size_t atk):ClapTrap(name, hp, ep, atk){ + if (ScavTrap::amount >= 128) + { + delete ScavTrap::registery[amount % 128]; + cout << "There are already too many Traps" << endl; + } + cout << "ScavTrap " << name << " was created" << endl; + ScavTrap::registery[ScavTrap::amount % 128] = this; + ScavTrap::amount++; +} + +ScavTrap::~ScavTrap (void) { + cout << "ScavTrap " << _name << " was destroyed" << endl; +} + +void ScavTrap::attack(const std::string& target) { + if (_energy == 0 || _health == 0) + cout << _name << " is no more able to attack" << endl; + else + { + cout << _name << " heavily attacked " << target << endl; + getClapTrap(target)->takeDamage(_attack); + _energy--; + } +} + +void ScavTrap::guardGate(void) { + if (_health == 0) + cout << _name << " is no more able to guard" << endl; + else + cout << _name << " is now in guard gate mode.\n"; +} diff --git a/CPP03/ex01/ScavTrap.hpp b/CPP03/ex01/ScavTrap.hpp new file mode 100644 index 0000000..66e1e9b --- /dev/null +++ b/CPP03/ex01/ScavTrap.hpp @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ScavTrap.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/23 15:17:41 by narnaud #+# #+# */ +/* Updated: 2022/06/23 17:03:22 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once +#include "ClapTrap.hpp" +#define ST_HEALTH 100 +#define ST_ENERGY 50 +#define ST_DMG 20 + +class ScavTrap : public ClapTrap { + + public: + + ScavTrap (std::string name, size_t hp = ST_HEALTH,\ + size_t ep = ST_ENERGY, size_t atk = ST_DMG); + ~ScavTrap (void); + void attack(const std::string& target); + void guardGate(void); +}; diff --git a/CPP03/ex01/claptrap b/CPP03/ex01/claptrap new file mode 100755 index 0000000..4857b0e Binary files /dev/null and b/CPP03/ex01/claptrap differ diff --git a/CPP03/ex01/main.cpp b/CPP03/ex01/main.cpp new file mode 100644 index 0000000..05bca4b --- /dev/null +++ b/CPP03/ex01/main.cpp @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/23 10:53:16 by narnaud #+# #+# */ +/* Updated: 2022/06/23 17:34:04 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ScavTrap.hpp" + +int main(void) +{ + ClapTrap a("A"); + ClapTrap b("B"); + ScavTrap c("C"); + + a.attack("B"); + b.attack("C"); + c.attack("A"); + a.attack("C"); + b.attack("A"); + c.beRepaired(10); + a.beRepaired(5); + b.attack("C"); + c.guardGate(); +} diff --git a/CPP03/ex02/ClapTrap.cpp b/CPP03/ex02/ClapTrap.cpp new file mode 100644 index 0000000..e07c0c5 --- /dev/null +++ b/CPP03/ex02/ClapTrap.cpp @@ -0,0 +1,96 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ClapTrap.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/23 10:53:50 by narnaud #+# #+# */ +/* Updated: 2022/06/23 17:47:34 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ClapTrap.hpp" + +int ClapTrap::amount = 0; +ClapTrap *ClapTrap::registery[128] = {NULL}; + + +ClapTrap::ClapTrap (void) { + + std::cout << "ClapTrap default constructor called " << endl; +} + +ClapTrap::ClapTrap (std::string name, size_t hp, size_t ep, size_t atk) + : _name(name), _health(hp), _energy(ep), _attack(atk) { + if (ClapTrap::amount >= 128) + { + delete ClapTrap::registery[amount % 128]; + cout << "There are too many Traps " << ClapTrap::registery[amount % 128]->getName() << " destroyed\n"; + } + cout << "ClapTrap " << name << " was created" << endl; + _id = ClapTrap::amount % 128; + ClapTrap::registery[ClapTrap::amount % 128] = this; + ClapTrap::amount++; +} + +ClapTrap::ClapTrap (ClapTrap const & src) { + _name = src.getName(); +} + +ClapTrap & ClapTrap::operator= (ClapTrap const & src) { + std::cout << "ClapTrap assignment operator called" << endl; + _name = src.getName(); + return (*this); +} + +ClapTrap::~ClapTrap (void) { + + std::cout << "ClapTrap " << _name << " was destroyed" << endl; +} + +void ClapTrap::attack(const std::string& target) { + if (_energy == 0 || _health == 0) + cout << _name << " is no more able to attack anyone" << endl; + else + { + cout << _name << " attacked " << target << endl; + getClapTrap(target)->takeDamage(_attack); + _energy--; + } +} + +void ClapTrap::takeDamage(unsigned int amount) { + if (_health == 0) + cout << _name << " is already death" << endl; + else + cout << _name << " lose " << amount << " hp" << endl; + if (amount >= _health) + _health = 0; + else + _health -= amount; +} + +void ClapTrap::beRepaired(unsigned int amount) { + if (_energy == 0 || _health == 0) + cout << _name << " is no more able to repair anyone" << endl; + else + { + cout << _name << " was repaired for " << amount << " hp" << endl; + _health += amount; + _energy--; + } +} + +std::string ClapTrap::getName(void) const { + return (_name); +} + +ClapTrap *ClapTrap::getClapTrap(std::string name) { + for (int i = 0; i < 128; i++) + { + if (name == ClapTrap::registery[i]->getName()) + return (ClapTrap::registery[i]); + } + return (NULL); +} diff --git a/CPP03/ex02/ClapTrap.hpp b/CPP03/ex02/ClapTrap.hpp new file mode 100644 index 0000000..a234c0a --- /dev/null +++ b/CPP03/ex02/ClapTrap.hpp @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ClapTrap.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/23 10:54:07 by narnaud #+# #+# */ +/* Updated: 2022/06/23 17:21:48 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once +#define CT_HEALTH 10 +#define CT_ENERGY 10 +#define CT_DMG 1 + +#include +#include +using std::cout; +using std::endl; + +class ClapTrap { + + public: + static ClapTrap *registery[128]; + static int amount; + ClapTrap (void); + ClapTrap (std::string name, size_t hp = CT_HEALTH,\ + size_t ep = CT_ENERGY, size_t atk = CT_DMG); + ClapTrap (ClapTrap const & src); + virtual ~ClapTrap (void); + ClapTrap & operator= (ClapTrap const & src); + virtual void attack(const std::string& target); + void takeDamage(unsigned int amount); + void beRepaired(unsigned int amount); + std::string getName(void) const; + static ClapTrap *getClapTrap(std::string name); + + protected: + std::string _name; + unsigned int _health; + unsigned int _energy; + unsigned int _attack; + unsigned int _id; +}; diff --git a/CPP03/ex02/FragTrap.cpp b/CPP03/ex02/FragTrap.cpp new file mode 100644 index 0000000..6864f32 --- /dev/null +++ b/CPP03/ex02/FragTrap.cpp @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* FragTrap.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/23 15:19:54 by narnaud #+# #+# */ +/* Updated: 2022/06/23 18:04:05 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "FragTrap.hpp" + +FragTrap::FragTrap (std::string name, size_t hp, size_t ep, size_t atk):ClapTrap(name, hp, ep, atk){ + if (FragTrap::amount >= 128) + { + delete FragTrap::registery[amount % 128]; + cout << "There are already too many Traps" << endl; + } + cout << "FragTrap " << name << " was created" << endl; + FragTrap::registery[FragTrap::amount % 128] = this; + FragTrap::amount++; +} + +FragTrap::~FragTrap (void) { + cout << "FragTrap " << _name << " was destroyed" << endl; +} + +void FragTrap::attack(const std::string& target) { + if (_energy == 0 || _health == 0) + cout << _name << " is no more able to attack anyone"; + else + { + cout << _name << " hardly attacked " << target << endl; + getClapTrap(target)->takeDamage(_attack); + _energy--; + } +} diff --git a/CPP03/ex02/FragTrap.hpp b/CPP03/ex02/FragTrap.hpp new file mode 100644 index 0000000..9539778 --- /dev/null +++ b/CPP03/ex02/FragTrap.hpp @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* FragTrap.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/23 15:17:41 by narnaud #+# #+# */ +/* Updated: 2022/06/23 17:59:52 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once +#include "ClapTrap.hpp" +#define FT_HEALTH 100 +#define FT_ENERGY 100 +#define FT_DMG 30 + +class FragTrap : public ClapTrap { + + public: + + FragTrap (std::string name, size_t hp = FT_HEALTH,\ + size_t ep = FT_ENERGY, size_t atk = FT_DMG); + ~FragTrap (void); + void attack(const std::string& target); +}; diff --git a/CPP03/ex02/Makefile b/CPP03/ex02/Makefile new file mode 100644 index 0000000..bd9bae8 --- /dev/null +++ b/CPP03/ex02/Makefile @@ -0,0 +1,20 @@ +NAME = fragtrap +SRCS = main.cpp ClapTrap.cpp ScavTrap.cpp FragTrap.cpp +OBJS = $(SRCS:.cpp=.o) + +CXXFLAGS = -std=c++98 -Werror -Wextra -Wall + +$(NAME): $(OBJS) + c++ $(OBJS) -o $(NAME) + +all : $(NAME) + +clean : + rm -rf $(OBJS) + +fclean : clean + rm -rf $(NAME) + +re : fclean all + +.PHONY: all clean fclean re diff --git a/CPP03/ex02/ScavTrap.cpp b/CPP03/ex02/ScavTrap.cpp new file mode 100644 index 0000000..26914d0 --- /dev/null +++ b/CPP03/ex02/ScavTrap.cpp @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ScavTrap.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/23 15:19:54 by narnaud #+# #+# */ +/* Updated: 2022/06/23 17:55:34 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ScavTrap.hpp" + +ScavTrap::ScavTrap (std::string name, size_t hp, size_t ep, size_t atk):ClapTrap(name, hp, ep, atk){ + if (ScavTrap::amount >= 128) + { + delete ScavTrap::registery[amount % 128]; + cout << "There are already too many Traps" << endl; + } + cout << "ScavTrap " << name << " was created" << endl; + ScavTrap::registery[ScavTrap::amount % 128] = this; + ScavTrap::amount++; +} + +ScavTrap::~ScavTrap (void) { + cout << "ScavTrap " << _name << " was destroyed" << endl; +} + +void ScavTrap::attack(const std::string& target) { + if (_energy == 0 || _health == 0) + cout << _name << " is no more able to attack" << endl; + else + { + cout << _name << " heavily attacked " << target << endl; + getClapTrap(target)->takeDamage(_attack); + _energy--; + } +} + +void ScavTrap::guardGate(void) { + if (_health == 0) + cout << _name << " is no more able to guard" << endl; + else + cout << _name << " is now in guard gate mode.\n"; +} diff --git a/CPP03/ex02/ScavTrap.hpp b/CPP03/ex02/ScavTrap.hpp new file mode 100644 index 0000000..66e1e9b --- /dev/null +++ b/CPP03/ex02/ScavTrap.hpp @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ScavTrap.hpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/23 15:17:41 by narnaud #+# #+# */ +/* Updated: 2022/06/23 17:03:22 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#pragma once +#include "ClapTrap.hpp" +#define ST_HEALTH 100 +#define ST_ENERGY 50 +#define ST_DMG 20 + +class ScavTrap : public ClapTrap { + + public: + + ScavTrap (std::string name, size_t hp = ST_HEALTH,\ + size_t ep = ST_ENERGY, size_t atk = ST_DMG); + ~ScavTrap (void); + void attack(const std::string& target); + void guardGate(void); +}; diff --git a/CPP03/ex02/claptrap b/CPP03/ex02/claptrap new file mode 100755 index 0000000..4857b0e Binary files /dev/null and b/CPP03/ex02/claptrap differ diff --git a/CPP03/ex02/main.cpp b/CPP03/ex02/main.cpp new file mode 100644 index 0000000..0627af7 --- /dev/null +++ b/CPP03/ex02/main.cpp @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.cpp :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: narnaud +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2022/06/23 10:53:16 by narnaud #+# #+# */ +/* Updated: 2022/06/23 17:59:14 by narnaud ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ScavTrap.hpp" +#include "FragTrap.hpp" + +int main(void) +{ + ClapTrap a("A"); + ScavTrap b("B"); + FragTrap c("C"); + + a.attack("B"); + b.attack("C"); + c.attack("B"); +}