Compare commits

...

No commits in common. "037daaf8e9cf62698d795ef2202d8fb377a28b2d" and "bc374353a231363f8047d4ca413a632a2772d729" have entirely different histories.

49 changed files with 623 additions and 849 deletions

View File

@ -1,34 +0,0 @@
#include "Animal.hpp"
#include <iostream>
#include <string>
Animal::Animal()
{
std::cout << "Animal()" << std::endl;
}
Animal::Animal(const Animal& src)
{
*this = src;
}
Animal& Animal::operator=(const Animal &src)
{
this->type = src.type;
return *this;
}
Animal::~Animal()
{
std::cout << "~Animal()" << std::endl;
}
void Animal::makeSound() const
{
std::cout << "OuGABounga" << std::endl;
}
std::string Animal::getType() const
{
return this->type;
}

View File

@ -1,19 +0,0 @@
#pragma once
#include <string>
class Animal
{
public:
Animal();
Animal(const Animal& src);
Animal &operator=(const Animal& src);
virtual ~Animal();
std::string getType() const;
virtual void makeSound() const;
protected:
std::string type;
};

View File

@ -1,30 +0,0 @@
#include "Cat.hpp"
#include "Animal.hpp"
#include <iostream>
Cat::Cat()
{
this->type = "Cat";
std::cout << "Cat()" << std::endl;
}
Cat& Cat::operator=(const Cat& src)
{
this->type = src.type;
return *this;
}
Cat::~Cat()
{
std::cout << "~Cat()" << std::endl;
}
Cat::Cat(const Cat& src): Animal()
{
*this = src;
}
void Cat::makeSound() const
{
std::cout << "Meow Meow !" << std::endl;
}

View File

@ -1,16 +0,0 @@
#pragma once
#include <string>
#include "./Animal.hpp"
class Cat : public Animal
{
public:
Cat(const Cat& src);
Cat &operator=(const Cat& src);
Cat();
~Cat();
void makeSound() const;
};

76
ex00/src/ClapTrap.cpp Normal file
View File

@ -0,0 +1,76 @@
#include "ClapTrap.hpp"
#include <iostream>
ClapTrap::ClapTrap():
_name(""),
_life(10),
_energy(10),
_damage(0)
{
std::cout << "ClapTrap()" << std::endl;
}
ClapTrap::ClapTrap(const std::string& name):
_name(name),
_life(10),
_energy(10),
_damage(0)
{
std::cout << "ClapTrap(" << name << ")" << std::endl;
}
ClapTrap::ClapTrap(const ClapTrap& src)
{
std::cout << "ClapTrap(ClapTrap)" << std::endl;
*this = src;
}
ClapTrap::~ClapTrap()
{
std::cout << "~ClapTrap()" << std::endl;
}
ClapTrap& ClapTrap::operator=(const ClapTrap& src)
{
this->_name = src._name;
this->_life = src._life;
this->_energy = src._energy;
this->_damage = src._damage;
return *this;
}
void ClapTrap::beRepaired(unsigned int amount)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl;
return;
}
this->_life += amount;
this->_energy--;
std::cout << "ClapTrap " << this->_name << " beRepaired causing life is now " << this->_life << std::endl;
}
void ClapTrap::takeDamage(unsigned int amount)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl;
return;
}
this->_life -= amount;
std::cout << "ClapTrap " << this->_name << " be attacked causing " << amount << " points of damage!" << std::endl;
}
void ClapTrap::attack(const std::string &target)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl;
return;
}
this->_energy--;
std::cout << "ClapTrap " << this->_name << " attacks " << target << ", causing " << this->_damage << " points of damage!" << std::endl;
}

24
ex00/src/ClapTrap.hpp Normal file
View File

@ -0,0 +1,24 @@
#pragma once
#include <string>
class ClapTrap
{
private:
std::string _name;
int _life;
int _energy;
int _damage;
public:
ClapTrap();
ClapTrap(const ClapTrap& src);
ClapTrap(const std::string& name);
~ClapTrap();
ClapTrap &operator=(const ClapTrap& src);
void attack(const std::string& target);
void takeDamage(unsigned int amount);
void beRepaired(unsigned int amount);
};

