diff options
Diffstat (limited to 'cpp04')
| -rw-r--r-- | cpp04/ex01/Character.cpp | 6 | ||||
| -rw-r--r-- | cpp04/ex01/Character.hpp | 2 | ||||
| -rw-r--r-- | cpp04/ex01/RadScorpion.hpp | 4 | ||||
| -rw-r--r-- | cpp04/ex01/SuperMutant.cpp | 4 | ||||
| -rw-r--r-- | cpp04/ex01/SuperMutant.hpp | 4 | ||||
| -rw-r--r-- | cpp04/ex01/main.cpp | 178 | ||||
| -rw-r--r-- | cpp04/ex02/AssaultTerminator.cpp | 11 | ||||
| -rw-r--r-- | cpp04/ex02/AssaultTerminator.hpp | 10 | ||||
| -rw-r--r-- | cpp04/ex02/Squad.cpp | 8 | ||||
| -rw-r--r-- | cpp04/ex02/Squad.hpp | 10 | ||||
| -rw-r--r-- | cpp04/ex02/TacticalMarine.cpp | 11 | ||||
| -rw-r--r-- | cpp04/ex02/TacticalMarine.hpp | 10 | ||||
| -rw-r--r-- | cpp04/ex02/main.cpp | 116 | ||||
| -rw-r--r-- | cpp04/ex03/AMateria.cpp | 20 | ||||
| -rw-r--r-- | cpp04/ex03/AMateria.hpp | 11 | ||||
| -rw-r--r-- | cpp04/ex03/Character.cpp | 24 | ||||
| -rw-r--r-- | cpp04/ex03/Character.hpp | 8 | ||||
| -rw-r--r-- | cpp04/ex03/Cure.cpp | 3 | ||||
| -rw-r--r-- | cpp04/ex03/Cure.hpp | 4 | ||||
| -rw-r--r-- | cpp04/ex03/ICharacter.hpp | 9 | ||||
| -rw-r--r-- | cpp04/ex03/IMateriaSource.hpp | 2 | ||||
| -rw-r--r-- | cpp04/ex03/Ice.cpp | 4 | ||||
| -rw-r--r-- | cpp04/ex03/Ice.hpp | 4 | ||||
| -rw-r--r-- | cpp04/ex03/MateriaSource.cpp | 28 | ||||
| -rw-r--r-- | cpp04/ex03/MateriaSource.hpp | 8 | ||||
| -rw-r--r-- | cpp04/ex03/main.cpp | 2 |
26 files changed, 400 insertions, 101 deletions
diff --git a/cpp04/ex01/Character.cpp b/cpp04/ex01/Character.cpp index 5f865c7..0952738 100644 --- a/cpp04/ex01/Character.cpp +++ b/cpp04/ex01/Character.cpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 13:44:35 by charles #+# #+# */ -/* Updated: 2020/11/12 14:28:26 by cacharle ### ########.fr */ +/* Updated: 2020/11/13 11:51:31 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -41,7 +41,7 @@ void Character::equip(AWeapon *weapon) void Character::attack(Enemy *enemy) { - if (m_weapon == NULL || m_ap < m_weapon->getAPCost()) + if (enemy == NULL || 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(); @@ -49,6 +49,8 @@ void Character::attack(Enemy *enemy) if (enemy->getHP() <= 0) delete enemy; m_ap -= m_weapon->getAPCost(); + if (m_ap < 0) + m_ap = 0; } std::string const& Character::getName() const { return m_name; } diff --git a/cpp04/ex01/Character.hpp b/cpp04/ex01/Character.hpp index 817fd53..08f1b59 100644 --- a/cpp04/ex01/Character.hpp +++ b/cpp04/ex01/Character.hpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 13:42:25 by charles #+# #+# */ -/* Updated: 2020/11/12 13:56:59 by cacharle ### ########.fr */ +/* Updated: 2020/11/13 11:14:03 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/cpp04/ex01/RadScorpion.hpp b/cpp04/ex01/RadScorpion.hpp index f07891e..70bac44 100644 --- a/cpp04/ex01/RadScorpion.hpp +++ b/cpp04/ex01/RadScorpion.hpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 13:35:04 by charles #+# #+# */ -/* Updated: 2020/11/12 14:24:38 by cacharle ### ########.fr */ +/* Updated: 2020/11/13 11:41:55 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ public: RadScorpion(); RadScorpion(RadScorpion const& other); RadScorpion& operator=(RadScorpion const& other); - ~RadScorpion(); + virtual ~RadScorpion(); private: }; diff --git a/cpp04/ex01/SuperMutant.cpp b/cpp04/ex01/SuperMutant.cpp index c9ce83c..8813217 100644 --- a/cpp04/ex01/SuperMutant.cpp +++ b/cpp04/ex01/SuperMutant.cpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 13:30:47 by charles #+# #+# */ -/* Updated: 2020/11/12 13:54:19 by cacharle ### ########.fr */ +/* Updated: 2020/11/13 10:35:24 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,5 +35,7 @@ SuperMutant::~SuperMutant() void SuperMutant::takeDamage(int amount) { + if (amount < 0) + amount = 3; Enemy::takeDamage(amount - 3); } diff --git a/cpp04/ex01/SuperMutant.hpp b/cpp04/ex01/SuperMutant.hpp index 64198de..4170a18 100644 --- a/cpp04/ex01/SuperMutant.hpp +++ b/cpp04/ex01/SuperMutant.hpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 13:29:53 by charles #+# #+# */ -/* Updated: 2020/11/12 13:50:54 by cacharle ### ########.fr */ +/* Updated: 2020/11/13 11:42:08 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -22,7 +22,7 @@ public: SuperMutant(); SuperMutant(SuperMutant const& other); SuperMutant& operator=(SuperMutant const& other); - ~SuperMutant(); + virtual ~SuperMutant(); virtual void takeDamage(int amount); diff --git a/cpp04/ex01/main.cpp b/cpp04/ex01/main.cpp index ca5b35e..5b907bd 100644 --- a/cpp04/ex01/main.cpp +++ b/cpp04/ex01/main.cpp @@ -6,19 +6,22 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 09:05:58 by charles #+# #+# */ -/* Updated: 2020/11/12 14:36:49 by cacharle ### ########.fr */ +/* Updated: 2020/11/13 12:00:52 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ +#include <climits> #include "Character.hpp" +#include "Enemy.hpp" #include "RadScorpion.hpp" +#include "SuperMutant.hpp" #include "PlasmaRifle.hpp" #include "PowerFist.hpp" int main() { { - std::cout << "================ SUBJECT MAIN =====================" << std::endl; + std::cout << "================ SUBJECT MAIN =====================" << std::endl; Character* me = new Character("me"); std::cout << *me; Enemy* b = new RadScorpion(); @@ -36,7 +39,6 @@ int main() me->attack(b); std::cout << *me; delete me; - ((RadScorpion*)b)->~RadScorpion(); delete pr; delete pf; } @@ -44,7 +46,177 @@ int main() std::cout << std::endl; { + std::cout << "================ PLASMA RIFLE =====================" << std::endl; + PlasmaRifle pr; + PlasmaRifle pr2(pr); + PlasmaRifle pr3; + pr3 = pr2; + std::cout << "Name: " << pr.getName() << std::endl; + std::cout << "AP Cost: " << pr.getAPCost() << std::endl; + std::cout << "Damage: " << pr.getDamage() << std::endl; + pr.attack(); + pr2.attack(); + pr3.attack(); + std::cout << "################ VIRTUAL" << std::endl; + AWeapon *w = ≺ + std::cout << "Name: " << w->getName() << std::endl; + std::cout << "AP Cost: " << w->getAPCost() << std::endl; + std::cout << "Damage: " << w->getDamage() << std::endl; + w->attack(); + } + + std::cout << std::endl; + + { + std::cout << "================ POWER FIST =====================" << std::endl; + PowerFist pf; + PowerFist pf2(pf); + PowerFist pf3; + pf3 = pf2; + std::cout << "Name: " << pf.getName() << std::endl; + std::cout << "AP Cost: " << pf.getAPCost() << std::endl; + std::cout << "Damage: " << pf.getDamage() << std::endl; + pf.attack(); + pf2.attack(); + pf3.attack(); + std::cout << "################ VIRTUAL" << std::endl; + AWeapon *w = &pf; + std::cout << "Name: " << w->getName() << std::endl; + std::cout << "AP Cost: " << w->getAPCost() << std::endl; + std::cout << "Damage: " << w->getDamage() << std::endl; + w->attack(); + } + + std::cout << std::endl; + + { + std::cout << "================ ENEMY =====================" << std::endl; + Enemy e(2000, "Titan"); + Enemy e2(e); + Enemy e3(0, "should not be printed"); + e3 = e2; + std::cout << "Type: " << e.getType() << ", HP: " << e.getHP() << std::endl; + std::cout << "Type: " << e2.getType() << ", HP: " << e2.getHP() << std::endl; + std::cout << "Type: " << e3.getType() << ", HP: " << e3.getHP() << std::endl; + std::cout << "################ TAKE DAMAGE" << std::endl; + std::cout << "HP: " << e.getHP() << std::endl; + e.takeDamage(10); + std::cout << "HP: " << e.getHP() << std::endl; + e.takeDamage(-1); + std::cout << "HP: " << e.getHP() << std::endl; + e.takeDamage(INT_MIN); + std::cout << "HP: " << e.getHP() << std::endl; + e.takeDamage(0); + std::cout << "HP: " << e.getHP() << std::endl; + e.takeDamage(3000); + std::cout << "HP: " << e.getHP() << std::endl; + } + + std::cout << std::endl; + + { + std::cout << "================ SUPER MUTANT ====================" << std::endl; + SuperMutant m; + SuperMutant m2(m); + SuperMutant m3; + m3 = m2; + std::cout << "Type: " << m.getType() << ", HP: " << m.getHP() << std::endl; + std::cout << "Type: " << m2.getType() << ", HP: " << m2.getHP() << std::endl; + std::cout << "Type: " << m3.getType() << ", HP: " << m3.getHP() << std::endl; + std::cout << "################ TAKE DAMAGE" << std::endl; + std::cout << "HP: " << m.getHP() << std::endl; + m.takeDamage(10); + std::cout << "HP: " << m.getHP() << std::endl; + m.takeDamage(-1); + std::cout << "HP: " << m.getHP() << std::endl; + m.takeDamage(INT_MIN); + std::cout << "HP: " << m.getHP() << std::endl; + m.takeDamage(0); + std::cout << "HP: " << m.getHP() << std::endl; + m.takeDamage(180); + std::cout << "HP: " << m.getHP() << std::endl; + } + + std::cout << std::endl; + + { + std::cout << "================ RAD SCORPION ====================" << std::endl; + RadScorpion s; + RadScorpion s2(s); + RadScorpion s3; + s3 = s2; + std::cout << "Type: " << s.getType() << ", HP: " << s.getHP() << std::endl; + std::cout << "Type: " << s2.getType() << ", HP: " << s2.getHP() << std::endl; + std::cout << "Type: " << s3.getType() << ", HP: " << s3.getHP() << std::endl; + std::cout << "################ TAKE DAMAGE" << std::endl; + std::cout << "HP: " << s.getHP() << std::endl; + s.takeDamage(10); + std::cout << "HP: " << s.getHP() << std::endl; + s.takeDamage(-1); + std::cout << "HP: " << s.getHP() << std::endl; + s.takeDamage(INT_MIN); + std::cout << "HP: " << s.getHP() << std::endl; + s.takeDamage(0); + std::cout << "HP: " << s.getHP() << std::endl; + s.takeDamage(90); + std::cout << "HP: " << s.getHP() << std::endl; + } + + std::cout << std::endl; + + { + std::cout << "================ CHARACTER ====================" << std::endl; + Character c("Jean-Didier"); + Character c2(c); + Character c3("should not be displayed"); + c3 = c2; + std::cout << c; + std::cout << c2; + std::cout << c3; + + std::cout << "################ ATTACK NO WEAPON" << std::endl; + Enemy* r = new RadScorpion(); + c.attack(r); + Enemy* s = new SuperMutant(); + c.attack(s); + + std::cout << "################ EQUIP" << std::endl; + PowerFist pf; + c.equip(&pf); + c.attack(r); + c.attack(s); + std::cout << c; + PlasmaRifle pr; + c.equip(&pr); + c.attack(r); + c.attack(s); + std::cout << c; + c.attack(s); + c.attack(s); + c.attack(s); + c.recoverAP(); + c.recoverAP(); + c.attack(s); + c.attack(s); + c.attack(s); + c.attack(s); + c.attack(s); + + std::cout << "################ RECOVER AP" << std::endl; + std::cout << c; + c.recoverAP(); + std::cout << c; + c.recoverAP(); + std::cout << c; + c.recoverAP(); + std::cout << c; + c.recoverAP(); + std::cout << c; + c.recoverAP(); + std::cout << c; + c.attack(r); + // std::cout << "################ DESTRUCTORS" << std::endl; } return 0; diff --git a/cpp04/ex02/AssaultTerminator.cpp b/cpp04/ex02/AssaultTerminator.cpp index c00a00c..a62c9e4 100644 --- a/cpp04/ex02/AssaultTerminator.cpp +++ b/cpp04/ex02/AssaultTerminator.cpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 15:47:06 by charles #+# #+# */ -/* Updated: 2020/11/12 15:37:48 by cacharle ### ########.fr */ +/* Updated: 2020/11/13 12:19:15 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,11 @@ AssaultTerminator::AssaultTerminator() std::cout << "* teleports from space *" << std::endl; } -AssaultTerminator::AssaultTerminator(AssaultTerminator const& other) { *this = other; } +AssaultTerminator::AssaultTerminator(AssaultTerminator const& other) +{ + std::cout << "* teleports from space *" << std::endl; + *this = other; +} AssaultTerminator& AssaultTerminator::operator=(AssaultTerminator const& other) { @@ -32,8 +36,7 @@ AssaultTerminator::~AssaultTerminator() ISpaceMarine* AssaultTerminator::clone() const { - ISpaceMarine* cloned = new AssaultTerminator(); - *cloned = *this; + ISpaceMarine* cloned = new AssaultTerminator(*this); return cloned; } diff --git a/cpp04/ex02/AssaultTerminator.hpp b/cpp04/ex02/AssaultTerminator.hpp index b2064f1..e1ac9f1 100644 --- a/cpp04/ex02/AssaultTerminator.hpp +++ b/cpp04/ex02/AssaultTerminator.hpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 15:46:20 by charles #+# #+# */ -/* Updated: 2020/11/12 15:36:54 by cacharle ### ########.fr */ +/* Updated: 2020/11/13 12:18:55 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,10 +24,10 @@ public: AssaultTerminator& operator=(AssaultTerminator const& other); virtual ~AssaultTerminator(); - virtual ISpaceMarine* clone() const; - virtual void battleCry() const; - virtual void rangedAttack() const; - virtual void meleeAttack() const; + virtual ISpaceMarine* clone() const; + virtual void battleCry() const; + virtual void rangedAttack() const; + virtual void meleeAttack() const; private: }; diff --git a/cpp04/ex02/Squad.cpp b/cpp04/ex02/Squad.cpp index d1d988f..1cc59f0 100644 --- a/cpp04/ex02/Squad.cpp +++ b/cpp04/ex02/Squad.cpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 15:08:35 by charles #+# #+# */ -/* Updated: 2020/11/12 15:38:55 by cacharle ### ########.fr */ +/* Updated: 2020/11/13 12:13:57 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,12 +14,12 @@ Squad::Squad() : m_units(new ISpaceMarine*[0]), m_size(0) {} -Squad::Squad(Squad const& other) { *this = other; } +Squad::Squad(Squad const& other) : m_units(NULL), m_size(0) { *this = other; } Squad& Squad::operator=(Squad const& other) { destroyUnits(); - m_size = other.m_size; + 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(); @@ -57,6 +57,8 @@ int Squad::push(ISpaceMarine* spaceMarine) void Squad::destroyUnits() { + if (m_units == NULL) + return; 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 index 9ea5268..48e53cd 100644 --- a/cpp04/ex02/Squad.hpp +++ b/cpp04/ex02/Squad.hpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 15:07:57 by charles #+# #+# */ -/* Updated: 2020/11/12 15:39:26 by cacharle ### ########.fr */ +/* Updated: 2020/11/13 12:06:51 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -25,15 +25,15 @@ public: Squad& operator=(Squad const& other); virtual ~Squad(); - virtual int getCount() const; - virtual ISpaceMarine* getUnit(int n) const; - virtual int push(ISpaceMarine* spaceMarine); + virtual int getCount() const; + virtual ISpaceMarine* getUnit(int n) const; + virtual int push(ISpaceMarine* spaceMarine); private: void destroyUnits(); ISpaceMarine** m_units; - int m_size; + int m_size; }; #endif diff --git a/cpp04/ex02/TacticalMarine.cpp b/cpp04/ex02/TacticalMarine.cpp index df771e8..cf30d2a 100644 --- a/cpp04/ex02/TacticalMarine.cpp +++ b/cpp04/ex02/TacticalMarine.cpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 15:31:43 by charles #+# #+# */ -/* Updated: 2020/11/12 15:37:41 by cacharle ### ########.fr */ +/* Updated: 2020/11/13 12:18:14 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,11 @@ TacticalMarine::TacticalMarine() std::cout << "Tactical Marine ready for battle!" << std::endl; } -TacticalMarine::TacticalMarine(TacticalMarine const& other) { *this = other; } +TacticalMarine::TacticalMarine(TacticalMarine const& other) +{ + std::cout << "Tactical Marine ready for battle!" << std::endl; + *this = other; +} TacticalMarine& TacticalMarine::operator=(TacticalMarine const& other) { @@ -32,8 +36,7 @@ TacticalMarine::~TacticalMarine() ISpaceMarine* TacticalMarine::clone() const { - ISpaceMarine* cloned = new TacticalMarine(); - *cloned = *this; + ISpaceMarine* cloned = new TacticalMarine(*this); return cloned; } diff --git a/cpp04/ex02/TacticalMarine.hpp b/cpp04/ex02/TacticalMarine.hpp index 43722d6..965cb30 100644 --- a/cpp04/ex02/TacticalMarine.hpp +++ b/cpp04/ex02/TacticalMarine.hpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 15:30:48 by charles #+# #+# */ -/* Updated: 2020/11/12 15:38:03 by cacharle ### ########.fr */ +/* Updated: 2020/11/13 12:16:07 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -24,10 +24,10 @@ public: TacticalMarine& operator=(TacticalMarine const& other); virtual ~TacticalMarine(); - virtual ISpaceMarine* clone() const; - virtual void battleCry() const; - virtual void rangedAttack() const; - virtual void meleeAttack() const; + virtual ISpaceMarine* clone() const; + virtual void battleCry() const; + virtual void rangedAttack() const; + virtual void meleeAttack() const; private: }; diff --git a/cpp04/ex02/main.cpp b/cpp04/ex02/main.cpp index 137ce46..c53dadb 100644 --- a/cpp04/ex02/main.cpp +++ b/cpp04/ex02/main.cpp @@ -6,7 +6,7 @@ /* 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 */ +/* Updated: 2020/11/13 12:36:22 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,20 +18,112 @@ int main() { - ISpaceMarine* bob = new TacticalMarine; - ISpaceMarine* jim = new AssaultTerminator; + { + std::cout << "================ SUBJECT MAIN =====================" << std::endl; + 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; + } + + std::cout << std::endl; + + { + std::cout << "================ TACTICAL MARINE =====================" << std::endl; + TacticalMarine t; + t.battleCry(); + t.rangedAttack(); + t.meleeAttack(); + TacticalMarine t2(t); + TacticalMarine t3; + t3 = t; + std::cout << "################ INTERFACE" << std::endl; + ISpaceMarine *sm = new TacticalMarine(); + sm->battleCry(); + sm->rangedAttack(); + sm->meleeAttack(); + delete sm; + } + + std::cout << std::endl; - 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(); + std::cout << "================ ASSAULT TERMINATOR =====================" << std::endl; + AssaultTerminator a; + a.battleCry(); + a.rangedAttack(); + a.meleeAttack(); + AssaultTerminator a2(a); + AssaultTerminator a3; + a3 = a; + std::cout << "################ INTERFACE" << std::endl; + ISpaceMarine *sm = new AssaultTerminator(); + sm->battleCry(); + sm->rangedAttack(); + sm->meleeAttack(); + delete sm; + } + + std::cout << std::endl; + + { + std::cout << "================ SQUAD =====================" << std::endl; + Squad s; + std::cout << "Count: " << s.getCount() << std::endl; + s.push(new TacticalMarine()); + std::cout << "Count: " << s.getCount() << std::endl; + s.push(new TacticalMarine()); + s.push(new AssaultTerminator()); + s.push(new AssaultTerminator()); + std::cout << "Count: " << s.getCount() << std::endl; + s.getUnit(0)->battleCry(); + s.getUnit(1)->battleCry(); + s.getUnit(2)->battleCry(); + s.getUnit(3)->battleCry(); + s.getUnit(3)->rangedAttack(); + s.getUnit(3)->meleeAttack(); + s.getUnit(0)->rangedAttack(); + s.getUnit(0)->meleeAttack(); + std::cout << s.getUnit(4) << std::endl; + std::cout << s.getUnit(-1) << std::endl; + + std::cout << "################ COPY" << std::endl; + Squad s2(s); + std::cout << "Copy Count: " << s2.getCount() << std::endl; + s2.push(new TacticalMarine()); + std::cout << "Copy Count: " << s2.getCount() << std::endl; + std::cout << "Origin Count: " << s.getCount() << std::endl; + + std::cout << "################ ASSIGN" << std::endl; + Squad s3; + s3 = s; + std::cout << "Copy Count: " << s3.getCount() << std::endl; + s3.push(new TacticalMarine()); + std::cout << "Copy Count: " << s3.getCount() << std::endl; + std::cout << "Origin Count: " << s.getCount() << std::endl; + + std::cout << "################ INTERFACE" << std::endl; + ISquad *si = new Squad(); + si->push(new TacticalMarine()); + std::cout << si->getCount() << std::endl; + si->getUnit(0)->battleCry(); + si->push(new AssaultTerminator()); + std::cout << si->getCount() << std::endl; + si->getUnit(1)->battleCry(); + delete si; + + std::cout << "################ DESTROY" << std::endl; } - delete vlc; return 0; } diff --git a/cpp04/ex03/AMateria.cpp b/cpp04/ex03/AMateria.cpp index 1dc7ca9..b08c4f2 100644 --- a/cpp04/ex03/AMateria.cpp +++ b/cpp04/ex03/AMateria.cpp @@ -6,21 +6,21 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 16:26:57 by charles #+# #+# */ -/* Updated: 2020/11/12 15:40:23 by cacharle ### ########.fr */ +/* Updated: 2020/11/13 14:26:28 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "AMateria.hpp" -AMateria::AMateria(AMateria const& other) +AMateria::AMateria(AMateria const& other) : m_type(other.m_type) { *this = other; - m_type = ""; } AMateria& AMateria::operator=(AMateria const& other) { - _xp = other._xp; + _xp = other._xp; + // subject doesn't want type to be copied return *this; } @@ -28,13 +28,13 @@ AMateria::~AMateria() {} AMateria::AMateria(std::string const& type) : m_type(type), _xp(0) {} -std::string const& AMateria::getType() const +std::string const& AMateria::getType() const { return m_type; } +unsigned int AMateria::getXP() const { return _xp; } + +void AMateria::use(ICharacter& target) { - return m_type; + (void)target; + _xp += 10; } -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 index 7fef1c8..41ef132 100644 --- a/cpp04/ex03/AMateria.hpp +++ b/cpp04/ex03/AMateria.hpp @@ -6,7 +6,7 @@ /* By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/04/14 16:24:00 by charles #+# #+# */ -/* Updated: 2020/11/12 15:41:54 by cacharle ### ########.fr */ +/* Updated: 2020/11/13 14:42:03 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -26,17 +26,18 @@ public: virtual ~AMateria(); AMateria(std: |
