aboutsummaryrefslogtreecommitdiff
path: root/cpp04/ex01
diff options
context:
space:
mode:
Diffstat (limited to 'cpp04/ex01')
-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
15 files changed, 630 insertions, 0 deletions
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;
+}