View File

@ -1,30 +0,0 @@
#include "Dog.hpp"
#include "Animal.hpp"
#include <iostream>
Dog::Dog()
{
this->type = "Dog";
std::cout << "Dog()" << std::endl;
}
Dog& Dog::operator=(const Dog& src)
{
this->type = src.type;
return *this;
}
Dog::~Dog()
{
std::cout << "~Dog()" << std::endl;
}
Dog::Dog(const Dog& src): Animal()
{
*this = src;
}
void Dog::makeSound() const
{
std::cout << "Ouaf ouaf !" << std::endl;
}

View File

@ -1,16 +0,0 @@
#pragma once
#include <string>
#include "./Animal.hpp"
class Dog : public Animal
{
public:
Dog(const Dog& src);
Dog &operator=(const Dog& src);
Dog();
~Dog();
void makeSound() const;
};

View File

@ -1,34 +0,0 @@
#include "WrongAnimal.hpp"
#include <iostream>
#include <string>
WrongAnimal::WrongAnimal()
{
std::cout << "WrongAnimal()" << std::endl;
}
WrongAnimal::WrongAnimal(const WrongAnimal& src)
{
*this = src;
}
WrongAnimal& WrongAnimal::operator=(const WrongAnimal &src)
{
this->type = src.type;
return *this;
}
WrongAnimal::~WrongAnimal()
{
std::cout << "~WrongAnimal()" << std::endl;
}
void WrongAnimal::makeSound() const
{
std::cout << "OuGABounga" << std::endl;
}
std::string WrongAnimal::getType() const
{
return this->type;
}

View File

@ -1,19 +0,0 @@
#pragma once
#include <string>
class WrongAnimal
{
public:
WrongAnimal();
WrongAnimal(const WrongAnimal& src);
WrongAnimal &operator=(const WrongAnimal& src);
virtual ~WrongAnimal();
std::string getType() const;
void makeSound() const;
protected:
std::string type;
};

View File

@ -1,24 +0,0 @@
#include "WrongCat.hpp"
#include <iostream>
WrongCat::WrongCat()
{
this->type = "WrongCat";
std::cout << "WrongCat()" << std::endl;
}
WrongCat& WrongCat::operator=(const WrongCat& src)
{
this->type = src.type;
return *this;
}
WrongCat::~WrongCat()
{
std::cout << "~WrongCat()" << std::endl;
}
WrongCat::WrongCat(const WrongCat& src): WrongAnimal()
{
*this = src;
}

View File

@ -1,14 +0,0 @@
#pragma once
#include <string>
#include "./WrongAnimal.hpp"
class WrongCat : public WrongAnimal
{
public:
WrongCat(const WrongCat& src);
WrongCat &operator=(const WrongCat& src);
WrongCat();
~WrongCat();
};

View File

@ -1,24 +1,20 @@
#include <iostream>
#include "Cat.hpp"
#include "Dog.hpp"
#include "WrongCat.hpp"
#include "ClapTrap.hpp"
int main()
{
const Animal* meta = new Animal();
const Animal* j = new Dog();
const Animal* i = new Cat();
std::cout << j->getType() << " " << std::endl;
std::cout << i->getType() << " " << std::endl;
i->makeSound(); //will output the cat sound!
j->makeSound();
meta->makeSound();
delete meta;
delete j;
delete i;
const WrongCat* kitten = new WrongCat();
kitten->makeSound();
delete kitten;
ClapTrap claptrap1("Claptrap1");
ClapTrap claptrap2("Claptrap2");
claptrap1.attack("Bandit");
claptrap2.takeDamage(20);
claptrap1.beRepaired(10);
claptrap1.attack("bozoman");
claptrap2.takeDamage(20);
claptrap1.beRepaired(1000);
ClapTrap tmp(claptrap1);
tmp.attack("bozo");
tmp = claptrap2;
tmp.attack("bozo");
return 0;
}

