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()
+{
+}