diff --git a/cpp_module_00/Warlock.hpp b/cpp_module_00/Warlock.hpp index c6e36a6..7bd80d5 100644 --- a/cpp_module_00/Warlock.hpp +++ b/cpp_module_00/Warlock.hpp @@ -14,20 +14,32 @@ 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() { + ~Warlock() + { std::cout << this->name << ": My job here is done!\n"; }; - std::string const & getName() const {return (this->name);}; - std::string const & getTitle() const {return (this->title);}; - void setTitle(std::string const & title) {this->title = title;}; + std::string const & getName() const + { + return (this->name); + }; + std::string const & getTitle() const + { + return (this->title); + }; + void setTitle(std::string const & title) + { + this->title = title; + }; - void introduce() const { + void introduce() const + { std::cout << this->name << ": I am " << this->name << ", " << this->title << "!\n"; }; }; diff --git a/cpp_module_00/a.out b/cpp_module_00/a.out index 7213813..e797334 100755 Binary files a/cpp_module_00/a.out and b/cpp_module_00/a.out differ diff --git a/cpp_module_00/test b/cpp_module_00/test deleted file mode 100755 index 7213813..0000000 Binary files a/cpp_module_00/test and /dev/null differ diff --git a/cpp_module_01/ASpell.cpp b/cpp_module_01/ASpell.cpp index 2cb07c0..8fb6110 100644 --- a/cpp_module_01/ASpell.cpp +++ b/cpp_module_01/ASpell.cpp @@ -1,5 +1,6 @@ #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_01/ASpell.hpp b/cpp_module_01/ASpell.hpp index be0a66c..e9c4705 100644 --- a/cpp_module_01/ASpell.hpp +++ b/cpp_module_01/ASpell.hpp @@ -7,34 +7,41 @@ class ATarget; class ASpell { + private: 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) { + ASpell(std::string const & name, std::string const & effects) + { this->name = name; this->effects = effects; }; - virtual ~ASpell() { - }; + virtual ~ASpell() + {}; - std::string const & getName() const { + std::string const & getName() const + { return (this->name); }; - std::string const & getEffects() const { + std::string const & getEffects() const + { return (this->effects); }; + void launch(ATarget const & atarget) const; virtual ASpell * clone() const = 0; @@ -43,3 +50,6 @@ class ASpell { #include "ATarget.hpp" #endif + + + diff --git a/cpp_module_01/ATarget.cpp b/cpp_module_01/ATarget.cpp index 3685615..61d5361 100644 --- a/cpp_module_01/ATarget.cpp +++ b/cpp_module_01/ATarget.cpp @@ -1,5 +1,6 @@ #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_01/ATarget.hpp b/cpp_module_01/ATarget.hpp index 86669a1..c74e741 100644 --- a/cpp_module_01/ATarget.hpp +++ b/cpp_module_01/ATarget.hpp @@ -7,26 +7,33 @@ class ASpell; class ATarget { - private: + private: std::string type; public: - ATarget() { - }; - ATarget(ATarget const & other) { + ATarget() + {}; + ATarget(ATarget const & other) + { *this = other; }; - ATarget & operator=(ATarget const & other) { + ATarget & operator=(ATarget const & other) + { this->type = other.type; return (*this); }; - ATarget(std::string const & type) { + ATarget(std::string const & type) + { this->type = type; }; - ~ATarget() {}; + ~ATarget() + {}; - std::string const & getType() const {return (this->type);}; + std::string const & getType() const + { + return (this->type); + }; void getHitBySpell(ASpell const & aspell) const; diff --git a/cpp_module_01/Dummy.hpp b/cpp_module_01/Dummy.hpp index 9d4167f..f9debbc 100644 --- a/cpp_module_01/Dummy.hpp +++ b/cpp_module_01/Dummy.hpp @@ -4,11 +4,15 @@ # include "ATarget.hpp" class Dummy: public ATarget { - public: - Dummy(): ATarget("Target Practice Dummy") {}; - ~Dummy() {}; - virtual ATarget * clone() const { + public: + Dummy(): ATarget("Target Practice Dummy") + {}; + ~Dummy() + {}; + + virtual ATarget * clone() const + { return (new Dummy()); }; }; diff --git a/cpp_module_01/Fwoosh.hpp b/cpp_module_01/Fwoosh.hpp index d49fbbc..046ad8f 100644 --- a/cpp_module_01/Fwoosh.hpp +++ b/cpp_module_01/Fwoosh.hpp @@ -4,11 +4,15 @@ # include "ASpell.hpp" class Fwoosh: public ASpell { - public: - Fwoosh(): ASpell("Fwoosh", "fwooshed") {}; - ~Fwoosh() {}; - virtual ASpell * clone() const { + public: + Fwoosh(): ASpell("Fwoosh", "fwooshed") + {}; + ~Fwoosh() + {}; + + virtual ASpell * clone() const + { return (new Fwoosh()); }; }; diff --git a/cpp_module_01/Warlock.hpp b/cpp_module_01/Warlock.hpp index a0324fd..d09d8f0 100644 --- a/cpp_module_01/Warlock.hpp +++ b/cpp_module_01/Warlock.hpp @@ -3,11 +3,13 @@ # include # include -# include "ASpell.hpp" -# include "ATarget.hpp" # include +# include "ASpell.hpp" +# include "ATarget.hpp" + class Warlock { + private: Warlock(); Warlock(Warlock const & other); @@ -18,12 +20,14 @@ class Warlock { std::map arr; 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() { + ~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(); @@ -34,30 +38,46 @@ class Warlock { this->arr.clear(); }; - std::string const & getName() const {return (this->name);}; - std::string const & getTitle() const {return (this->title);}; + std::string const & getName() const + { + return (this->name); + }; + std::string const & getTitle() const + { + return (this->title); + }; - void setTitle(std::string const & title) {this->title = title;}; + void setTitle(std::string const & title) + { + this->title = title; + }; - void introduce() const { + void introduce() const + { std::cout << this->name << ": I am " << this->name << ", " << this->title << "!\n"; }; - 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) { + void forgetSpell(std::string 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) { + void launchSpell(std::string name, ATarget const & target) + { ASpell * spell = arr[name]; if (spell) spell->launch(target); diff --git a/cpp_module_01/a.out b/cpp_module_01/a.out index 470ccac..8ad5690 100755 Binary files a/cpp_module_01/a.out and b/cpp_module_01/a.out differ diff --git a/cpp_module_01/testt b/cpp_module_01/testt deleted file mode 100755 index f634a06..0000000 Binary files a/cpp_module_01/testt and /dev/null differ