View File

@ -1,34 +0,0 @@
#include "Animal.hpp"
#include <iostream>
#include <string>
Animal::Animal()
{
std::cout << "Animal()" << std::endl;
}
Animal::Animal(const Animal& src)
{
*this = src;
}
Animal& Animal::operator=(const Animal &src)
{
this->type = src.type;
return *this;
}
Animal::~Animal()
{
std::cout << "~Animal()" << std::endl;
}
void Animal::makeSound() const
{
std::cout << "OuGABounga" << std::endl;
}
std::string Animal::getType() const
{
return this->type;
}

View File

@ -1,19 +0,0 @@
#pragma once
#include <string>
class Animal
{
public:
Animal();
Animal(const Animal& src);
Animal &operator=(const Animal& src);
virtual ~Animal();
std::string getType() const;
virtual void makeSound() const;
protected:
std::string type;
};

View File

@ -1,24 +0,0 @@
#include "Brain.hpp"
#include <iostream>
Brain& Brain::operator=(const Brain &src)
{
for (size_t i = 0; i < 100; i++)
this->ideas[i] = src.ideas[i];
return *this;
}
Brain::~Brain()
{
std::cout << "~Brain()" << std::endl;
}
Brain::Brain()
{
std::cout << "Brain()" << std::endl;
}
Brain::Brain(const Brain& src)
{
*this = src;
}

View File

@ -1,14 +0,0 @@
#pragma once
#include <string>
class Brain
{
public:
Brain();
Brain(const Brain& src);
~Brain();
Brain& operator=(const Brain& src);
private:
std::string ideas[100];
};

View File

@ -1,31 +0,0 @@
#include "Cat.hpp"
#include <iostream>
Cat::Cat()
{
this->brain = new Brain();
this->type = "Cat";
std::cout << "Cat()" << std::endl;
}
Cat& Cat::operator=(const Cat& src)
{
this->type = src.type;
return *this;
}
Cat::~Cat()
{
delete this->brain;
std::cout << "~Cat()" << std::endl;
}
Cat::Cat(const Cat& src): Animal()
{
*this = src;
}
void Cat::makeSound() const
{
std::cout << "Meow Meow !" << std::endl;
}

View File

@ -1,20 +0,0 @@
#pragma once
#include <string>
#include "./Animal.hpp"
#include "./Brain.hpp"
class Cat : public Animal
{
public:
Cat(const Cat& src);
Cat &operator=(const Cat& src);
Cat();
~Cat();
void makeSound() const;
private:
Brain* brain;
};

96
ex01/src/ClapTrap.cpp Normal file
View File

@ -0,0 +1,96 @@
#include "ClapTrap.hpp"
#include <iostream>
ClapTrap::ClapTrap():
_name(""),
_life(10),
_energy(10),
_damage(0)
{
std::cout << "ClapTrap()" << std::endl;
}
ClapTrap::ClapTrap(const std::string& name):
_name(name),
_life(10),
_energy(10),
_damage(0)
{
std::cout << "ClapTrap(" << name << ")" << std::endl;
}
ClapTrap::ClapTrap(const ClapTrap& src)
{
std::cout << "ClapTrap(ClapTrap)" << std::endl;
*this = src;
}
ClapTrap::~ClapTrap()
{
std::cout << "~ClapTrap()" << std::endl;
}
ClapTrap& ClapTrap::operator=(const ClapTrap& src)
{
this->_name = src._name;
this->_life = src._life;
this->_energy = src._energy;
this->_damage = src._damage;
return *this;
}
void ClapTrap::beRepaired(unsigned int amount)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl;
return;
}
this->_life += amount;
this->_energy--;
std::cout << "ClapTrap " << this->_name << " beRepaired causing life is now " << this->_life << std::endl;
}
void ClapTrap::takeDamage(unsigned int amount)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl;
return;
}
this->_life -= amount;
std::cout << "ClapTrap " << this->_name << " be attacked causing " << amount << " points of damage!" << std::endl;
}
void ClapTrap::attack(const std::string &target)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl;
return;
}
this->_energy--;
std::cout << "ClapTrap " << this->_name << " attacks " << target << ", causing " << this->_damage << " points of damage!" << std::endl;
}
const std::string& ClapTrap::getName() const
{
return this->_name;
}
int ClapTrap::getLife() const
{
return this->_life;
}
int ClapTrap::getEnergy() const
{
return this->_energy;
}
int ClapTrap::getDamage() const
{
return this->_damage;
}

