diff --git a/cpp03/ex01/ScavTrap.cpp b/cpp03/ex01/ScavTrap.cpp index 14ecd78..05bcde7 100644 --- a/cpp03/ex01/ScavTrap.cpp +++ b/cpp03/ex01/ScavTrap.cpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/13 08:03:51 by apommier #+# #+# */ -/* Updated: 2022/07/14 01:17:00 by apommier ### ########.fr */ +/* Updated: 2022/08/03 14:27:09 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,6 +34,19 @@ ScavTrap::~ScavTrap() std::cout << "ScavTrap " << this->_name << " Destructor called" << std::endl; } +void ScavTrap::attack(const std::string& target) +{ + if (this->_hitPoints <= 0) + std::cout << "ScavTrap " << this->_name << " could not attack because he died" << std::endl; + else if (this->_energyPoints <= 0) + std::cout << "ScavTrap " << this->_name << " could not attack because he don't have energy" << std::endl; + else + { + std::cout << "ScavTrap " << this->_name << " attacks " << target << ", causing " << this->_attackDamage << " points of damage!" << std::endl; + this->_energyPoints--; + } +} + ScavTrap &ScavTrap::operator=(const ScavTrap& rhs) { std::cout << "ScavTrap " << this->_name << " Assignation operator called" << std::endl; @@ -46,5 +59,8 @@ ScavTrap &ScavTrap::operator=(const ScavTrap& rhs) void ScavTrap::guardGate() { - std::cout << "ScavTrap " << this->_name << " came into Gatekeeper mode\n"; + if (this->_hitPoints <= 0) + std::cout << "ScavTrap " << this->_name << " could not guard because he died" << std::endl; + else + std::cout << "ScavTrap " << this->_name << " came into Gatekeeper mode\n"; } \ No newline at end of file diff --git a/cpp03/ex01/ScavTrap.hpp b/cpp03/ex01/ScavTrap.hpp index a7cadd8..0ed3ea3 100644 --- a/cpp03/ex01/ScavTrap.hpp +++ b/cpp03/ex01/ScavTrap.hpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/13 08:03:53 by apommier #+# #+# */ -/* Updated: 2022/07/13 10:18:35 by apommier ### ########.fr */ +/* Updated: 2022/08/03 14:23:58 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,8 +23,10 @@ class ScavTrap : public ClapTrap ScavTrap(std::string name); ScavTrap(const ScavTrap& copy); ~ScavTrap(); + ScavTrap &operator=(const ScavTrap& rhs); + void attack(const std::string& target); void guardGate(); private: diff --git a/cpp03/ex02/FragTrap.cpp b/cpp03/ex02/FragTrap.cpp index ddabe89..87c60e5 100644 --- a/cpp03/ex02/FragTrap.cpp +++ b/cpp03/ex02/FragTrap.cpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/14 01:24:31 by apommier #+# #+# */ -/* Updated: 2022/07/14 01:55:06 by apommier ### ########.fr */ +/* Updated: 2022/08/03 15:27:21 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,6 +34,19 @@ FragTrap::~FragTrap() std::cout << "FragTrap " << this->_name << " Destructor called" << std::endl; } +void FragTrap::attack(const std::string& target) +{ + if (this->_hitPoints <= 0) + std::cout << "FragTrap " << this->_name << " could not attack because he died" << std::endl; + else if (this->_energyPoints <= 0) + std::cout << "FragTrap " << this->_name << " could not attack because he don't have energy" << std::endl; + else + { + std::cout << "FragTrap " << this->_name << " attacks " << target << ", causing " << this->_attackDamage << " points of damage!" << std::endl; + this->_energyPoints--; + } +} + FragTrap &FragTrap::operator=(const FragTrap& rhs) { std::cout << "FragTrap " << this->_name << " Assignation operator called" << std::endl; @@ -46,5 +59,8 @@ FragTrap &FragTrap::operator=(const FragTrap& rhs) void FragTrap::highFivesGuys(void) { - std::cout << "FragTrap " << this->_name << " ask you for a highfive\n"; + if (this->_hitPoints <= 0) + std::cout << "FragTrap " << this->_name << " could not ask you for a highfive because he died" << std::endl; + else + std::cout << "FragTrap " << this->_name << " ask you for a highfive\n"; } \ No newline at end of file diff --git a/cpp03/ex02/FragTrap.hpp b/cpp03/ex02/FragTrap.hpp index dae4b9f..b1c4b09 100644 --- a/cpp03/ex02/FragTrap.hpp +++ b/cpp03/ex02/FragTrap.hpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/14 01:24:34 by apommier #+# #+# */ -/* Updated: 2022/07/14 01:54:11 by apommier ### ########.fr */ +/* Updated: 2022/08/03 14:23:47 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,8 +23,10 @@ class FragTrap : public ClapTrap FragTrap(std::string name); FragTrap(const FragTrap& copy); ~FragTrap(); + FragTrap &operator=(const FragTrap& rhs); + void attack(const std::string& target); void highFivesGuys(void); private: diff --git a/cpp03/ex02/ScavTrap.cpp b/cpp03/ex02/ScavTrap.cpp index f6705da..cb4a757 100644 --- a/cpp03/ex02/ScavTrap.cpp +++ b/cpp03/ex02/ScavTrap.cpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/13 08:03:51 by apommier #+# #+# */ -/* Updated: 2022/07/14 01:23:29 by apommier ### ########.fr */ +/* Updated: 2022/08/03 14:27:02 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,6 +34,19 @@ ScavTrap::~ScavTrap() std::cout << "ScavTrap " << this->_name << " Destructor called" << std::endl; } +void ScavTrap::attack(const std::string& target) +{ + if (this->_hitPoints <= 0) + std::cout << "ScavTrap " << this->_name << " could not attack because he died" << std::endl; + else if (this->_energyPoints <= 0) + std::cout << "ScavTrap " << this->_name << " could not attack because he don't have energy" << std::endl; + else + { + std::cout << "ScavTrap " << this->_name << " attacks " << target << ", causing " << this->_attackDamage << " points of damage!" << std::endl; + this->_energyPoints--; + } +} + ScavTrap &ScavTrap::operator=(const ScavTrap& rhs) { std::cout << "ScavTrap " << this->_name << " Assignation operator called" << std::endl; @@ -46,5 +59,8 @@ ScavTrap &ScavTrap::operator=(const ScavTrap& rhs) void ScavTrap::guardGate() { - std::cout << "ScavTrap " << this->_name << " came into Gatekeeper mode\n"; + if (this->_hitPoints <= 0) + std::cout << "ScavTrap " << this->_name << " could not guard because he died" << std::endl; + else + std::cout << "ScavTrap " << this->_name << " came into Gatekeeper mode\n"; } \ No newline at end of file diff --git a/cpp03/ex02/ScavTrap.hpp b/cpp03/ex02/ScavTrap.hpp index a7cadd8..510adf8 100644 --- a/cpp03/ex02/ScavTrap.hpp +++ b/cpp03/ex02/ScavTrap.hpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/13 08:03:53 by apommier #+# #+# */ -/* Updated: 2022/07/13 10:18:35 by apommier ### ########.fr */ +/* Updated: 2022/08/03 14:23:43 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -23,8 +23,10 @@ class ScavTrap : public ClapTrap ScavTrap(std::string name); ScavTrap(const ScavTrap& copy); ~ScavTrap(); + ScavTrap &operator=(const ScavTrap& rhs); + void attack(const std::string& target); void guardGate(); private: diff --git a/cpp03/ex02/main.cpp b/cpp03/ex02/main.cpp index 6c0b834..0ba8e4b 100644 --- a/cpp03/ex02/main.cpp +++ b/cpp03/ex02/main.cpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/13 05:22:55 by apommier #+# #+# */ -/* Updated: 2022/08/01 22:12:59 by apommier ### ########.fr */ +/* Updated: 2022/08/03 14:21:28 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -50,6 +50,7 @@ int main() std::cout << std::endl << "ScavTrap turn\n"; ScavTrap ScavJohn("CL4P-TP"); + std::cout << std::endl; ScavJohn.guardGate(); ScavJohn.attack("Jean"); @@ -62,52 +63,17 @@ int main() std::cout << std::endl << "FragTrap turn\n"; FragTrap FragJohn("Assassin"); + std::cout << std::endl; FragJohn.highFivesGuys(); FragJohn.attack("Jean"); FragJohn.takeDamage(5); FragJohn.takeDamage(4); FragJohn.takeDamage(1); - FragJohn.takeDamage(1); + FragJohn.takeDamage(300); FragJohn.attack("Jean"); std::cout <<"ScavTrap have " << FragJohn.getEnergyPoints() << " energy point(s)\n\n"; std::cout << std::endl; return (0); } - -// int main() -// { -// ClapTrap John("John"); - -// John.attack("Jean"); -// John.takeDamage(5); -// John.takeDamage(4); -// John.takeDamage(1); -// John.takeDamage(1); -// John.attack("Jean"); - -// std::cout << std::endl; -// ScavTrap ScavJohn("CL4P-TP"); - -// ScavJohn.guardGate(); -// ScavJohn.attack("Jean"); -// ScavJohn.takeDamage(5); -// ScavJohn.takeDamage(4); -// ScavJohn.takeDamage(1); -// ScavJohn.takeDamage(1); -// ScavJohn.attack("Jean"); - -// std::cout << std::endl; -// FragTrap FragJohn("Assassin"); - -// FragJohn.highFivesGuys(); -// FragJohn.attack("Jean"); -// FragJohn.takeDamage(5); -// FragJohn.takeDamage(4); -// FragJohn.takeDamage(1); -// FragJohn.takeDamage(1); -// FragJohn.attack("Jean"); - -// return (0); -// } \ No newline at end of file diff --git a/cpp04/ex00/main.cpp b/cpp04/ex00/main.cpp index 33a9f44..0e20734 100644 --- a/cpp04/ex00/main.cpp +++ b/cpp04/ex00/main.cpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/14 02:04:10 by apommier #+# #+# */ -/* Updated: 2022/07/17 11:29:39 by apommier ### ########.fr */ +/* Updated: 2022/08/03 13:26:10 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,8 +24,8 @@ int main() std::cout << j->getType() << " " << std::endl; std::cout << i->getType() << " " << std::endl; i->makeSound(); //will output the cat sound! - j->makeSound(); - meta->makeSound(); + j->makeSound(); //will output the dog sound! + meta->makeSound();//will output the animal sound! delete meta; delete j; @@ -34,13 +34,16 @@ int main() std::cout << std::endl; const WrongAnimal* meta2 = new WrongAnimal(); - const WrongAnimal* i2 = new WrongCat(); - std::cout << i2->getType() << " " << std::endl; - i2->makeSound(); //will output the WrongAnimal sound! + const WrongAnimal* falseWrongCat = new WrongCat(); + const WrongCat* realWrongCat = new WrongCat(); + std::cout << falseWrongCat->getType() << " " << std::endl; + falseWrongCat->makeSound(); //will output the WrongAnimal sound! meta2->makeSound(); //same + realWrongCat->makeSound();//will output the WrongCat sound! + delete realWrongCat; delete meta2; - delete i2; + delete falseWrongCat; return 0; } \ No newline at end of file diff --git a/cpp04/ex01/Animal.cpp b/cpp04/ex01/Animal.cpp index fc947b4..504c02c 100644 --- a/cpp04/ex01/Animal.cpp +++ b/cpp04/ex01/Animal.cpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/14 02:05:22 by apommier #+# #+# */ -/* Updated: 2022/07/17 18:36:09 by apommier ### ########.fr */ +/* Updated: 2022/08/03 13:21:28 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -21,7 +21,7 @@ Animal::Animal() Animal::Animal(const Animal& copy) { std::cout << "Animal Copy constructor called" << std::endl; - this->type = copy.getType(); + *this = copy; } Animal::~Animal() diff --git a/cpp04/ex01/Cat.cpp b/cpp04/ex01/Cat.cpp index 894bfb0..d689c10 100644 --- a/cpp04/ex01/Cat.cpp +++ b/cpp04/ex01/Cat.cpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/14 02:11:37 by apommier #+# #+# */ -/* Updated: 2022/07/17 19:03:24 by apommier ### ########.fr */ +/* Updated: 2022/08/03 13:20:30 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,8 +22,7 @@ Cat::Cat() : Animal() Cat::Cat(const Cat& copy) : Animal(copy) { std::cout << "Cat Copy constructor called" << std::endl; - this->type = copy.getType(); - //this->_Brain = copy.getType(); + *this = copy; } Cat::~Cat() diff --git a/cpp04/ex01/Dog.cpp b/cpp04/ex01/Dog.cpp index a0ec1d2..1ab349d 100644 --- a/cpp04/ex01/Dog.cpp +++ b/cpp04/ex01/Dog.cpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/14 02:11:41 by apommier #+# #+# */ -/* Updated: 2022/07/17 19:03:52 by apommier ### ########.fr */ +/* Updated: 2022/08/03 13:20:17 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ Dog::Dog() : Animal() Dog::Dog(const Dog& copy) : Animal(copy) { std::cout << "Dog Copy constructor called" << std::endl; - this->type = copy.getType(); + *this = copy; } Dog::~Dog() diff --git a/cpp04/ex01/main.cpp b/cpp04/ex01/main.cpp index d428e4b..591256a 100644 --- a/cpp04/ex01/main.cpp +++ b/cpp04/ex01/main.cpp @@ -6,7 +6,7 @@ /* By: apommier +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2022/07/14 02:04:10 by apommier #+# #+# */ -/* Updated: 2022/07/18 10:28:22 by apommier ### ########.fr */ +/* Updated: 2022/08/03 13:44:10 by apommier ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,64 +16,75 @@ #include "WrongAnimal.hpp" #include "WrongCat.hpp" -/*int main() +void copyTest() +{ + std::cout << std::endl; + Dog first; + Dog cpy = first; + std::cout << std::endl; +} + +int main() { Animal *Animals[10]; - Brain *OneBrain; + Brain *oneBrain; for (int i = 0; i < 10; i++) { if (i < 5) { Animals[i] = new Cat; - Animals[i]->getBrain()->setgetIdeas(0) "Sleep"); - Animals[i]->getBrain()->setgetIdeas(1) "Hate"); - Animals[i]->getBrain()->setgetIdeas(2) "Sleep"); + oneBrain = Animals[i]->getBrain(); + oneBrain->setIdeas(0, "Sleep"); + oneBrain->setIdeas(1, "Hate"); + oneBrain->setIdeas(2, "Sleep"); } else { Animals[i] = new Dog; - Animals[i]->getBrain()->setgetIdeas(0) "Sleep"); - Animals[i]->getBrain()->setgetIdeas(1) "Play"); - Animals[i]->getBrain()->setgetIdeas(2) "Ate"); + oneBrain = Animals[i]->getBrain(); + oneBrain->setIdeas(0, "Sleep"); + oneBrain->setIdeas(1, "Play"); + oneBrain->setIdeas(2, "Ate"); } std::cout << Animals[i]->getType() << std::endl; } for (int i = 0; i < 10; i++) { - std::cout << Animals[i]->getBrain() << std::endl; + std::cout << i + 1 << "- "<< Animals[i]->getBrain() << std::endl; } + //copyTest(); for (int i = 0; i < 10; i++) delete Animals[i]; -}*/ +} -int main( void ) -{ - Animal *animals[10]; - Brain *brain; +// int main( void ) +// { +// Animal *animals[10]; +// Brain *brain; - for (int i = 0; i < 10; i++) - { - if (i < 5) - animals[i] = new Dog(); - else - animals[i] = new Cat(); - std::cout << animals[i]->getType() << std::endl; - } +// for (int i = 0; i < 10; i++) +// { +// if (i < 5) +// animals[i] = new Cat(); +// else +// animals[i] = new Dog(); +// std::cout << animals[i]->getType() << std::endl; +// } - brain = animals[7]->getBrain(); - brain->setIdeas(0, "I'm hungry"); - brain->setIdeas(1, "That's a strange idea I'm having"); - brain->setIdeas(2, "Ball!!!!!"); - brain->setIdeas(3, "Squirrel!!!!!"); - std::cout << std::endl << animals[7]->getBrain()->getIdeas()[0] << std::endl; - std::cout << animals[7]->getBrain()->getIdeas()[2] << std::endl; +// brain = animals[7]->getBrain(); +// brain->setIdeas(0, "I'm hungry"); +// brain->setIdeas(1, "That's a strange idea I'm having"); +// brain->setIdeas(2, "Ball!!!!!"); +// brain->setIdeas(3, "Squirrel!!!!!"); +// std::cout << std::endl << animals[7]->getBrain()->getIdeas()[0] << std::endl; +// std::cout << animals[7]->getBrain()->getIdeas()[2] << std::endl; - *(animals[5]) = *(animals[7]); - std::cout << animals[5]->getBrain()->getIdeas()[2] << std::endl; - std::cout << "Test of copy\n"; - animals[7]->getBrain()->setIdeas(2, "Squirrel!!!!!"); - std::cout << animals[5]->getBrain()->getIdeas()[2] << std::endl << std::endl; - for (int i = 0; i < 10; i++) - delete animals[i]; -} \ No newline at end of file +// *(animals[5]) = *(animals[7]); +// std::cout << animals[5]->getBrain()->getIdeas()[2] << std::endl; +// std::cout << "Test of copy\n"; +// animals[7]->getBrain()->setIdeas(2, "Squirrel!!!!!"); +// std::cout << animals[5]->getBrain()->getIdeas()[2] << std::endl << std::endl; +// for (int i = 0; i < 10; i++) +// delete animals[i]; +// } \ No newline at end of file