#include "ASpell.hpp" ASpell::ASpell() { } ASpell::ASpell(std::string const &name, std::string const &effects) : _name(name), _effects(effects) { } ASpell::ASpell(ASpell const &other) { *this = other; } ASpell &ASpell::operator=(ASpell const &other) { this->_name = other._name; this->_effects = other._effects; return *this; } ASpell::~ASpell() { } std::string const &ASpell::getName() const { return this->_name; } std::string const &ASpell::getEffects() const { return this->_effects; } void ASpell::launch(ATarget const &atargetref) const { atargetref.getHitBySpell(*this); } #pragma once #include class ATarget; class ASpell { private: std::string _name; std::string _effects; public: ASpell(); ASpell(std::string const &name, std::string const &effects); ASpell(ASpell const &other); ASpell &operator=(ASpell const &other); virtual ~ASpell(); std::string const &getName() const; std::string const &getEffects() const; virtual ASpell *clone() const = 0; void launch(ATarget const &atargetref) const; }; #include "ATarget.hpp"#include "ATarget.hpp" ATarget::ATarget() { } ATarget::ATarget(std::string const &type) : _type(type){ } ATarget::ATarget(ATarget const &other) { *this = other; } ATarget &ATarget::operator=(ATarget const &other) { this->_type = other._type; return *this; } ATarget::~ATarget() { } std::string const &ATarget::getType() const { return this->_type; } void ATarget::getHitBySpell(ASpell const &aspellref) const { std::cout << _type << " has been " << aspellref.getEffects() << "!\n"; } #pragma once #include class ASpell; class ATarget { private: std::string _type; public: ATarget(); ATarget(std::string const &type); ATarget(ATarget const &other); ATarget &operator=(ATarget const &other); virtual ~ATarget(); std::string const &getType() const; virtual ATarget *clone() const = 0; void getHitBySpell(ASpell const &aspellref) const; }; #include "ASpell.hpp"#include "Dummy.hpp" Dummy::Dummy() : ATarget("Target Practice Dummy") { } Dummy::~Dummy() { } ATarget *Dummy::clone() const { return (new Dummy()); } #pragma once #include "ATarget.hpp" class Dummy : public ATarget { public: Dummy(); ~Dummy(); ATarget *clone() const; }; #include "Fwoosh.hpp" Fwoosh::Fwoosh() : ASpell("Fwoosh", "fwooshed") { } Fwoosh::~Fwoosh() { } ASpell *Fwoosh::clone() const { return (new Fwoosh()); } #pragma once #include "ASpell.hpp" class Fwoosh : public ASpell { public: Fwoosh(); ~Fwoosh(); ASpell *clone() const; }; #include "Warlock.hpp" Warlock::Warlock(std::string const &name, std::string const &title) : _name(name), _title(title) { std::cout << _name << ": This looks like another boring day.\n"; } Warlock::~Warlock() { std::cout << _name << ": My job here is done!\n"; std::map::iterator itb = arr.begin(); std::map::iterator ite = arr.end(); while (itb != ite) { delete itb->second; ++itb; } arr.clear(); } std::string const &Warlock::getName() const { return this->_name; } std::string const &Warlock::getTitle() const { return this->_title; } void Warlock::setTitle(std::string const &title) { this->_title = title; } void Warlock::introduce() const { std::cout << _name << ": I am " << _name << ", " << _title << "!\n"; } void Warlock::learnSpell(ASpell *aspellptr) { if (aspellptr) arr.insert(std::pair(aspellptr->getName(), aspellptr->clone())); } void Warlock::forgetSpell(std::string spellname) { std::map::iterator itf = arr.find(spellname); if (itf != arr.end()) delete itf->second; arr.erase(spellname); } void Warlock::launchSpell(std::string spellname, ATarget const &atargetref) { ASpell *spell = arr[spellname]; if (spell) spell->launch(atargetref); } #pragma once #include #include "ASpell.hpp" #include "ATarget.hpp" #include class Warlock { private: std::string _name; std::string _title; Warlock(); Warlock(Warlock const &other); Warlock &operator=(Warlock const &other); std::map arr; public: Warlock(std::string const &name, std::string const &title); ~Warlock(); std::string const &getName() const; std::string const &getTitle() const; void setTitle(std::string const &title); void introduce() const; void learnSpell(ASpell *aspellptr); void forgetSpell(std::string spellname); void launchSpell(std::string spellname, ATarget const &atargetref); };