29
ex01/src/ClapTrap.hpp Normal file
View File

@ -0,0 +1,29 @@
#pragma once
#include <string>
class ClapTrap
{
protected:
std::string _name;
int _life;
int _energy;
int _damage;
public:
ClapTrap();
ClapTrap(const ClapTrap& src);
ClapTrap(const std::string& name);
virtual ~ClapTrap();
ClapTrap &operator=(const ClapTrap& src);
virtual void attack(const std::string& target);
void takeDamage(unsigned int amount);
void beRepaired(unsigned int amount);
const std::string& getName() const;
int getLife() const;
int getEnergy() const;
int getDamage() const;
};

View File

@ -1,32 +0,0 @@
#include "Dog.hpp"
#include <iostream>
Dog::Dog()
{
this->type = "Dog";
this->brain = new Brain();
std::cout << "Dog()" << std::endl;
}
Dog& Dog::operator=(const Dog& src)
{
this->type = src.type;
return *this;
}
Dog::~Dog()
{
delete this->brain;
std::cout << "~Dog()" << std::endl;
}
Dog::Dog(const Dog& src): Animal()
{
*this = src;
}
void Dog::makeSound() const
{
std::cout << "Ouaf ouaf !" << std::endl;
}

View File

@ -1,20 +0,0 @@
#pragma once
#include <string>
#include "./Animal.hpp"
#include "./Brain.hpp"
class Dog : public Animal
{
public:
Dog(const Dog& src);
Dog &operator=(const Dog& src);
Dog();
~Dog();
void makeSound() const;
private:
Brain* brain;
};

60
ex01/src/ScavTrap.cpp Normal file
View File

@ -0,0 +1,60 @@
#include "ScavTrap.hpp"
#include "ClapTrap.hpp"
#include <iostream>
#include <string>
ScavTrap::ScavTrap()
{
this->_name = "";
this->_life = 100;
this->_energy = 50;
this->_damage = 20;
std::cout << "ScavTrap()" << std::endl;
}
ScavTrap::ScavTrap(const std::string& name)
{
this->_name = name;
this->_life = 100;
this->_energy = 50;
this->_damage = 20;
std::cout << "ScavTrap(" << name << ")" << std::endl;
}
ScavTrap::ScavTrap(const ScavTrap& src): ClapTrap(src)
{
*this = src;
std::cout << "ScavTrap(ScavTrap)" << std::endl;
}
ScavTrap::~ScavTrap()
{
std::cout << "~ScavTrap()" << std::endl;
}
ScavTrap& ScavTrap::operator=(const ScavTrap &src)
{
this->_life = src._life;
this->_name = src._name;
this->_energy = src._energy;
this->_damage = src._damage;
return *this;
}
void ScavTrap::guardGate()
{
std::cout << "ScavTrap " << this->_name << " turn in Gate keeper mode" << std::endl;
}
void ScavTrap::attack(const std::string& target)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ScavTrap " << this->_name << " dead" << std::endl;
return;
}
this->_energy--;
std::cout << "ScavTrap " << this->_name << " attacks " << target << ", causing " << this->_damage << " points of damage!" << std::endl;
}

20
ex01/src/ScavTrap.hpp Normal file
View File

