aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cpp04/ex00/Peon.cpp39
-rw-r--r--cpp04/ex00/Peon.hpp34
-rw-r--r--cpp04/ex00/Sorcerer.cpp63
-rw-r--r--cpp04/ex00/Sorcerer.hpp41
-rw-r--r--cpp04/ex00/Victim.cpp54
-rw-r--r--cpp04/ex00/Victim.hpp39
-rw-r--r--cpp04/ex00/main.cpp30
-rw-r--r--cpp04/ex01/AWeapon.cpp53
-rw-r--r--cpp04/ex01/AWeapon.hpp38
-rw-r--r--cpp04/ex01/Character.cpp81
-rw-r--r--cpp04/ex01/Character.hpp46
-rw-r--r--cpp04/ex01/Enemy.cpp54
-rw-r--r--cpp04/ex01/Enemy.hpp39
-rw-r--r--cpp04/ex01/PlasmaRifle.cpp37
-rw-r--r--cpp04/ex01/PlasmaRifle.hpp33
-rw-r--r--cpp04/ex01/PowerFist.cpp37
-rw-r--r--cpp04/ex01/PowerFist.hpp32
-rw-r--r--cpp04/ex01/RadScorpion.cpp35
-rw-r--r--cpp04/ex01/RadScorpion.hpp30
-rw-r--r--cpp04/ex01/SuperMutant.cpp40
-rw-r--r--cpp04/ex01/SuperMutant.hpp32
-rw-r--r--cpp04/ex01/main.cpp43
-rw-r--r--cpp04/ex02/AssaultTerminator.cpp55
-rw-r--r--cpp04/ex02/AssaultTerminator.hpp34
-rw-r--r--cpp04/ex02/ISpaceMarine.hpp26
-rw-r--r--cpp04/ex02/ISquad.hpp27
-rw-r--r--cpp04/ex02/Squad.cpp73
-rw-r--r--cpp04/ex02/Squad.hpp38
-rw-r--r--cpp04/ex02/TacticalMarine.cpp55
-rw-r--r--cpp04/ex02/TacticalMarine.hpp34
-rw-r--r--cpp04/ex02/main.cpp37
-rw-r--r--cpp04/ex03/AMateria.cpp52
-rw-r--r--cpp04/ex03/AMateria.hpp40
-rw-r--r--cpp04/ex03/Character.cpp72
-rw-r--r--cpp04/ex03/Character.hpp40
-rw-r--r--cpp04/ex03/Cure.cpp41
-rw-r--r--cpp04/ex03/Cure.hpp32
-rw-r--r--cpp04/ex03/ICharacter.hpp34
-rw-r--r--cpp04/ex03/IMateriaSource.hpp27
-rw-r--r--cpp04/ex03/Ice.cpp42
-rw-r--r--cpp04/ex03/Ice.hpp32
-rw-r--r--cpp04/ex03/MateriaSource.cpp43
-rw-r--r--cpp04/ex03/MateriaSource.hpp35
-rw-r--r--cpp04/ex03/main.cpp40
44 files changed, 1839 insertions, 0 deletions
diff --git a/cpp04/ex00/Peon.cpp b/cpp04/ex00/Peon.cpp
new file mode 100644
index 0000000..df55b4f
--- /dev/null
+++ b/cpp04/ex00/Peon.cpp
@@ -0,0 +1,39 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Peon.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/13 20:53:16 by charles #+# #+# */
+/* Updated: 2020/04/13 21:00:23 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Peon.hpp"
+
+Peon::Peon(std::string name):
+ Victim(name)
+{
+ std::cout << "Zog zog." << std::endl;
+}
+
+void Peon::operator=(Peon const& other)
+{
+ m_name = other.m_name;
+}
+
+Peon::Peon(Peon const& other)
+ : Victim(other)
+{
+}
+
+Peon::~Peon()
+{
+ std::cout << "Bleuark..." << std::endl;
+}
+
+void Peon::getPolymorphed() const
+{
+ std::cout << m_name << " has been turned into a pink pony!" << std::endl;
+}
diff --git a/cpp04/ex00/Peon.hpp b/cpp04/ex00/Peon.hpp
new file mode 100644
index 0000000..2d57a05
--- /dev/null
+++ b/cpp04/ex00/Peon.hpp
@@ -0,0 +1,34 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Peon.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/13 20:50:54 by charles #+# #+# */
+/* Updated: 2020/04/13 20:57:37 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef PEON_HPP
+# define PEON_HPP
+
+# include <string>
+# include <iostream>
+# include "Victim.hpp"
+
+class Peon : public Victim
+{
+public:
+ Peon(std::string name);
+ void operator=(Peon const& other);
+ Peon(Peon const& other);
+ ~Peon();
+
+ virtual void getPolymorphed() const;
+
+private:
+ Peon();
+};
+
+#endif
diff --git a/cpp04/ex00/Sorcerer.cpp b/cpp04/ex00/Sorcerer.cpp
new file mode 100644
index 0000000..c6910ce
--- /dev/null
+++ b/cpp04/ex00/Sorcerer.cpp
@@ -0,0 +1,63 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Sorcerer.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/13 20:29:19 by charles #+# #+# */
+/* Updated: 2020/04/13 20:49:48 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Sorcerer.hpp"
+
+Sorcerer::Sorcerer(std::string name, std::string title):
+ m_name(name),
+ m_title(title)
+{
+ std::cout << name << ", " << title << ", is born!" << std::endl;
+}
+
+void Sorcerer::operator=(Sorcerer const& other)
+{
+ m_name = other.m_name;
+ m_title = other.m_title;
+}
+
+Sorcerer::Sorcerer(Sorcerer const& other)
+{
+ *this = other;
+}
+
+Sorcerer::~Sorcerer()
+{
+ std::cout << m_name << ", " << m_title
+ << ", is dead. Consequences will never be the same!" << std::endl;
+}
+
+std::string const& Sorcerer::getName() const
+{
+ return m_name;
+}
+
+std::string const& Sorcerer::getTitle() const
+{
+ return m_title;
+}
+
+void Sorcerer::polymorph(Victim const& v) const
+{
+ v.getPolymorphed();
+}
+
+Sorcerer::Sorcerer()
+{
+}
+
+std::ostream& operator<<(std::ostream& out, Sorcerer const& s)
+{
+ out << "I am " << s.getName() << ", " << s.getTitle()
+ << ", and I like ponies!" << std::endl;
+ return out;
+}
diff --git a/cpp04/ex00/Sorcerer.hpp b/cpp04/ex00/Sorcerer.hpp
new file mode 100644
index 0000000..ed261ae
--- /dev/null
+++ b/cpp04/ex00/Sorcerer.hpp
@@ -0,0 +1,41 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Sorcerer.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/13 20:27:26 by charles #+# #+# */
+/* Updated: 2020/04/13 20:58:46 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef SORCERER_HPP
+# define SORCERER_HPP
+
+# include <string>
+# include <iostream>
+# include "Victim.hpp"
+
+class Sorcerer
+{
+public:
+ Sorcerer(std::string name, std::string title);
+ void operator=(Sorcerer const& other);
+ Sorcerer(Sorcerer const& other);
+ ~Sorcerer();
+
+ std::string const& getName() const;
+ std::string const& getTitle() const;
+ void polymorph(Victim const& v) const;
+
+private:
+ Sorcerer();
+
+ std::string m_name;
+ std::string m_title;
+};
+
+std::ostream& operator<<(std::ostream& out, Sorcerer const& s);
+
+#endif
diff --git a/cpp04/ex00/Victim.cpp b/cpp04/ex00/Victim.cpp
new file mode 100644
index 0000000..2f2f6ad
--- /dev/null
+++ b/cpp04/ex00/Victim.cpp
@@ -0,0 +1,54 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Victim.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/13 20:42:22 by charles #+# #+# */
+/* Updated: 2020/04/13 20:59:51 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Victim.hpp"
+
+Victim::Victim(std::string name) :
+ m_name(name)
+{
+ std::cout << "Some random victim called " << name << " just appeared!" << std::endl;
+}
+
+void Victim::operator=(Victim const& other)
+{
+ m_name = other.m_name;
+}
+
+Victim::Victim(Victim const& other)
+{
+ *this = other;
+}
+
+Victim::~Victim()
+{
+ std::cout << "Victim " << m_name << " just died for no apparent reason!" << std::endl;
+}
+
+std::string const& Victim::getName() const
+{
+ return m_name;
+}
+
+void Victim::getPolymorphed() const
+{
+ std::cout << m_name << " has been turned into a cute little sheep!" << std::endl;
+}
+
+Victim::Victim()
+{
+}
+
+std::ostream& operator<<(std::ostream& out, Victim const& v)
+{
+ out << "I'm " << v.getName() << " and I like otters!" << std::endl;
+ return out;
+}
diff --git a/cpp04/ex00/Victim.hpp b/cpp04/ex00/Victim.hpp
new file mode 100644
index 0000000..dafd8c6
--- /dev/null
+++ b/cpp04/ex00/Victim.hpp
@@ -0,0 +1,39 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Victim.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/13 20:40:50 by charles #+# #+# */
+/* Updated: 2020/04/13 20:59:08 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef VICTIM_HPP
+# define VICTIM_HPP
+
+# include <string>
+# include <iostream>
+
+class Victim
+{
+public:
+ Victim(std::string name);
+ void operator=(Victim const& other);
+ Victim(Victim const& other);
+ ~Victim();
+
+ std::string const& getName() const;
+ virtual void getPolymorphed() const;
+
+protected:
+ std::string m_name;
+
+private:
+ Victim();
+};
+
+std::ostream& operator<<(std::ostream& out, Victim const& v);
+
+#endif
diff --git a/cpp04/ex00/main.cpp b/cpp04/ex00/main.cpp
new file mode 100644
index 0000000..9c17e99
--- /dev/null
+++ b/cpp04/ex00/main.cpp
@@ -0,0 +1,30 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/13 20:47:34 by charles #+# #+# */
+/* Updated: 2020/04/13 20:57:19 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Sorcerer.hpp"
+#include "Victim.hpp"
+#include "Peon.hpp"
+
+int main()
+{
+ Sorcerer robert("Robert", "the Magnificent");
+
+ Victim jim("Jimmy");
+ Peon joe("Joe");
+
+ std::cout << robert << jim << joe;
+
+ robert.polymorph(jim);
+ robert.polymorph(joe);
+
+ return 0;
+}
diff --git a/cpp04/ex01/AWeapon.cpp b/cpp04/ex01/AWeapon.cpp
new file mode 100644
index 0000000..9c53839
--- /dev/null
+++ b/cpp04/ex01/AWeapon.cpp
@@ -0,0 +1,53 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* AWeapon.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 12:16:04 by charles #+# #+# */
+/* Updated: 2020/04/14 13:18:07 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "AWeapon.hpp"
+
+AWeapon::AWeapon(AWeapon const& other)
+{
+ *this = other;
+}
+
+void AWeapon::operator=(AWeapon const& other)
+{
+ m_name = other.m_name;
+ m_apcost = other.m_apcost;
+ m_damage = other.m_damage;
+}
+
+AWeapon::~AWeapon()
+{
+}
+
+AWeapon::AWeapon(std::string const& name, int apcost, int damage)
+ : m_name(name), m_apcost(apcost), m_damage(damage)
+{
+}
+
+std::string const& AWeapon::getName() const
+{
+ return m_name;
+}
+
+int AWeapon::getAPCost() const
+{
+ return m_apcost;
+}
+
+int AWeapon::getDamage() const
+{
+ return m_damage;
+}
+
+AWeapon::AWeapon()
+{
+}
diff --git a/cpp04/ex01/AWeapon.hpp b/cpp04/ex01/AWeapon.hpp
new file mode 100644
index 0000000..468f966
--- /dev/null
+++ b/cpp04/ex01/AWeapon.hpp
@@ -0,0 +1,38 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* AWeapon.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 11:22:06 by charles #+# #+# */
+/* Updated: 2020/04/14 14:33:07 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef AWEAPON_HPP
+# define AWEAPON_HPP
+
+# include <string>
+
+class AWeapon
+{
+public:
+ AWeapon(AWeapon const& other);
+ void operator=(AWeapon const& other);
+ virtual ~AWeapon();
+
+ AWeapon(std::string const& name, int apcost, int damage);
+ std::string const& getName() const;
+ int getAPCost() const;
+ int getDamage() const;
+ virtual void attack() const = 0;
+
+protected:
+ AWeapon();
+ std::string m_name;
+ int m_apcost;
+ int m_damage;
+};
+
+#endif
diff --git a/cpp04/ex01/Character.cpp b/cpp04/ex01/Character.cpp
new file mode 100644
index 0000000..e06be50
--- /dev/null
+++ b/cpp04/ex01/Character.cpp
@@ -0,0 +1,81 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Character.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 13:44:35 by charles #+# #+# */
+/* Updated: 2020/04/14 14:13:39 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Character.hpp"
+
+Character::Character(Character const& other)
+{
+ *this = other;
+}
+
+void Character::operator=(Character const& other)
+{
+ m_name = other.m_name;
+}
+
+Character::~Character()
+{
+}
+
+Character::Character(std::string const& name) : m_name(name), m_ap(40), m_weapon(NULL)
+{
+}
+
+void Character::recoverAP()
+{
+ m_ap += 10;
+ if (m_ap > 40)
+ m_ap = 40;
+}
+
+void Character::equip(AWeapon *weapon)
+{
+ m_weapon = weapon;
+}
+
+void Character::attack(Enemy *enemy)
+{
+ if (m_weapon == NULL || m_ap < m_weapon->getAPCost())
+ return;
+ std::cout << m_name << " attacks " << enemy->getType() << " with a " << m_weapon->getName() << std::endl;
+ m_weapon->attack();
+ enemy->takeDamage(m_weapon->getDamage());
+ if (enemy->getHP() <= 0)
+ delete enemy;
+ m_ap -= m_weapon->getAPCost();
+}
+
+std::string const& Character::getName() const
+{
+ return m_name;
+}
+
+int Character::getAP() const
+{
+ return m_ap;
+}
+
+AWeapon* Character::getWeapon() const
+{
+ return m_weapon;
+}
+
+std::ostream& operator<<(std::ostream& out, Character const& c)
+{
+ out << c.getName() << " has " << c.getAP();
+ if (c.getWeapon() == NULL)
+ out << " and is unarmed";
+ else
+ out << " and wields a " << c.getWeapon()->getName();
+ out << std::endl;
+ return out;
+}
diff --git a/cpp04/ex01/Character.hpp b/cpp04/ex01/Character.hpp
new file mode 100644
index 0000000..04da9fc
--- /dev/null
+++ b/cpp04/ex01/Character.hpp
@@ -0,0 +1,46 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Character.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 13:42:25 by charles #+# #+# */
+/* Updated: 2020/04/14 14:09:51 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef CHARACTER_HPP
+# define CHARACTER_HPP
+
+# include <iostream>
+# include <string>
+# include "AWeapon.hpp"
+# include "Enemy.hpp"
+
+class Character
+{
+public:
+ Character(Character const& other);
+ void operator=(Character const& other);
+ ~Character();
+
+ Character(std::string const& name);
+ void recoverAP();
+ void equip(AWeapon *weapon);
+ void attack(Enemy *enemy);
+ std::string const& getName() const;
+ int getAP() const;
+ AWeapon* getWeapon() const;
+
+private:
+ Character();
+
+ std::string m_name;
+ int m_ap;
+ AWeapon *m_weapon;
+};
+
+std::ostream& operator<<(std::ostream& out, Character const& c);
+
+#endif
diff --git a/cpp04/ex01/Enemy.cpp b/cpp04/ex01/Enemy.cpp
new file mode 100644
index 0000000..321ca68
--- /dev/null
+++ b/cpp04/ex01/Enemy.cpp
@@ -0,0 +1,54 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Enemy.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 13:23:47 by charles #+# #+# */
+/* Updated: 2020/04/14 14:11:19 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Enemy.hpp"
+
+Enemy::Enemy(Enemy const& other)
+{
+ *this = other;
+}
+
+void Enemy::operator=(Enemy const& other)
+{
+ m_hp = other.m_hp;
+ m_type = other.m_type;
+}
+
+Enemy::~Enemy()
+{
+}
+
+Enemy::Enemy(int hp, std::string const& type)
+ : m_hp(hp), m_type(type)
+{
+}
+
+std::string const& Enemy::getType() const
+{
+ return m_type;
+}
+
+int Enemy::getHP() const
+{
+ return m_hp;
+}
+
+void Enemy::takeDamage(int amount)
+{
+ if (amount < 0)
+ return;
+ m_hp -= amount;
+}
+
+Enemy::Enemy()
+{
+}
diff --git a/cpp04/ex01/Enemy.hpp b/cpp04/ex01/Enemy.hpp
new file mode 100644
index 0000000..582a61c
--- /dev/null
+++ b/cpp04/ex01/Enemy.hpp
@@ -0,0 +1,39 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Enemy.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 13:23:40 by charles #+# #+# */
+/* Updated: 2020/04/14 14:13:07 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef ENEMY_HPP
+# define ENEMY_HPP
+
+# include <string>
+
+class Enemy
+{
+public:
+ Enemy(Enemy const& other);
+ void operator=(Enemy const& other);
+ virtual ~Enemy();
+
+ Enemy(int hp, std::string const& type);
+
+ std::string const& getType() const;
+ int getHP() const;
+
+ virtual void takeDamage(int amount);
+
+protected:
+ Enemy();
+
+ int m_hp;
+ std::string m_type;
+};
+
+#endif
diff --git a/cpp04/ex01/PlasmaRifle.cpp b/cpp04/ex01/PlasmaRifle.cpp
new file mode 100644
index 0000000..6629905
--- /dev/null
+++ b/cpp04/ex01/PlasmaRifle.cpp
@@ -0,0 +1,37 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* PlasmaRifle.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 13:07:24 by charles #+# #+# */
+/* Updated: 2020/04/14 13:18:53 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "PlasmaRifle.hpp"
+
+PlasmaRifle::PlasmaRifle()
+ : AWeapon("Plasma Rifle", 5, 21)
+{
+}
+
+PlasmaRifle::PlasmaRifle(PlasmaRifle const& other)
+{
+ *this = other;
+}
+
+void PlasmaRifle::operator=(PlasmaRifle const& other)
+{
+ AWeapon::operator=(other);
+}
+
+PlasmaRifle::~PlasmaRifle()
+{
+}
+
+void PlasmaRifle::attack() const
+{
+ std::cout << "* piouuu piouuu piouuu *" << std::endl;
+}
diff --git a/cpp04/ex01/PlasmaRifle.hpp b/cpp04/ex01/PlasmaRifle.hpp
new file mode 100644
index 0000000..ef7caab
--- /dev/null
+++ b/cpp04/ex01/PlasmaRifle.hpp
@@ -0,0 +1,33 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* PlasmaRifle.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 12:15:47 by charles #+# #+# */
+/* Updated: 2020/04/14 14:04:39 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef PLASMARIFLE_HPP
+# define PLASMARIFLE_HPP
+
+# include <iostream>
+# include "AWeapon.hpp"
+
+class PlasmaRifle : public AWeapon
+{
+public:
+ PlasmaRifle();
+ PlasmaRifle(PlasmaRifle const& other);
+ void operator=(PlasmaRifle const& other);
+ ~PlasmaRifle();
+
+ virtual void attack() const;
+
+private:
+};
+
+
+#endif
diff --git a/cpp04/ex01/PowerFist.cpp b/cpp04/ex01/PowerFist.cpp
new file mode 100644
index 0000000..d14deba
--- /dev/null
+++ b/cpp04/ex01/PowerFist.cpp
@@ -0,0 +1,37 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* PowerFist.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 13:15:42 by charles #+# #+# */
+/* Updated: 2020/04/14 14:09:51 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "PowerFist.hpp"
+
+PowerFist::PowerFist()
+ : AWeapon("Power Fist", 8, 50)
+{
+}
+
+PowerFist::PowerFist(PowerFist const& other)
+{
+ *this = other;
+}
+
+void PowerFist::operator=(PowerFist const& other)
+{
+ AWeapon::operator=(other);
+}
+
+PowerFist::~PowerFist()
+{
+}
+
+void PowerFist::attack() const
+{
+ std::cout << "* pschhh... SBAM! *" << std::endl;
+}
diff --git a/cpp04/ex01/PowerFist.hpp b/cpp04/ex01/PowerFist.hpp
new file mode 100644
index 0000000..2fbf212
--- /dev/null
+++ b/cpp04/ex01/PowerFist.hpp
@@ -0,0 +1,32 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* PowerFist.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 13:14:42 by charles #+# #+# */
+/* Updated: 2020/04/14 14:04:27 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef POWERFIST_HPP
+# define POWERFIST_HPP
+
+# include <iostream>
+# include "AWeapon.hpp"
+
+class PowerFist : public AWeapon
+{
+public:
+ PowerFist();
+ PowerFist(PowerFist const& other);
+ void operator=(PowerFist const& other);
+ ~PowerFist();
+
+ virtual void attack() const;
+
+private:
+};
+
+#endif
diff --git a/cpp04/ex01/RadScorpion.cpp b/cpp04/ex01/RadScorpion.cpp
new file mode 100644
index 0000000..8422fb7
--- /dev/null
+++ b/cpp04/ex01/RadScorpion.cpp
@@ -0,0 +1,35 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* RadScorpion.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 13:36:11 by charles #+# #+# */
+/* Updated: 2020/04/14 13:37:54 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "RadScorpion.hpp"
+
+RadScorpion::RadScorpion()
+ : Enemy(80, "RadScorpion")
+{
+ std::cout << "* click click click *" << std::endl;
+}
+
+RadScorpion::RadScorpion(RadScorpion const& other)
+{
+ *this = other;
+ std::cout << "* click click click *" << std::endl;
+}
+
+void RadScorpion::operator=(RadScorpion const& other)
+{
+ Enemy::operator=(other);
+}
+
+RadScorpion::~RadScorpion()
+{
+ std::cout << "* SPROTCH *" << std::endl;
+}
diff --git a/cpp04/ex01/RadScorpion.hpp b/cpp04/ex01/RadScorpion.hpp
new file mode 100644
index 0000000..71b98db
--- /dev/null
+++ b/cpp04/ex01/RadScorpion.hpp
@@ -0,0 +1,30 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* RadScorpion.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 13:35:04 by charles #+# #+# */
+/* Updated: 2020/04/14 13:37:58 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef RADSCORPION_HPP
+# define RADSCORPION_HPP
+
+# include <iostream>
+# include "Enemy.hpp"
+
+class RadScorpion : public Enemy
+{
+public:
+ RadScorpion();
+ RadScorpion(RadScorpion const& other);
+ void operator=(RadScorpion const& other);
+ ~RadScorpion();
+
+private:
+};
+
+#endif
diff --git a/cpp04/ex01/SuperMutant.cpp b/cpp04/ex01/SuperMutant.cpp
new file mode 100644
index 0000000..ba0a8a9
--- /dev/null
+++ b/cpp04/ex01/SuperMutant.cpp
@@ -0,0 +1,40 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* SuperMutant.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 13:30:47 by charles #+# #+# */
+/* Updated: 2020/04/14 13:34:32 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "SuperMutant.hpp"
+
+SuperMutant::SuperMutant()
+ : Enemy(170, "Super Mutant")
+{
+ std::cout << "Gaaah. Me want smash heads!" << std::endl;
+}
+
+SuperMutant::SuperMutant(SuperMutant const& other)
+{
+ std::cout << "Gaaah. Me want smash heads!" << std::endl;
+ *this = other;
+}
+
+void SuperMutant::operator=(SuperMutant const& other)
+{
+ Enemy::operator=(other);
+}
+
+SuperMutant::~SuperMutant()
+{
+ std::cout << "Aaargh..." << std::endl;
+}
+
+void SuperMutant::takeDamage(int amount)
+{
+ Enemy::takeDamage(amount - 3);
+}
diff --git a/cpp04/ex01/SuperMutant.hpp b/cpp04/ex01/SuperMutant.hpp
new file mode 100644
index 0000000..1a890cc
--- /dev/null
+++ b/cpp04/ex01/SuperMutant.hpp
@@ -0,0 +1,32 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* SuperMutant.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 13:29:53 by charles #+# #+# */
+/* Updated: 2020/04/14 13:37:56 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef SUPERMUTANT_HPP
+# define SUPERMUTANT_HPP
+
+# include <iostream>
+# include "Enemy.hpp"
+
+class SuperMutant : public Enemy
+{
+public:
+ SuperMutant();
+ SuperMutant(SuperMutant const& other);
+ void operator=(SuperMutant const& other);
+ ~SuperMutant();
+
+ virtual void takeDamage(int amount);
+
+private:
+};
+
+#endif
diff --git a/cpp04/ex01/main.cpp b/cpp04/ex01/main.cpp
new file mode 100644
index 0000000..6798b57
--- /dev/null
+++ b/cpp04/ex01/main.cpp
@@ -0,0 +1,43 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 09:05:58 by charles #+# #+# */
+/* Updated: 2020/04/14 14:09:51 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Character.hpp"
+#include "RadScorpion.hpp"
+#include "PlasmaRifle.hpp"
+#include "PowerFist.hpp"
+
+int main()
+{
+ Character* me = new Character("me");
+
+ std::cout << *me;
+
+ Enemy* b = new RadScorpion();
+
+ AWeapon* pr = new PlasmaRifle();
+ AWeapon* pf = new PowerFist();
+
+ me->equip(pr);
+ std::cout << *me;
+ me->equip(pf);
+
+ me->attack(b);
+ std::cout << *me;
+ me->equip(pr);
+ std::cout << *me;
+ me->attack(b);
+ std::cout << *me;
+ me->attack(b);
+ std::cout << *me;
+
+ return 0;
+}
diff --git a/cpp04/ex02/AssaultTerminator.cpp b/cpp04/ex02/AssaultTerminator.cpp
new file mode 100644
index 0000000..40518da
--- /dev/null
+++ b/cpp04/ex02/AssaultTerminator.cpp
@@ -0,0 +1,55 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* AssaultTerminator.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 15:47:06 by charles #+# #+# */
+/* Updated: 2020/04/14 15:51:46 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "AssaultTerminator.hpp"
+
+AssaultTerminator::AssaultTerminator()
+{
+ std::cout << "* teleports from space *" << std::endl;
+}
+
+AssaultTerminator::AssaultTerminator(AssaultTerminator const& other)
+{
+ *this = other;
+}
+
+void AssaultTerminator::operator=(AssaultTerminator const& other)
+{
+ (void)other;
+}
+
+AssaultTerminator::~AssaultTerminator()
+{
+ std::cout << "I'll be back..." << std::endl;
+}
+
+ISpaceMarine* AssaultTerminator::clone() const
+{
+ ISpaceMarine* cloned = new AssaultTerminator();
+ *cloned = *this;
+ return cloned;
+}
+
+void AssaultTerminator::battleCry() const
+{
+ std::cout << "This code is unclean. PURIFY IT!" << std::endl;
+}
+
+void AssaultTerminator::rangedAttack() const
+{
+ std::cout << "* does nothing *" << std::endl;
+}
+
+void AssaultTerminator::meleeAttack() const
+{
+ std::cout << "* attacks with chainfists *" << std::endl;
+}
diff --git a/cpp04/ex02/AssaultTerminator.hpp b/cpp04/ex02/AssaultTerminator.hpp
new file mode 100644
index 0000000..e2d7acd
--- /dev/null
+++ b/cpp04/ex02/AssaultTerminator.hpp
@@ -0,0 +1,34 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* AssaultTerminator.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 15:46:20 by charles #+# #+# */
+/* Updated: 2020/04/14 15:52:47 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef ASSAULTTERMINATOR_HPP
+# define ASSAULTTERMINATOR_HPP
+
+# include <iostream>
+# include "ISpaceMarine.hpp"
+
+class AssaultTerminator : public ISpaceMarine
+{
+public:
+ AssaultTerminator();
+ AssaultTerminator(AssaultTerminator const& other);
+ void operator=(AssaultTerminator const& other);
+ virtual ~AssaultTerminator();
+
+ virtual ISpaceMarine* clone() const;
+ virtual void battleCry() const;
+ virtual void rangedAttack() const;
+ virtual void meleeAttack() const;
+private:
+};
+
+#endif
diff --git a/cpp04/ex02/ISpaceMarine.hpp b/cpp04/ex02/ISpaceMarine.hpp
new file mode 100644
index 0000000..ebb5583
--- /dev/null
+++ b/cpp04/ex02/ISpaceMarine.hpp
@@ -0,0 +1,26 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ISpaceMarine.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 15:12:33 by charles #+# #+# */
+/* Updated: 2020/04/14 15:28:26 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef ISPACEMARINE_HPP
+# define ISPACEMARINE_HPP
+
+class ISpaceMarine
+{
+public:
+ virtual ~ISpaceMarine() {}
+ virtual ISpaceMarine* clone() const = 0;
+ virtual void battleCry() const = 0;
+ virtual void rangedAttack() const = 0;
+ virtual void meleeAttack() const = 0;
+};
+
+#endif
diff --git a/cpp04/ex02/ISquad.hpp b/cpp04/ex02/ISquad.hpp
new file mode 100644
index 0000000..7e73928
--- /dev/null
+++ b/cpp04/ex02/ISquad.hpp
@@ -0,0 +1,27 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ISquad.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 15:02:01 by charles #+# #+# */
+/* Updated: 2020/04/14 15:27:28 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef ISQUAD_HPP
+# define ISQUAD_HPP
+
+# include "ISpaceMarine.hpp"
+
+class ISquad
+{
+public:
+ virtual ~ISquad() {}
+ virtual int getCount() const = 0;
+ virtual ISpaceMarine* getUnit(int n) const = 0;
+ virtual int push(ISpaceMarine* spaceMarine) = 0;
+};
+
+#endif
diff --git a/cpp04/ex02/Squad.cpp b/cpp04/ex02/Squad.cpp
new file mode 100644
index 0000000..ba825b9
--- /dev/null
+++ b/cpp04/ex02/Squad.cpp
@@ -0,0 +1,73 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Squad.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 15:08:35 by charles #+# #+# */
+/* Updated: 2020/04/14 15:54:17 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Squad.hpp"
+
+Squad::Squad() : m_units(new ISpaceMarine*[0]), m_size(0)
+{
+}
+
+Squad::Squad(Squad const& other)
+{
+ *this = other;
+}
+
+void Squad::operator=(Squad const& other)
+{
+ destroyUnits();
+ m_size = other.m_size;
+ m_units = new ISpaceMarine*[m_size];
+ for (int i = 0; i < m_size; i++)
+ m_units[i] = other.m_units[i]->clone();
+}
+
+Squad::~Squad()
+{
+ destroyUnits();
+}
+
+int Squad::getCount() const
+{
+ return m_size;
+}
+
+ISpaceMarine* Squad::getUnit(int n) const
+{
+ if (n < 0 || n >= m_size)
+ return nullptr;
+ return m_units[n];
+}
+
+int Squad::push(ISpaceMarine* spaceMarine)
+{
+ if (spaceMarine == nullptr)
+ return (-1);
+ for (int i = 0; i < m_size; i++)
+ if (m_units[i] == spaceMarine)
+ return (-1);
+
+ ISpaceMarine** new_units = new ISpaceMarine*[m_size + 1];
+ for (int i = 0; i < m_size; i++)
+ new_units[i] = m_units[i];
+ new_units[m_size] = spaceMarine;
+ delete [] m_units;
+ m_size++;
+ m_units = new_units;
+ return m_size;
+}
+
+void Squad::destroyUnits()
+{
+ for (int i = 0; i < m_size; i++)
+ delete m_units[i];
+ delete [] m_units;
+}
diff --git a/cpp04/ex02/Squad.hpp b/cpp04/ex02/Squad.hpp
new file mode 100644
index 0000000..fda1148
--- /dev/null
+++ b/cpp04/ex02/Squad.hpp
@@ -0,0 +1,38 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Squad.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 15:07:57 by charles #+# #+# */
+/* Updated: 2020/04/14 15:28:02 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef SQUAD_HPP
+# define SQUAD_HPP
+
+# include "ISquad.hpp"
+# include "ISpaceMarine.hpp"
+
+class Squad : public ISquad
+{
+public:
+ Squad();
+ Squad(Squad const& other);
+ void operator=(Squad const& other);
+ virtual ~Squad();
+
+ virtual int getCount() const;
+ virtual ISpaceMarine* getUnit(int n) const;
+ virtual int push(ISpaceMarine* spaceMarine);
+
+private:
+ void destroyUnits();
+
+ ISpaceMarine** m_units;
+ int m_size;
+};
+
+#endif
diff --git a/cpp04/ex02/TacticalMarine.cpp b/cpp04/ex02/TacticalMarine.cpp
new file mode 100644
index 0000000..f2684ba
--- /dev/null
+++ b/cpp04/ex02/TacticalMarine.cpp
@@ -0,0 +1,55 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* TacticalMarine.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 15:31:43 by charles #+# #+# */
+/* Updated: 2020/04/14 15:45:55 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "TacticalMarine.hpp"
+
+TacticalMarine::TacticalMarine()
+{
+ std::cout << "Tactical Marine ready for battle!" << std::endl;
+}
+
+TacticalMarine::TacticalMarine(TacticalMarine const& other)
+{
+ *this = other;
+}
+
+void TacticalMarine::operator=(TacticalMarine const& other)
+{
+ (void)other;
+}
+
+TacticalMarine::~TacticalMarine()
+{
+ std::cout << "Aaargh..." << std::endl;
+}
+
+ISpaceMarine* TacticalMarine::clone() const
+{
+ ISpaceMarine* cloned = new TacticalMarine();
+ *cloned = *this;
+ return cloned;
+}
+
+void TacticalMarine::battleCry() const
+{
+ std::cout << "For the holy PLOT!" << std::endl;
+}
+
+void TacticalMarine::rangedAttack() const
+{
+ std::cout << "* attacks with a botler *" << std::endl;
+}
+
+void TacticalMarine::meleeAttack() const
+{
+ std::cout << "* attacks with a chainsword *" << std::endl;
+}
diff --git a/cpp04/ex02/TacticalMarine.hpp b/cpp04/ex02/TacticalMarine.hpp
new file mode 100644
index 0000000..18dd0c9
--- /dev/null
+++ b/cpp04/ex02/TacticalMarine.hpp
@@ -0,0 +1,34 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* TacticalMarine.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 15:30:48 by charles #+# #+# */
+/* Updated: 2020/04/14 15:34:12 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef TACTICALMARINE_HPP
+# define TACTICALMARINE_HPP
+
+# include <iostream>
+# include "ISpaceMarine.hpp"
+
+class TacticalMarine : public ISpaceMarine
+{
+public:
+ TacticalMarine();
+ TacticalMarine(TacticalMarine const& other);
+ void operator=(TacticalMarine const& other);
+ virtual ~TacticalMarine();
+
+ virtual ISpaceMarine* clone() const;
+ virtual void battleCry() const;
+ virtual void rangedAttack() const;
+ virtual void meleeAttack() const;
+private:
+};
+
+#endif
diff --git a/cpp04/ex02/main.cpp b/cpp04/ex02/main.cpp
new file mode 100644
index 0000000..137ce46
--- /dev/null
+++ b/cpp04/ex02/main.cpp
@@ -0,0 +1,37 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 15:50:35 by charles #+# #+# */
+/* Updated: 2020/04/14 15:53:35 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "ISpaceMarine.hpp"
+#include "ISquad.hpp"
+#include "Squad.hpp"
+#include "TacticalMarine.hpp"
+#include "AssaultTerminator.hpp"
+
+int main()
+{
+ ISpaceMarine* bob = new TacticalMarine;
+ ISpaceMarine* jim = new AssaultTerminator;
+
+ ISquad* vlc = new Squad;
+ vlc->push(bob);
+ vlc->push(jim);
+ for (int i = 0; i < vlc->getCount(); ++i)
+ {
+ ISpaceMarine* cur = vlc->getUnit(i);
+ cur->battleCry();
+ cur->rangedAttack();
+ cur->meleeAttack();
+ }
+ delete vlc;
+
+ return 0;
+}
diff --git a/cpp04/ex03/AMateria.cpp b/cpp04/ex03/AMateria.cpp
new file mode 100644
index 0000000..77e674b
--- /dev/null
+++ b/cpp04/ex03/AMateria.cpp
@@ -0,0 +1,52 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* AMateria.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 16:26:57 by charles #+# #+# */
+/* Updated: 2020/04/14 16:35:09 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "AMateria.hpp"
+
+AMateria::AMateria(AMateria const& other)
+{
+ *this = other;
+ m_type = "";
+}
+
+void AMateria::operator=(AMateria const& other)
+{
+ _xp = other._xp;
+}
+
+AMateria::~AMateria()
+{
+}
+
+AMateria::AMateria(std::string const& type)
+ : m_type(type), _xp(0)
+{
+}
+
+std::string const& AMateria::getType() const
+{
+ return m_type;
+}
+
+unsigned int AMateria::getXP() const
+{
+ return _xp;
+}
+
+void AMateria::use(ICharacter& target)
+{
+ _xp += 10;
+}
+
+AMateria::AMateria()
+{
+}
diff --git a/cpp04/ex03/AMateria.hpp b/cpp04/ex03/AMateria.hpp
new file mode 100644
index 0000000..65d5cc5
--- /dev/null
+++ b/cpp04/ex03/AMateria.hpp
@@ -0,0 +1,40 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* AMateria.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 16:24:00 by charles #+# #+# */
+/* Updated: 2020/04/14 17:55:18 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef AMATERIA_HPP
+# define AMATERIA_HPP
+
+# include <string>
+# include "ICharacter.hpp"
+
+class AMateria
+{
+public:
+ AMateria(AMateria const& other);
+ void operator=(AMateria const& other);
+ virtual ~AMateria();
+
+ AMateria(std::string const& type);
+ std::string const& getType() const;
+ unsigned int getXP() const;
+
+ virtual AMateria* clone() const = 0;
+ virtual void use(ICharacter& target);
+
+protected:
+ AMateria();
+
+ std::string m_type;
+ unsigned int _xp; // subject force _xp instead of m_xp
+};
+
+#endif
diff --git a/cpp04/ex03/Character.cpp b/cpp04/ex03/Character.cpp
new file mode 100644
index 0000000..34aaa48
--- /dev/null
+++ b/cpp04/ex03/Character.cpp
@@ -0,0 +1,72 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Character.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 16:45:54 by charles #+# #+# */
+/* Updated: 2020/04/14 17:59:57 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Character.hpp"
+
+Character::Character() : m_name(""), m_inventory_size(0)
+{
+}
+
+Character::Character(Character const& other)
+{
+ *this = other;
+}
+
+void Character::operator=(Character const& other)
+{
+ for (int i = 0; i < m_inventory_size; i++)
+ delete m_inventory[i];
+ m_inventory_size = other.m_inventory_size;
+ for (int i = 0; i < m_inventory_size; i++)
+ m_inventory[i] = other.m_inventory[i]->clone();
+ m_name = other.m_name;
+}
+
+Character::~Character()
+{
+ for (int i = 0; i < m_inventory_size; i++)
+ delete m_inventory[i];
+}
+
+Character::Character(std::string const& name)
+ : m_name(name), m_inventory_size(0)
+{
+}
+
+std::string const& Character::getName() const
+{
+ return m_name;
+}
+
+void Character::equip(AMateria* m)
+{
+ if (m_inventory_size >= INVENTORY_MAX_SIZE)
+ return;
+ m_inventory[m_inventory_size] = m;
+ m_inventory_size++;
+}
+
+void Character::unequip(int idx)
+{
+ if (idx < 0 || idx >= m_inventory_size)
+ return;
+ for (int i = idx; i < m_inventory_size - 1; i++)
+ m_inventory[i] = m_inventory[i + 1];
+ m_inventory_size--;
+}
+
+void Character::use(int idx, ICharacter& target)
+{
+ if (idx < 0 || idx >= m_inventory_size)
+ return;
+ m_inventory[idx]->use(target);
+}
diff --git a/cpp04/ex03/Character.hpp b/cpp04/ex03/Character.hpp
new file mode 100644
index 0000000..c6ffc7b
--- /dev/null
+++ b/cpp04/ex03/Character.hpp
@@ -0,0 +1,40 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Character.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 16:44:43 by charles #+# #+# */
+/* Updated: 2020/04/14 17:31:49 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef CHARACTER_HPP
+# define CHARACTER_HPP
+
+# include "ICharacter.hpp"
+
+# define INVENTORY_MAX_SIZE 4
+
+class Character : public ICharacter
+{
+public:
+ Character();
+ Character(Character const& other);
+ void operator=(Character const& other);
+ virtual ~Character();
+
+ Character(std::string const& name);
+ virtual std::string const& getName() const;
+ virtual void equip(AMateria* m);
+ virtual void unequip(int idx);
+ virtual void use(int idx, ICharacter& target);
+
+private:
+ AMateria* m_inventory[INVENTORY_MAX_SIZE];
+ int m_inventory_size;
+ std::string m_name;
+};
+
+#endif
diff --git a/cpp04/ex03/Cure.cpp b/cpp04/ex03/Cure.cpp
new file mode 100644
index 0000000..1f3e0d5
--- /dev/null
+++ b/cpp04/ex03/Cure.cpp
@@ -0,0 +1,41 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Cure.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 17:38:01 by charles #+# #+# */
+/* Updated: 2020/04/14 17:41:32 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Cure.hpp"
+
+Cure::Cure() : AMateria("cure")
+{
+}
+
+Cure::Cure(Cure const& other)
+{
+ *this = other;
+}
+
+void Cure::operator=(Cure const& other)
+{
+ AMateria::operator=(other);
+}
+
+Cure::~Cure()
+{
+}
+
+AMateria* Cure::clone() const
+{
+ return new Cure(*this);
+}
+
+void Cure::use(ICharacter& target)
+{
+ std::cout << "* heals " << target.getName() << "'s wounds *" << std::endl;
+}
diff --git a/cpp04/ex03/Cure.hpp b/cpp04/ex03/Cure.hpp
new file mode 100644
index 0000000..4c7a6dd
--- /dev/null
+++ b/cpp04/ex03/Cure.hpp
@@ -0,0 +1,32 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Cure.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 17:37:11 by charles #+# #+# */
+/* Updated: 2020/04/14 17:42:52 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef CURE_HPP
+# define CURE_HPP
+
+# include <iostream>
+# include "AMateria.hpp"
+
+class Cure : public AMateria
+{
+public:
+ Cure();
+ Cure(Cure const& other);
+ void operator=(Cure const& other);
+ ~Cure();
+
+ virtual AMateria* clone() const;
+ virtual void use(ICharacter& target);
+private:
+};
+
+#endif
diff --git a/cpp04/ex03/ICharacter.hpp b/cpp04/ex03/ICharacter.hpp
new file mode 100644
index 0000000..ea56d47
--- /dev/null
+++ b/cpp04/ex03/ICharacter.hpp
@@ -0,0 +1,34 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ICharacter.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 16:40:25 by charles #+# #+# */
+/* Updated: 2020/04/14 17:55:14 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef ICHARACTER_HPP
+# define ICHARACTER_HPP
+
+# include <string>
+# include "AMateria.hpp"
+
+class ICharacter
+{
+public:
+ virtual ~ICharacter() {}
+ virtual std::string const& getName() const = 0;
+ virtual void equip(AMateria* m) = 0;
+ virtual void unequip(int idx) = 0;
+ virtual void use(int idx, ICharacter& target) = 0;
+
+protected:
+ ICharacter();
+ ICharacter(ICharacter const& other);
+ void operator=(ICharacter const& other);
+};
+
+#endif
diff --git a/cpp04/ex03/IMateriaSource.hpp b/cpp04/ex03/IMateriaSource.hpp
new file mode 100644
index 0000000..5161604
--- /dev/null
+++ b/cpp04/ex03/IMateriaSource.hpp
@@ -0,0 +1,27 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* IMateriaSource.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 17:15:52 by charles #+# #+# */
+/* Updated: 2020/04/14 17:21:54 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef IMATERIASOURCE_HPP
+# define IMATERIASOURCE_HPP
+
+# include <string>
+# include "AMateria.hpp"
+
+class IMateriaSource
+{
+public:
+ virtual ~IMateriaSource() {}
+ virtual void learnMateria(AMateria* materia) = 0;
+ virtual AMateria* createMateria(std::string const& type) = 0;
+};
+
+#endif
diff --git a/cpp04/ex03/Ice.cpp b/cpp04/ex03/Ice.cpp
new file mode 100644
index 0000000..976cb84
--- /dev/null
+++ b/cpp04/ex03/Ice.cpp
@@ -0,0 +1,42 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Ice.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 16:32:27 by charles #+# #+# */
+/* Updated: 2020/04/14 17:36:26 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "Ice.hpp"
+
+Ice::Ice() : AMateria("ice")
+{
+}
+
+Ice::Ice(Ice const& other)
+{
+ *this = other;
+}
+
+void Ice::operator=(Ice const& other)
+{
+ AMateria::operator=(other);
+}
+
+Ice::~Ice()
+{
+}
+
+AMateria* Ice::clone() const
+{
+ return new Ice(*this);
+}
+
+void Ice::use(ICharacter& target)
+{
+ std::cout << "* shoots an ice bolt at " << target.getName() << " *" << std::endl;
+ AMateria::use(target);
+}
diff --git a/cpp04/ex03/Ice.hpp b/cpp04/ex03/Ice.hpp
new file mode 100644
index 0000000..55011c0
--- /dev/null
+++ b/cpp04/ex03/Ice.hpp
@@ -0,0 +1,32 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* Ice.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 16:31:34 by charles #+# #+# */
+/* Updated: 2020/04/14 17:38:30 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef ICE_HPP
+# define ICE_HPP
+
+# include <iostream>
+# include "AMateria.hpp"
+
+class Ice : public AMateria
+{
+public:
+ Ice();
+ Ice(Ice const& other);
+ void operator=(Ice const& other);
+ ~Ice();
+
+ virtual AMateria* clone() const;
+ virtual void use(ICharacter& target);
+private:
+};
+
+#endif
diff --git a/cpp04/ex03/MateriaSource.cpp b/cpp04/ex03/MateriaSource.cpp
new file mode 100644
index 0000000..bce6e5a
--- /dev/null
+++ b/cpp04/ex03/MateriaSource.cpp
@@ -0,0 +1,43 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* MateriaSource.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 17:19:10 by charles #+# #+# */
+/* Updated: 2020/04/14 17:51:07 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "MateriaSource.hpp"
+
+MateriaSource::MateriaSource()
+{
+
+}
+
+MateriaSource::MateriaSource(MateriaSource const& other)
+{
+ *this = other;
+}
+
+void MateriaSource::operator=(MateriaSource const& other)
+{
+
+}
+
+MateriaSource::~MateriaSource()
+{
+
+}
+
+void MateriaSource::learnMateria(AMateria* materia)
+{
+
+}
+
+AMateria* MateriaSource::createMateria(std::string const& type)
+{
+ return nullptr;
+}
diff --git a/cpp04/ex03/MateriaSource.hpp b/cpp04/ex03/MateriaSource.hpp
new file mode 100644
index 0000000..a8b4c0e
--- /dev/null
+++ b/cpp04/ex03/MateriaSource.hpp
@@ -0,0 +1,35 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* MateriaSource.hpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 17:17:40 by charles #+# #+# */
+/* Updated: 2020/04/14 17:33:50 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#ifndef MATERIASOURCE_HPP
+# define MATERIASOURCE_HPP
+
+# include "IMateriaSource.hpp"
+
+# define LEARNED_MAX_SIZE 4
+class MateriaSource : public IMateriaSource
+{
+public:
+ MateriaSource();
+ MateriaSource(MateriaSource const& other);
+ void operator=(MateriaSource const& other);
+ virtual ~MateriaSource();
+
+ virtual void learnMateria(AMateria* materia);
+ virtual AMateria* createMateria(std::string const& type);
+
+private:
+ AMateria* m_learned[LEARNED_MAX_SIZE];
+ int m_learned_size;
+};
+
+#endif
diff --git a/cpp04/ex03/main.cpp b/cpp04/ex03/main.cpp
new file mode 100644
index 0000000..11f471f
--- /dev/null
+++ b/cpp04/ex03/main.cpp
@@ -0,0 +1,40 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* main.cpp :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2020/04/14 17:58:01 by charles #+# #+# */
+/* Updated: 2020/04/14 17:59:02 by charles ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+#include "MateriaSource.hpp"
+#include "Ice.hpp"
+#include "Cure.hpp"
+#include "Character.hpp"
+
+int main()
+{
+ IMateriaSource* src = new MateriaSource();
+ src->learnMateria(new Ice());
+ src->learnMateria(new Cure());
+
+ ICharacter* me = new Character("me");
+
+ AMateria* tmp;
+ tmp = src->createMateria("ice");
+ me->equip(tmp);
+ tmp = src->createMateria("cure");
+ me->equip(tmp);
+
+ ICharacter* bob = new Character("bob");
+
+ me->use(0, *bob);
+ me->use(1, *bob);
+
+ delete bob;
+ delete me;
+ delete src;
+}