diff --git a/README.md b/README.md index 39af52c..bf2a11c 100644 --- a/README.md +++ b/README.md @@ -1,29 +1,2 @@ # README # -This README would normally document whatever steps are necessary to get your application up and running. - -### What is this repository for? ### - -* Quick summary -* Version -* [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo) - -### How do I get set up? ### - -* Summary of set up -* Configuration -* Dependencies -* Database configuration -* How to run tests -* Deployment instructions - -### Contribution guidelines ### - -* Writing tests -* Code review -* Other guidelines - -### Who do I talk to? ### - -* Repo owner or admin -* Other community or team contact \ No newline at end of file diff --git a/cpp_module_00/Warlock.hpp b/cpp_module_00/Warlock.hpp index 7bd80d5..fb77763 100644 --- a/cpp_module_00/Warlock.hpp +++ b/cpp_module_00/Warlock.hpp @@ -1,10 +1,11 @@ #ifndef WARLOCK_HPP -# define WARLOCK_HPP +#define WARLOCK_HPP -# include -# include +#include +#include -class Warlock { +class Warlock +{ private: Warlock(); Warlock(Warlock const & other); @@ -14,34 +15,36 @@ class Warlock { std::string title; public: - Warlock(std::string const & name, std::string const & title) + Warlock(std::string const name, std::string const title) { this->name = name; this->title = title; std::cout << this->name << ": This looks like another boring day.\n"; - }; + } ~Warlock() { std::cout << this->name << ": My job here is done!\n"; - }; + } std::string const & getName() const { - return (this->name); - }; + return this->name; + } std::string const & getTitle() const { - return (this->title); - }; + return this->title; + } + void setTitle(std::string const & title) { this->title = title; - }; + } void introduce() const { std::cout << this->name << ": I am " << this->name << ", " << this->title << "!\n"; - }; + } }; #endif + diff --git a/cpp_module_00/a.out b/cpp_module_00/a.out index e797334..8226c11 100755 Binary files a/cpp_module_00/a.out and b/cpp_module_00/a.out differ diff --git a/cpp_module_01/ASpell.cpp b/cpp_module_01/ASpell.cpp index 8fb6110..867abf3 100644 --- a/cpp_module_01/ASpell.cpp +++ b/cpp_module_01/ASpell.cpp @@ -3,4 +3,5 @@ void ASpell::launch(ATarget const & atarget) const { atarget.getHitBySpell(*this); -}; +} + diff --git a/cpp_module_01/ASpell.hpp b/cpp_module_01/ASpell.hpp index e9c4705..36819b9 100644 --- a/cpp_module_01/ASpell.hpp +++ b/cpp_module_01/ASpell.hpp @@ -1,55 +1,54 @@ #ifndef ASPELL_HPP -# define ASPELL_HPP +#define ASPELL_HPP -# include -# include +#include +#include class ATarget; -class ASpell { - - private: +class ASpell +{ + protected: std::string name; std::string effects; public: ASpell() - {}; + {} ASpell(ASpell const & other) { *this = other; - }; + } ASpell & operator=(ASpell const & other) { this->name = other.name; this->effects = other.effects; - return (*this); - }; + return *this; + } ASpell(std::string const & name, std::string const & effects) { this->name = name; this->effects = effects; - }; + } virtual ~ASpell() - {}; + {} std::string const & getName() const { - return (this->name); - }; + return this->name; + } std::string const & getEffects() const { - return (this->effects); - }; + return this->effects; + } - void launch(ATarget const & atarget) const; + void launch(ATarget const &) const; virtual ASpell * clone() const = 0; + }; #include "ATarget.hpp" #endif - - diff --git a/cpp_module_01/ATarget.cpp b/cpp_module_01/ATarget.cpp index 61d5361..b0f2720 100644 --- a/cpp_module_01/ATarget.cpp +++ b/cpp_module_01/ATarget.cpp @@ -3,4 +3,5 @@ void ATarget::getHitBySpell(ASpell const & aspell) const { std::cout << this->type << " has been " << aspell.getEffects() << "!\n"; -}; +} + diff --git a/cpp_module_01/ATarget.hpp b/cpp_module_01/ATarget.hpp index c74e741..38a9012 100644 --- a/cpp_module_01/ATarget.hpp +++ b/cpp_module_01/ATarget.hpp @@ -1,45 +1,47 @@ #ifndef ATARGET_HPP -# define ATARGET_HPP +#define ATARGET_HPP -# include -# include +#include +#include class ASpell; -class ATarget { - - private: +class ATarget +{ + protected: std::string type; public: ATarget() - {}; + {} ATarget(ATarget const & other) { - *this = other; - }; + * this = other; + } ATarget & operator=(ATarget const & other) { this->type = other.type; - return (*this); - }; + return *this; + } ATarget(std::string const & type) { this->type = type; - }; - ~ATarget() - {}; + } + virtual ~ATarget() + {} std::string const & getType() const { - return (this->type); - }; + return this->type; + } - void getHitBySpell(ASpell const & aspell) const; + void getHitBySpell(ASpell const &) const; virtual ATarget * clone() const = 0; + }; #include "ASpell.hpp" #endif + diff --git a/cpp_module_01/Dummy.cpp b/cpp_module_01/Dummy.cpp index 6eb8744..2e8ab16 100644 --- a/cpp_module_01/Dummy.cpp +++ b/cpp_module_01/Dummy.cpp @@ -1,2 +1 @@ #include "Dummy.hpp" - diff --git a/cpp_module_01/Dummy.hpp b/cpp_module_01/Dummy.hpp index f9debbc..a482921 100644 --- a/cpp_module_01/Dummy.hpp +++ b/cpp_module_01/Dummy.hpp @@ -1,20 +1,21 @@ #ifndef DUMMY_HPP -# define DUMMY_HPP +#define DUMMY_HPP -# include "ATarget.hpp" - -class Dummy: public ATarget { +#include "ATarget.hpp" +class Dummy: public ATarget +{ public: Dummy(): ATarget("Target Practice Dummy") - {}; + {} ~Dummy() - {}; + {} virtual ATarget * clone() const { return (new Dummy()); - }; + } }; #endif + diff --git a/cpp_module_01/Fwoosh.hpp b/cpp_module_01/Fwoosh.hpp index 046ad8f..0809ee3 100644 --- a/cpp_module_01/Fwoosh.hpp +++ b/cpp_module_01/Fwoosh.hpp @@ -1,20 +1,21 @@ #ifndef FWOOSH_HPP #define FWOOSH_HPP -# include "ASpell.hpp" - -class Fwoosh: public ASpell { +#include "ASpell.hpp" +class Fwoosh: public ASpell +{ public: Fwoosh(): ASpell("Fwoosh", "fwooshed") - {}; + {} ~Fwoosh() - {}; + {} virtual ASpell * clone() const { return (new Fwoosh()); - }; + } }; #endif + diff --git a/cpp_module_01/Warlock.hpp b/cpp_module_01/Warlock.hpp index d09d8f0..329830b 100644 --- a/cpp_module_01/Warlock.hpp +++ b/cpp_module_01/Warlock.hpp @@ -1,15 +1,15 @@ #ifndef WARLOCK_HPP -# define WARLOCK_HPP +#define WARLOCK_HPP -# include -# include -# include +#include +#include +#include -# include "ASpell.hpp" -# include "ATarget.hpp" - -class Warlock { +#include "ASpell.hpp" +#include "ATarget.hpp" +class Warlock +{ private: Warlock(); Warlock(Warlock const & other); @@ -17,71 +17,73 @@ class Warlock { std::string name; std::string title; - std::map arr; + std::map arr; public: Warlock(std::string const & name, std::string const & title) { this->name = name; - this->title = title; + this->title = title; std::cout << this->name << ": This looks like another boring day.\n"; - }; + } ~Warlock() { std::cout << this->name << ": My job here is done!\n"; - std::map::iterator it_begin = this->arr.begin(); - std::map::iterator it_end = this->arr.end(); - while (it_begin != it_end) { - delete it_begin->second; - ++it_begin; - } + + std::map::iterator it; + + for (it = arr.begin(); it != arr.end(); ++it) + delete it->second; + this->arr.clear(); - }; + } std::string const & getName() const { - return (this->name); - }; + return this->name; + } std::string const & getTitle() const { - return (this->title); - }; + return this->title; + } void setTitle(std::string const & title) { this->title = title; - }; + } void introduce() const { std::cout << this->name << ": I am " << this->name << ", " << this->title << "!\n"; - }; + } void learnSpell(ASpell * aspell) { if (aspell) { - arr.insert(std::pair + arr.insert(std::pair ( aspell->getName(), aspell->clone() )); } - }; - void forgetSpell(std::string name) + } + void forgetSpell(std::string spell_name) { - std::map::iterator it = arr.find(name); - if (it == arr.end()) - return; - delete it->second; - arr.erase(name); - }; - void launchSpell(std::string name, ATarget const & target) - { - ASpell * spell = arr[name]; + ASpell * spell = arr[spell_name]; if (spell) - spell->launch(target); - }; + { + delete spell; + arr.erase(spell_name); + } + } + void launchSpell(std::string spell_name, ATarget const & atarget) + { + ASpell * spell = arr[spell_name]; + if (spell) + spell->launch(atarget); + } }; #endif + diff --git a/cpp_module_01/a.out b/cpp_module_01/a.out index 8ad5690..f65a3d8 100755 Binary files a/cpp_module_01/a.out and b/cpp_module_01/a.out differ diff --git a/cpp_module_01/main.cpp b/cpp_module_01/main.cpp index 3d12dfe..9ffb04d 100644 --- a/cpp_module_01/main.cpp +++ b/cpp_module_01/main.cpp @@ -4,17 +4,17 @@ int main() { - Warlock richard("Richard", "the Titled"); + Warlock richard("Richard", "the Titled"); - Dummy bob; - Fwoosh* fwoosh = new Fwoosh(); + Dummy bob; + Fwoosh* fwoosh = new Fwoosh(); - richard.learnSpell(fwoosh); + richard.learnSpell(fwoosh); - richard.introduce(); - richard.launchSpell("Fwoosh", bob); + richard.introduce(); + richard.launchSpell("Fwoosh", bob); - richard.forgetSpell("Fwoosh"); - richard.launchSpell("Fwoosh", bob); + richard.forgetSpell("Fwoosh"); + richard.launchSpell("Fwoosh", bob); delete fwoosh; } diff --git a/cpp_module_01/test b/cpp_module_01/test new file mode 100755 index 0000000..4061c6f Binary files /dev/null and b/cpp_module_01/test differ diff --git a/cpp_module_02/ASpell.cpp b/cpp_module_02/ASpell.cpp index 2cb07c0..867abf3 100644 --- a/cpp_module_02/ASpell.cpp +++ b/cpp_module_02/ASpell.cpp @@ -1,5 +1,7 @@ #include "ASpell.hpp" -void ASpell::launch(ATarget const & atarget) const { +void ASpell::launch(ATarget const & atarget) const +{ atarget.getHitBySpell(*this); -}; +} + diff --git a/cpp_module_02/ASpell.hpp b/cpp_module_02/ASpell.hpp index be0a66c..36819b9 100644 --- a/cpp_module_02/ASpell.hpp +++ b/cpp_module_02/ASpell.hpp @@ -1,45 +1,54 @@ #ifndef ASPELL_HPP -# define ASPELL_HPP +#define ASPELL_HPP -# include -# include +#include +#include class ATarget; -class ASpell { - private: +class ASpell +{ + protected: std::string name; std::string effects; public: - ASpell() { - }; - ASpell(ASpell const & other) { + ASpell() + {} + ASpell(ASpell const & other) + { *this = other; - }; - ASpell & operator=(ASpell const & other) { + } + ASpell & operator=(ASpell const & other) + { this->name = other.name; this->effects = other.effects; - return (*this); - }; - ASpell(std::string const & name, std::string const & effects) { + return *this; + } + ASpell(std::string const & name, std::string const & effects) + { this->name = name; this->effects = effects; - }; - virtual ~ASpell() { - }; + } + virtual ~ASpell() + {} - std::string const & getName() const { - return (this->name); - }; - std::string const & getEffects() const { - return (this->effects); - }; - void launch(ATarget const & atarget) const; + std::string const & getName() const + { + return this->name; + } + std::string const & getEffects() const + { + return this->effects; + } + + void launch(ATarget const &) const; virtual ASpell * clone() const = 0; + }; #include "ATarget.hpp" #endif + diff --git a/cpp_module_02/ATarget.cpp b/cpp_module_02/ATarget.cpp index 3685615..b0f2720 100644 --- a/cpp_module_02/ATarget.cpp +++ b/cpp_module_02/ATarget.cpp @@ -1,5 +1,7 @@ #include "ATarget.hpp" -void ATarget::getHitBySpell(ASpell const & aspell) const { +void ATarget::getHitBySpell(ASpell const & aspell) const +{ std::cout << this->type << " has been " << aspell.getEffects() << "!\n"; -}; +} + diff --git a/cpp_module_02/ATarget.hpp b/cpp_module_02/ATarget.hpp index 4a31b0c..38a9012 100644 --- a/cpp_module_02/ATarget.hpp +++ b/cpp_module_02/ATarget.hpp @@ -1,40 +1,47 @@ #ifndef ATARGET_HPP -# define ATARGET_HPP +#define ATARGET_HPP -# include -# include +#include +#include class ASpell; -class ATarget { - private: - +class ATarget +{ + protected: std::string type; public: - ATarget() { - }; - ATarget(std::string const & type) { - this->type = type; - }; - ATarget(ATarget const & other) { - *this = other; - }; - ATarget & operator=(ATarget const & other) { + ATarget() + {} + ATarget(ATarget const & other) + { + * this = other; + } + ATarget & operator=(ATarget const & other) + { this->type = other.type; - return (*this); - }; - virtual ~ATarget() {}; + return *this; + } + ATarget(std::string const & type) + { + this->type = type; + } + virtual ~ATarget() + {} - std::string const & getType() const { - return (this->type); - }; + std::string const & getType() const + { + return this->type; + } - void getHitBySpell(ASpell const & aspell) const; + void getHitBySpell(ASpell const &) const; virtual ATarget * clone() const = 0; + }; #include "ASpell.hpp" #endif + diff --git a/cpp_module_02/BrickWall.hpp b/cpp_module_02/BrickWall.hpp index 01afd84..7993a06 100644 --- a/cpp_module_02/BrickWall.hpp +++ b/cpp_module_02/BrickWall.hpp @@ -1,16 +1,21 @@ #ifndef BRICKWALL_HPP -# define BRICKWALL_HPP +#define BRICKWALL_HPP -# include "ATarget.hpp" +#include "ATarget.hpp" -class BrickWall: public ATarget { +class BrickWall: public ATarget +{ public: - BrickWall(): ATarget("Inconspicuous Red-brick Wall") {}; - ~BrickWall() {}; + BrickWall(): ATarget("Inconspicuous Red-brick Wall") + {} + ~BrickWall() + {} - virtual ATarget * clone() const { + virtual ATarget * clone() const + { return (new BrickWall()); - }; + } }; #endif + diff --git a/cpp_module_02/Dummy.cpp b/cpp_module_02/Dummy.cpp index 6eb8744..2e8ab16 100644 --- a/cpp_module_02/Dummy.cpp +++ b/cpp_module_02/Dummy.cpp @@ -1,2 +1 @@ #include "Dummy.hpp" - diff --git a/cpp_module_02/Dummy.hpp b/cpp_module_02/Dummy.hpp index 9d4167f..a482921 100644 --- a/cpp_module_02/Dummy.hpp +++ b/cpp_module_02/Dummy.hpp @@ -1,16 +1,21 @@ #ifndef DUMMY_HPP -# define DUMMY_HPP +#define DUMMY_HPP -# include "ATarget.hpp" +#include "ATarget.hpp" -class Dummy: public ATarget { +class Dummy: public ATarget +{ public: - Dummy(): ATarget("Target Practice Dummy") {}; - ~Dummy() {}; + Dummy(): ATarget("Target Practice Dummy") + {} + ~Dummy() + {} - virtual ATarget * clone() const { + virtual ATarget * clone() const + { return (new Dummy()); - }; + } }; #endif + diff --git a/cpp_module_02/Fireball.hpp b/cpp_module_02/Fireball.hpp index c961156..e7e4d5f 100644 --- a/cpp_module_02/Fireball.hpp +++ b/cpp_module_02/Fireball.hpp @@ -1,16 +1,21 @@ #ifndef FIREBALL_HPP #define FIREBALL_HPP -# include "ASpell.hpp" +#include "ASpell.hpp" -class Fireball: public ASpell { +class Fireball: public ASpell +{ public: - Fireball(): ASpell("Fireball", "burnt to a crisp") {}; - ~Fireball() {}; + Fireball(): ASpell("Fireball", "burnt to a crisp") + {} + ~Fireball() + {} - virtual ASpell * clone() const { + virtual ASpell * clone() const + { return (new Fireball()); - }; + } }; #endif + diff --git a/cpp_module_02/Fwoosh.hpp b/cpp_module_02/Fwoosh.hpp index d49fbbc..0809ee3 100644 --- a/cpp_module_02/Fwoosh.hpp +++ b/cpp_module_02/Fwoosh.hpp @@ -1,16 +1,21 @@ #ifndef FWOOSH_HPP #define FWOOSH_HPP -# include "ASpell.hpp" +#include "ASpell.hpp" -class Fwoosh: public ASpell { +class Fwoosh: public ASpell +{ public: - Fwoosh(): ASpell("Fwoosh", "fwooshed") {}; - ~Fwoosh() {}; + Fwoosh(): ASpell("Fwoosh", "fwooshed") + {} + ~Fwoosh() + {} - virtual ASpell * clone() const { + virtual ASpell * clone() const + { return (new Fwoosh()); - }; + } }; #endif + diff --git a/cpp_module_02/Polymorph.cpp b/cpp_module_02/Polymorph.cpp index ac17197..58a35cd 100644 --- a/cpp_module_02/Polymorph.cpp +++ b/cpp_module_02/Polymorph.cpp @@ -1,2 +1 @@ #include "Polymorph.hpp" - diff --git a/cpp_module_02/Polymorph.hpp b/cpp_module_02/Polymorph.hpp index 1f104ce..39f4ed4 100644 --- a/cpp_module_02/Polymorph.hpp +++ b/cpp_module_02/Polymorph.hpp @@ -1,16 +1,21 @@ #ifndef POLYMORPH_HPP #define POLYMORPH_HPP -# include "ASpell.hpp" +#include "ASpell.hpp" -class Polymorph: public ASpell { +class Polymorph: public ASpell +{ public: - Polymorph(): ASpell("Polymorph", "turned into a critter") {}; - ~Polymorph() {}; + Polymorph(): ASpell("Polymorph", "turned into a critter") + {} + ~Polymorph() + {} - virtual ASpell * clone() const { + virtual ASpell * clone() const + { return (new Polymorph()); - }; + } }; #endif + diff --git a/cpp_module_02/SpellBook.cpp b/cpp_module_02/SpellBook.cpp index bc6fd84..7faf59b 100644 --- a/cpp_module_02/SpellBook.cpp +++ b/cpp_module_02/SpellBook.cpp @@ -1,2 +1,2 @@ -#include "Warlock.hpp" +#include "SpellBook.hpp" diff --git a/cpp_module_02/SpellBook.hpp b/cpp_module_02/SpellBook.hpp index e6c964c..290a0cc 100644 --- a/cpp_module_02/SpellBook.hpp +++ b/cpp_module_02/SpellBook.hpp @@ -1,50 +1,61 @@ -#ifndef SPELLBOOK_HPP +#ifndef SPELLBOOK_HPP #define SPELLBOOK_HPP -# include -# include -# include "ASpell.hpp" -# include +#include +#include +#include -class SpellBook { +#include "ASpell.hpp" + +class SpellBook +{ private: SpellBook(SpellBook const & other); SpellBook & operator=(SpellBook const & other); - std::map arr; + std::map arr; public: - SpellBook() {}; - ~SpellBook() { - std::map::iterator it_begin = this->arr.begin(); - std::map::iterator it_end = this->arr.end(); - while (it_begin != it_end) { - delete it_begin->second; - ++it_begin; - } + SpellBook() + {} + ~SpellBook() + { + std::map::iterator it; + for (it = arr.begin(); it != arr.end(); ++it) + delete it->second; this->arr.clear(); - }; + } - void learnSpell(ASpell *aspell) { + void learnSpell(ASpell * aspell) + { if (aspell) - arr.insert(std::pair( + { + arr.insert(std::pair + ( aspell->getName(), aspell->clone() )); - }; - void forgetSpell(std::string & name) { - std::map::iterator it = arr.find(name); - if (it == arr.end()) - return; - delete it->second; - arr.erase(name); - }; - ASpell * createSpell(std::string & name) { - std::map::iterator it = arr.find(name); - if (it == arr.end()) - return NULL; - return arr[name]; - }; + } + } + void forgetSpell(std::string const & spell_name) + { + std::map::iterator it; + it = arr.find(spell_name); + if (it != arr.end()) + { + delete it->second; + arr.erase(spell_name); + } + } + ASpell * createSpell(std::string const & spell_name) + { + std::map::iterator it; + it = arr.find(spell_name); + if (it != arr.end()) + return arr[spell_name]; + return NULL; + } }; #endif + diff --git a/cpp_module_02/TargetGenerator.hpp b/cpp_module_02/TargetGenerator.hpp index c1e12d0..5032919 100644 --- a/cpp_module_02/TargetGenerator.hpp +++ b/cpp_module_02/TargetGenerator.hpp @@ -1,50 +1,65 @@ -#ifndef TARGETGENERATOR_HPP +#ifndef TARGETGENERATOR_HPP #define TARGETGENERATOR_HPP -# include -# include -# include "ATarget.hpp" -# include +#include +#include +#include -class TargetGenerator { +#include "ATarget.hpp" + +class TargetGenerator +{ private: TargetGenerator(TargetGenerator const & other); TargetGenerator & operator=(TargetGenerator const & other); - std::map arr; + std::map arr; public: - TargetGenerator() { - }; - ~TargetGenerator() { - std::map::iterator it_begin = this->arr.begin(); - std::map::iterator it_end = this->arr.end(); - while (it_begin != it_end) { - delete it_begin->second; - ++it_begin; - } + TargetGenerator() + {} + ~TargetGenerator() + { + std::map::iterator it; + for (it = arr.begin(); it != arr.end(); ++it) + delete it->second; this->arr.clear(); - }; + } - void learnTargetType(ATarget * atarget) { + void learnTargetType(ATarget * atarget) + { if (atarget) - arr.insert(std::pair( + { + arr.insert(std::pair + ( atarget->getType(), atarget->clone() )); - }; - void forgetTargetType(std::string const & name) { - std::map::iterator it = arr.find(name); + } + } + void forgetTargetType(std::string const & type) + { + std::map::iterator it; + it = arr.find(type); if (it != arr.end()) + { delete it->second; - arr.erase(name); - }; - ATarget * createTarget(std::string const & name) { - std::map::iterator it = arr.find(name); + arr.erase(type); + } + } + + ATarget * createTarget(std::string const & type) + { + std::map::iterator it; + it = arr.find(type); if (it != arr.end()) - return arr[name]; + return arr[type]->clone(); return NULL; - }; + } + + }; #endif + + diff --git a/cpp_module_02/Warlock.cpp b/cpp_module_02/Warlock.cpp index 7faf59b..bc6fd84 100644 --- a/cpp_module_02/Warlock.cpp +++ b/cpp_module_02/Warlock.cpp @@ -1,2 +1,2 @@ -#include "SpellBook.hpp" +#include "Warlock.hpp" diff --git a/cpp_module_02/Warlock.hpp b/cpp_module_02/Warlock.hpp index 0a40262..a11b239 100644 --- a/cpp_module_02/Warlock.hpp +++ b/cpp_module_02/Warlock.hpp @@ -1,13 +1,16 @@ #ifndef WARLOCK_HPP -# define WARLOCK_HPP +#define WARLOCK_HPP -# include -# include -# include "ASpell.hpp" -# include "ATarget.hpp" -# include "SpellBook.hpp" +#include +#include +#include -class Warlock { +#include "SpellBook.hpp" +#include "ASpell.hpp" +#include "ATarget.hpp" + +class Warlock +{ private: Warlock(); Warlock(Warlock const & other); @@ -15,57 +18,61 @@ class Warlock { std::string name; std::string title; - SpellBook book; + + SpellBook * book; public: Warlock(std::string const & name, std::string const & title) { this->name = name; - this->title = title; + this->title = title; + book = new SpellBook(); std::cout << this->name << ": This looks like another boring day.\n"; - }; + } ~Warlock() { std::cout << this->name << ": My job here is done!\n"; - }; + + delete book; + } std::string const & getName() const { - return (this->name); - }; + return this->name; + } std::string const & getTitle() const { - return (this->title); - }; + return this->title; + } void setTitle(std::string const & title) { this->title = title; - }; + } void introduce() const { std::cout << this->name << ": I am " << this->name << ", " << this->title << "!\n"; - }; + } - void learnSpell(ASpell *aspell) + void learnSpell(ASpell * aspell) { - book.learnSpell(aspell); - }; - void forgetSpell(std::string name) + book->learnSpell(aspell); + } + void forgetSpell(std::string spell_name) { - book.forgetSpell(name); - }; - void launchSpell(std::string name, ATarget const & atarget) + book->forgetSpell(spell_name); + } + void launchSpell(std::string spell_name, ATarget const & atarget) { - //ATarget const * test = 0; - //if (test == & atarget) - // return; - - ASpell * spell = book.createSpell(name); + ATarget * test = NULL; + if (&atarget == test) + return; + ASpell * spell = book->createSpell(spell_name); if (spell) spell->launch(atarget); - }; + } }; #endif + diff --git a/cpp_module_02/a.out b/cpp_module_02/a.out index fd928af..4b513d7 100755 Binary files a/cpp_module_02/a.out and b/cpp_module_02/a.out differ diff --git a/cpp_module_02/main.cpp b/cpp_module_02/main.cpp index a492eae..a77effd 100644 --- a/cpp_module_02/main.cpp +++ b/cpp_module_02/main.cpp @@ -8,23 +8,205 @@ int main() { - Warlock richard("Richard", "foo"); - richard.setTitle("Hello, I'm Richard the Warlock!"); - BrickWall model1; + // test subect + { + Warlock richard("Richard", "foo"); + richard.setTitle("Hello, I'm Richard the Warlock!"); + BrickWall model1; - Polymorph* polymorph = new Polymorph(); - TargetGenerator tarGen; + Polymorph* polymorph = new Polymorph(); + TargetGenerator tarGen; - tarGen.learnTargetType(&model1); - richard.learnSpell(polymorph); + tarGen.learnTargetType(&model1); + richard.learnSpell(polymorph); - Fireball* fireball = new Fireball(); + Fireball* fireball = new Fireball(); - richard.learnSpell(fireball); + richard.learnSpell(fireball); - ATarget* wall = tarGen.createTarget("Inconspicuous Red-brick Wall"); + ATarget* wall = tarGen.createTarget("Inconspicuous Red-brick Wall"); - richard.introduce(); - richard.launchSpell("Polymorph", *wall); - richard.launchSpell("Fireball", *wall); + richard.introduce(); + richard.launchSpell("Polymorph", *wall); + richard.launchSpell("Fireball", *wall); + } + + // my test + { + Warlock richard("Richard", "foo"); + BrickWall * wall = new BrickWall(); + Fireball * fireball = new Fireball(); + + richard.launchSpell("Fireball", *wall); + + std::cout << "-\n"; + + richard.learnSpell(fireball); + richard.launchSpell("Fireball", *wall); + richard.learnSpell(fireball); + richard.launchSpell("Fireball", *wall); + + std::cout << "-\n"; + + richard.forgetSpell(fireball->getName()); + richard.launchSpell("Fireball", *wall); + richard.forgetSpell(fireball->getName()); + richard.launchSpell("Fireball", *wall); + richard.forgetSpell(fireball->getName()); + richard.launchSpell("Fireball", *wall); + + std::cout << "--\n"; + richard.learnSpell(fireball); + + TargetGenerator tarGen; + Dummy dummy; + + ATarget * dum = tarGen.createTarget(dummy.getType()); + richard.launchSpell("Fireball", *dum); + + std::cout << "-\n"; + + tarGen.learnTargetType(&dummy); + richard.launchSpell("Fireball", *dum); + dum = tarGen.createTarget(dummy.getType()); + richard.launchSpell("Fireball", *dum); + + tarGen.learnTargetType(&dummy); + richard.launchSpell("Fireball", *dum); + dum = tarGen.createTarget(dummy.getType()); + richard.launchSpell("Fireball", *dum); + + std::cout << "-\n"; + + tarGen.forgetTargetType(dummy.getType()); + richard.launchSpell("Fireball", *dum); + dum = tarGen.createTarget(dummy.getType()); + richard.launchSpell("Fireball", *dum); + + tarGen.forgetTargetType(dummy.getType()); + richard.launchSpell("Fireball", *dum); + dum = tarGen.createTarget(dummy.getType()); + richard.launchSpell("Fireball", *dum); + + tarGen.forgetTargetType(dummy.getType()); + richard.launchSpell("Fireball", *dum); + dum = tarGen.createTarget(dummy.getType()); + richard.launchSpell("Fireball", *dum); + } + + std::cout << "\n-----------------\n"; + // https://github.com/adbenoit-9/42_exams/tree/main/Exam_rank_05/cpp_module_02 + { + Warlock richard("Richard", "foo"); + + // test copy + Fireball * fire = new Fireball(); + BrickWall * wall = new BrickWall(); + TargetGenerator tarGen; + tarGen.learnTargetType(wall); + richard.learnSpell(fire); + const std::string name(fire->getName()); + const std::string effects(fire->getEffects()); + const std::string type(wall->getType()); + delete fire; + delete wall; + ATarget* target = tarGen.createTarget(type); + richard.launchSpell(name, *target); + + // test double + fire = new Fireball(); + richard.learnSpell(fire); + tarGen.learnTargetType(target); + richard.forgetSpell(name); + tarGen.forgetTargetType(type); + std::cout << "have to be empy : "; + richard.launchSpell(name, *target); + if (tarGen.createTarget(type)) + std::cout << "is not..."; + std::cout << std::endl; + } + + std::cout << "\n-----------------\n"; + //https://github.com/Glagan/42-exam-rank-05/blob/master/cpp_module_02/main.cc + { + std::cout << "--- Constructors:\n"; + Warlock richard("Aang", "The Avatar"); + + std::cout << "--- Spells:\n"; + Polymorph *water = new Polymorph(); + Fireball *fire = new Fireball(); + Fwoosh *air = new Fwoosh(); + richard.learnSpell(water); + richard.learnSpell(fire); + richard.forgetSpell("Fwoosh"); + richard.learnSpell(air); + richard.forgetSpell("Fwoosh"); + richard.forgetSpell("Fwoosh"); + richard.learnSpell(air); + + std::cout << "--- Targets:\n"; + Dummy *hay = new Dummy(); + BrickWall *earth = new BrickWall(); + + TargetGenerator tarGen; + tarGen.learnTargetType(hay); + tarGen.learnTargetType(earth); + + std::cout << "--- Spells (all):\n"; + + richard.launchSpell("Fwoosh", *tarGen.createTarget("Dummy Practice")); + richard.launchSpell("Fireball", *tarGen.createTarget("BrickWall Practice")); + richard.launchSpell("Polymorph", *tarGen.createTarget("Dummy Practice")); + + std::cout << "--- Forgotten \"Fwoosh\":\n"; + + richard.forgetSpell("Fwoosh"); + richard.launchSpell("Fwoosh", *tarGen.createTarget("Dummy Practice")); + richard.launchSpell("Fireball", *tarGen.createTarget("BrickWall Practice")); + richard.launchSpell("Polymorph", *tarGen.createTarget("Dummy Practice")); + + std::cout << "--- Spells (all):\n"; + + richard.learnSpell(air); + richard.launchSpell("Fwoosh", *tarGen.createTarget("Dummy Practice")); + richard.launchSpell("Fireball", *tarGen.createTarget("BrickWall Practice")); + richard.launchSpell("Polymorph", *tarGen.createTarget("Dummy Practice")); + + std::cout << "--- Non-existant spell:\n"; + + richard.launchSpell("ACID", *tarGen.createTarget("BrickWall Practice")); + richard.forgetSpell("ACID"); + richard.launchSpell("ACID", *tarGen.createTarget("Dummy Practice")); + + std::cout << "--- Destructors:\n"; + return (0); + } + + std::cout << "\n-----------------\n"; + // https://github.com/Kromolux/42_exam_rank_05/blob/main/cpp_module_02/main.cpp + { + Warlock richard("Richard", "foo"); + richard.setTitle("Hello, I'm Richard the Warlock!"); + BrickWall model1; + BrickWall test1(model1); + + Polymorph* polymorph = new Polymorph(); + TargetGenerator tarGen; + + tarGen.learnTargetType(&test1); + richard.learnSpell(polymorph); + + Fireball* fireball = new Fireball(); + + richard.learnSpell(fireball); + + ATarget* wall = tarGen.createTarget("Inconspicuous Red-brick Wall"); + + richard.introduce(); + richard.launchSpell("Polymorph", *wall); + richard.launchSpell("Fireball", *wall); + delete wall; + delete fireball; + delete polymorph; + } } diff --git a/cpp_module_02/subject.en.txt b/cpp_module_02/subject.en.txt index 8ab660d..523278f 100644 --- a/cpp_module_02/subject.en.txt +++ b/cpp_module_02/subject.en.txt @@ -51,6 +51,7 @@ It will have the following functions: * ATarget* createTarget(string const &), that creates a target of the specified type +-------------------------------------------------------------------------------- Phew, that's done. Now here's a test main. It's not very thorough, so make sure to use your own aswell.