@ -0,0 +1,20 @@
#pragma once
#include "ClapTrap.hpp"
#include <string>
class ScavTrap: public ClapTrap
{
public:
ScavTrap();
ScavTrap(const std::string& name);
ScavTrap(const ScavTrap& src);
~ScavTrap();
ScavTrap& operator=(const ScavTrap& src);
void guardGate();
void attack(const std::string& target);
};

View File

@ -1,34 +0,0 @@
#include "WrongAnimal.hpp"
#include <iostream>
#include <string>
WrongAnimal::WrongAnimal()
{
std::cout << "WrongAnimal()" << std::endl;
}
WrongAnimal::WrongAnimal(const WrongAnimal& src)
{
*this = src;
}
WrongAnimal& WrongAnimal::operator=(const WrongAnimal &src)
{
this->type = src.type;
return *this;
}
WrongAnimal::~WrongAnimal()
{
std::cout << "~WrongAnimal()" << std::endl;
}
void WrongAnimal::makeSound() const
{
std::cout << "OuGABounga" << std::endl;
}
std::string WrongAnimal::getType() const
{
return this->type;
}

View File

@ -1,19 +0,0 @@
#pragma once
#include <string>
class WrongAnimal
{
public:
WrongAnimal();
WrongAnimal(const WrongAnimal& src);
WrongAnimal &operator=(const WrongAnimal& src);
virtual ~WrongAnimal();
std::string getType() const;
void makeSound() const;
protected:
std::string type;
};

View File

@ -1,24 +0,0 @@
#include "WrongCat.hpp"
#include <iostream>
WrongCat::WrongCat()
{
this->type = "WrongCat";
std::cout << "WrongCat()" << std::endl;
}
WrongCat& WrongCat::operator=(const WrongCat& src)
{
this->type = src.type;
return *this;
}
WrongCat::~WrongCat()
{
std::cout << "~WrongCat()" << std::endl;
}
WrongCat::WrongCat(const WrongCat& src): WrongAnimal()
{
*this = src;
}

View File

@ -1,14 +0,0 @@
#pragma once
#include <string>
#include "./WrongAnimal.hpp"
class WrongCat : public WrongAnimal
{
public:
WrongCat(const WrongCat& src);
WrongCat &operator=(const WrongCat& src);
WrongCat();
~WrongCat();
};

View File

@ -1,16 +1,22 @@
#include <iostream>
#include "Cat.hpp"
#include "Dog.hpp"
#include "WrongCat.hpp"
#include "ScavTrap.hpp"
int main()
{
const Animal* meta = new Animal();
delete meta;
const Animal* j = new Dog();
delete j;
const Animal* i = new Cat();
delete i;
return 0;
ClapTrap dead;
ScavTrap active ("Warrior");
ScavTrap copy (active);
active = copy;
dead.attack(active.getName());
active.attack(dead.getName());
dead.takeDamage(active.getDamage());
active.attack(dead.getName());
dead.takeDamage(active.getDamage());
active.attack(dead.getName());
dead.takeDamage(active.getDamage());
active.attack(dead.getName());
dead.takeDamage(active.getDamage());
active.attack(dead.getName());
active.takeDamage(3);
dead.beRepaired(42);
active.guardGate();
}

View File

@ -1,34 +0,0 @@
#include "AAnimal.hpp"
#include <iostream>
#include <string>
AAnimal::AAnimal()
{
std::cout << "AAnimal()" << std::endl;
}
AAnimal::AAnimal(const AAnimal& src)
{
*this = src;
}
AAnimal& AAnimal::operator=(const AAnimal &src)
{
this->type = src.type;
return *this;
}
AAnimal::~AAnimal()
{
std::cout << "~AAnimal()" << std::endl;
}
void AAnimal::makeSound() const
{
std::cout << "OuGAABounga" << std::endl;
}
std::string AAnimal::getType() const
{
return this->type;
}

View File

@ -1,19 +0,0 @@
#pragma once
#include <string>
class AAnimal
{
public:
AAnimal();
AAnimal(const AAnimal& src);
AAnimal &operator=(const AAnimal& src);
virtual ~AAnimal();
std::string getType() const;
virtual void makeSound() const;
protected:
std::string type;
};

View File

@ -1,24 +0,0 @@
#include "Brain.hpp"
#include <iostream>
Brain& Brain::operator=(const Brain &src)
{
for (size_t i = 0; i < 100; i++)
this->ideas[i] = src.ideas[i];
return *this;
}
Brain::~Brain()
{
std::cout << "~Brain()" << std::endl;
}
Brain::Brain()
{
std::cout << "Brain()" << std::endl;
}
Brain::Brain(const Brain& src)
{
*this = src;
}

View File

@ -1,14 +0,0 @@
#pragma once
#include <string>
class Brain
{
public:
Brain();
Brain(const Brain& src);
~Brain();
Brain& operator=(const Brain& src);
private:
std::string ideas[100];
};

View File

@ -1,31 +0,0 @@
#include "Cat.hpp"
#include <iostream>
Cat::Cat()
{
this->brain = new Brain();
this->type = "Cat";
std::cout << "Cat()" << std::endl;
}
Cat& Cat::operator=(const Cat& src)
{
this->type = src.type;
return *this;
}
Cat::~Cat()
{
delete this->brain;
std::cout << "~Cat()" << std::endl;
}
Cat::Cat(const Cat& src): AAnimal()
{
*this = src;
}
void Cat::makeSound() const
{
std::cout << "Meow Meow !" << std::endl;
}

View File

@ -1,20 +0,0 @@
#pragma once
#include <string>
#include "./AAnimal.hpp"
#include "./Brain.hpp"
class Cat : public AAnimal
{
public:
Cat(const Cat& src);
Cat &operator=(const Cat& src);
Cat();
~Cat();
void makeSound() const;
private:
Brain* brain;
};

96
ex02/src/ClapTrap.cpp Normal file
View File

@ -0,0 +1,96 @@
#include "ClapTrap.hpp"
#include <iostream>
ClapTrap::ClapTrap():
_name(""),
_life(10),
_energy(10),
_damage(0)
{
std::cout << "ClapTrap()" << std::endl;
}
ClapTrap::ClapTrap(const std::string& name):
_name(name),
_life(10),
_energy(10),
_damage(0)
{
std::cout << "ClapTrap(" << name << ")" << std::endl;
}
ClapTrap::ClapTrap(const ClapTrap& src)
{
std::cout << "ClapTrap(ClapTrap)" << std::endl;
*this = src;
}
ClapTrap::~ClapTrap()
{
std::cout << "~ClapTrap()" << std::endl;
}
ClapTrap& ClapTrap::operator=(const ClapTrap& src)
{
this->_name = src._name;
this->_life = src._life;
this->_energy = src._energy;
this->_damage = src._damage;
return *this;
}
void ClapTrap::beRepaired(unsigned int amount)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl;
return;
}
this->_life += amount;
this->_energy--;
std::cout << "ClapTrap " << this->_name << " beRepaired causing life is now " << this->_life << std::endl;
}
void ClapTrap::takeDamage(unsigned int amount)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl;
return;
}
this->_life -= amount;
std::cout << "ClapTrap " << this->_name << " be attacked causing " << amount << " points of damage!" << std::endl;
}
void ClapTrap::attack(const std::string &target)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ClapTrap " << this->_name << " dead" << std::endl;
return;
}
this->_energy--;
std::cout << "ClapTrap " << this->_name << " attacks " << target << ", causing " << this->_damage << " points of damage!" << std::endl;
}
const std::string& ClapTrap::getName() const
{
return this->_name;
}
int ClapTrap::getLife() const
{
return this->_life;
}
int ClapTrap::getEnergy() const
{
return this->_energy;
}
int ClapTrap::getDamage() const
{
return this->_damage;
}

29
ex02/src/ClapTrap.hpp Normal file
View File

@ -0,0 +1,29 @@
#pragma once
#include <string>
class ClapTrap
{
protected:
std::string _name;
int _life;
int _energy;
int _damage;
public:
ClapTrap();
ClapTrap(const ClapTrap& src);
ClapTrap(const std::string& name);
virtual ~ClapTrap();
ClapTrap &operator=(const ClapTrap& src);
virtual void attack(const std::string& target);
void takeDamage(unsigned int amount);
void beRepaired(unsigned int amount);
const std::string& getName() const;
int getLife() const;
int getEnergy() const;
int getDamage() const;
};

View File

@ -1,32 +0,0 @@
#include "Dog.hpp"
#include <iostream>
Dog::Dog()
{
this->type = "Dog";
this->brain = new Brain();
std::cout << "Dog()" << std::endl;
}
Dog& Dog::operator=(const Dog& src)
{
this->type = src.type;
return *this;
}
Dog::~Dog()
{
delete this->brain;
std::cout << "~Dog()" << std::endl;
}
Dog::Dog(const Dog& src): AAnimal()
{
*this = src;
}
void Dog::makeSound() const
{
std::cout << "Ouaf ouaf !" << std::endl;
}

View File

@ -1,20 +0,0 @@
#pragma once
#include <string>
#include "./AAnimal.hpp"
#include "./Brain.hpp"
class Dog : public AAnimal
{
public:
Dog(const Dog& src);
Dog &operator=(const Dog& src);
Dog();
~Dog();
void makeSound() const;
private:
Brain* brain;
};

46
ex02/src/FragTrap.cpp Normal file
View File

@ -0,0 +1,46 @@
#include "FragTrap.hpp"
#include <iostream>
#include <string>
FragTrap::FragTrap()
{
this->_life = 100;
this->_energy = 100;
this->_damage = 30;
this->_name = "";
std::cout << "FragTrap()" << std::endl;
}
FragTrap::FragTrap(const FragTrap& src): ClapTrap(src)
{
std::cout << "FragTrap(FragTrap)" << std::endl;
}
FragTrap::FragTrap(const std::string& name)
{
this->_life = 100;
this->_energy = 100;
this->_damage = 30;
this->_name = name;
std::cout << "FragTrap(" << name << ")" << std::endl;
}
FragTrap& FragTrap::operator=(const FragTrap &src)
{
this->_name = src._name;
this->_life = src._life;
this->_energy = src._energy;
this->_damage = src._damage;
return *this;
}
FragTrap::~FragTrap()
{
std::cout << "~FragTrap()" << std::endl;
}
void FragTrap::highFivesGuys(void)
{
std::cout << "high fives ?" << std::endl;
}

16
ex02/src/FragTrap.hpp Normal file
View File

@ -0,0 +1,16 @@
#pragma once
#include "ClapTrap.hpp"
class FragTrap: public ClapTrap
{
public:
FragTrap();
FragTrap(const std::string& name);
FragTrap(const FragTrap& src);
~FragTrap();
FragTrap& operator=(const FragTrap& src);
void highFivesGuys(void);
};

60
ex02/src/ScavTrap.cpp Normal file
View File

@ -0,0 +1,60 @@
#include "ScavTrap.hpp"
#include "ClapTrap.hpp"
#include <iostream>
#include <string>
ScavTrap::ScavTrap()
{
this->_name = "";
this->_life = 100;
this->_energy = 50;
this->_damage = 20;
std::cout << "ScavTrap()" << std::endl;
}
ScavTrap::ScavTrap(const std::string& name)
{
this->_name = name;
this->_life = 100;
this->_energy = 50;
this->_damage = 20;
std::cout << "ScavTrap(" << name << ")" << std::endl;
}
ScavTrap::ScavTrap(const ScavTrap& src): ClapTrap(src)
{
*this = src;
std::cout << "ScavTrap(ScavTrap)" << std::endl;
}
ScavTrap::~ScavTrap()
{
std::cout << "~ScavTrap()" << std::endl;
}
ScavTrap& ScavTrap::operator=(const ScavTrap &src)
{
this->_life = src._life;
this->_name = src._name;
this->_energy = src._energy;
this->_damage = src._damage;
return *this;
}
void ScavTrap::guardGate()
{
std::cout << "ScavTrap " << this->_name << " turn in Gate keeper mode" << std::endl;
}
void ScavTrap::attack(const std::string& target)
{
if (this->_life == 0 || this->_energy == 0)
{
std::cout << "error: ScavTrap " << this->_name << " dead" << std::endl;
return;
}
this->_energy--;
std::cout << "ScavTrap " << this->_name << " attacks " << target << ", causing " << this->_damage << " points of damage!" << std::endl;
}

20
ex02/src/ScavTrap.hpp Normal file
View File

@ -0,0 +1,20 @@
#pragma once
#include "ClapTrap.hpp"
#include <string>
class ScavTrap: public ClapTrap
{
public:
ScavTrap();
ScavTrap(const std::string& name);
ScavTrap(const ScavTrap& src);
~ScavTrap();
ScavTrap& operator=(const ScavTrap& src);
void guardGate();
void attack(const std::string& target);
};

View File

@ -1,34 +0,0 @@
#include "WrongAnimal.hpp"
#include <iostream>
#include <string>
WrongAnimal::WrongAnimal()
{
std::cout << "WrongAnimal()" << std::endl;
}
WrongAnimal::WrongAnimal(const WrongAnimal& src)
{
*this = src;
}
WrongAnimal& WrongAnimal::operator=(const WrongAnimal &src)
{
this->type = src.type;
return *this;
}
WrongAnimal::~WrongAnimal()
{
std::cout << "~WrongAnimal()" << std::endl;
}
void WrongAnimal::makeSound() const
{
std::cout << "OuGABounga" << std::endl;
}
std::string WrongAnimal::getType() const
{
return this->type;
}

View File

@ -1,19 +0,0 @@
#pragma once
#include <string>
class WrongAnimal
{
public:
WrongAnimal();
WrongAnimal(const WrongAnimal& src);
WrongAnimal &operator=(const WrongAnimal& src);
virtual ~WrongAnimal();
std::string getType() const;
void makeSound() const;
protected:
std::string type;
};

View File

@ -1,24 +0,0 @@
#include "WrongCat.hpp"
#include <iostream>
WrongCat::WrongCat()
{
this->type = "WrongCat";
std::cout << "WrongCat()" << std::endl;
}
WrongCat& WrongCat::operator=(const WrongCat& src)
{
this->type = src.type;
return *this;
}
WrongCat::~WrongCat()
{
std::cout << "~WrongCat()" << std::endl;
}
WrongCat::WrongCat(const WrongCat& src): WrongAnimal()
{
*this = src;
}

View File

@ -1,14 +0,0 @@
#pragma once
#include <string>
#include "./WrongAnimal.hpp"
class WrongCat : public WrongAnimal
{
public:
WrongCat(const WrongCat& src);
WrongCat &operator=(const WrongCat& src);
WrongCat();
~WrongCat();
};

View File

@ -1,16 +1,22 @@
#include <iostream>
#include "AAnimal.hpp"
#include "Cat.hpp"
#include "Dog.hpp"
#include "WrongCat.hpp"
#include "FragTrap.hpp"
int main()
{
const AAnimal* j = new Dog();
delete j;
const AAnimal* i = new Cat();
delete i;
// const AAnimal* meta = new AAnimal();
return 0;
ClapTrap dead;
FragTrap active ("Warrior");
FragTrap copy (active);
active = copy;
dead.attack(active.getName());
active.attack(dead.getName());
dead.takeDamage(active.getDamage());
active.attack(dead.getName());
dead.takeDamage(active.getDamage());
active.attack(dead.getName());
dead.takeDamage(active.getDamage());
active.attack(dead.getName());
dead.takeDamage(active.getDamage());
active.attack(dead.getName());
active.takeDamage(3);
copy.highFivesGuys();
dead.beRepaired(42);
}