resolved one error and one segfault in xpp02
This commit is contained in:
27
README.md
27
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
|
||||
@@ -1,10 +1,11 @@
|
||||
#ifndef WARLOCK_HPP
|
||||
# define WARLOCK_HPP
|
||||
#define WARLOCK_HPP
|
||||
|
||||
# include <iostream>
|
||||
# include <string>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
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
|
||||
|
||||
|
||||
Binary file not shown.
@@ -3,4 +3,5 @@
|
||||
void ASpell::launch(ATarget const & atarget) const
|
||||
{
|
||||
atarget.getHitBySpell(*this);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,55 +1,54 @@
|
||||
#ifndef ASPELL_HPP
|
||||
# define ASPELL_HPP
|
||||
#define ASPELL_HPP
|
||||
|
||||
# include <iostream>
|
||||
# include <string>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,4 +3,5 @@
|
||||
void ATarget::getHitBySpell(ASpell const & aspell) const
|
||||
{
|
||||
std::cout << this->type << " has been " << aspell.getEffects() << "!\n";
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,45 +1,47 @@
|
||||
#ifndef ATARGET_HPP
|
||||
# define ATARGET_HPP
|
||||
#define ATARGET_HPP
|
||||
|
||||
# include <iostream>
|
||||
# include <string>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
#include "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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
#ifndef WARLOCK_HPP
|
||||
# define WARLOCK_HPP
|
||||
#define WARLOCK_HPP
|
||||
|
||||
# include <iostream>
|
||||
# include <string>
|
||||
# include <map>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
# 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<std::string, ASpell *> arr;
|
||||
std::map<std::string, ASpell*> 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<std::string, ASpell *>::iterator it_begin = this->arr.begin();
|
||||
std::map<std::string, ASpell *>::iterator it_end = this->arr.end();
|
||||
while (it_begin != it_end) {
|
||||
delete it_begin->second;
|
||||
++it_begin;
|
||||
}
|
||||
|
||||
std::map<std::string, ASpell*>::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<std::string, ASpell *>
|
||||
arr.insert(std::pair<std::string, ASpell*>
|
||||
(
|
||||
aspell->getName(),
|
||||
aspell->clone()
|
||||
));
|
||||
}
|
||||
};
|
||||
void forgetSpell(std::string name)
|
||||
}
|
||||
void forgetSpell(std::string spell_name)
|
||||
{
|
||||
std::map<std::string, ASpell *>::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
|
||||
|
||||
|
||||
Binary file not shown.
@@ -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;
|
||||
}
|
||||
|
||||
BIN
cpp_module_01/test
Executable file
BIN
cpp_module_01/test
Executable file
Binary file not shown.
@@ -1,5 +1,7 @@
|
||||
#include "ASpell.hpp"
|
||||
|
||||
void ASpell::launch(ATarget const & atarget) const {
|
||||
void ASpell::launch(ATarget const & atarget) const
|
||||
{
|
||||
atarget.getHitBySpell(*this);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,45 +1,54 @@
|
||||
#ifndef ASPELL_HPP
|
||||
# define ASPELL_HPP
|
||||
#define ASPELL_HPP
|
||||
|
||||
# include <iostream>
|
||||
# include <string>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -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";
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,40 +1,47 @@
|
||||
#ifndef ATARGET_HPP
|
||||
# define ATARGET_HPP
|
||||
#define ATARGET_HPP
|
||||
|
||||
# include <iostream>
|
||||
# include <string>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
#include "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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
#include "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
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#include "Warlock.hpp"
|
||||
#include "SpellBook.hpp"
|
||||
|
||||
|
||||
@@ -1,50 +1,61 @@
|
||||
#ifndef SPELLBOOK_HPP
|
||||
#ifndef SPELLBOOK_HPP
|
||||
#define SPELLBOOK_HPP
|
||||
|
||||
# include <iostream>
|
||||
# include <string>
|
||||
# include "ASpell.hpp"
|
||||
# include <map>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
class SpellBook {
|
||||
#include "ASpell.hpp"
|
||||
|
||||
class SpellBook
|
||||
{
|
||||
private:
|
||||
SpellBook(SpellBook const & other);
|
||||
SpellBook & operator=(SpellBook const & other);
|
||||
|
||||
std::map<std::string, ASpell *> arr;
|
||||
std::map<std::string, ASpell*> arr;
|
||||
|
||||
public:
|
||||
SpellBook() {};
|
||||
~SpellBook() {
|
||||
std::map<std::string, ASpell *>::iterator it_begin = this->arr.begin();
|
||||
std::map<std::string, ASpell *>::iterator it_end = this->arr.end();
|
||||
while (it_begin != it_end) {
|
||||
delete it_begin->second;
|
||||
++it_begin;
|
||||
}
|
||||
SpellBook()
|
||||
{}
|
||||
~SpellBook()
|
||||
{
|
||||
std::map<std::string, ASpell*>::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<std::string, ASpell *>(
|
||||
{
|
||||
arr.insert(std::pair<std::string, ASpell*>
|
||||
(
|
||||
aspell->getName(),
|
||||
aspell->clone()
|
||||
));
|
||||
};
|
||||
void forgetSpell(std::string & name) {
|
||||
std::map<std::string, ASpell *>::iterator it = arr.find(name);
|
||||
if (it == arr.end())
|
||||
return;
|
||||
delete it->second;
|
||||
arr.erase(name);
|
||||
};
|
||||
ASpell * createSpell(std::string & name) {
|
||||
std::map<std::string, ASpell *>::iterator it = arr.find(name);
|
||||
if (it == arr.end())
|
||||
return NULL;
|
||||
return arr[name];
|
||||
};
|
||||
}
|
||||
}
|
||||
void forgetSpell(std::string const & spell_name)
|
||||
{
|
||||
std::map<std::string, ASpell*>::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<std::string, ASpell*>::iterator it;
|
||||
it = arr.find(spell_name);
|
||||
if (it != arr.end())
|
||||
return arr[spell_name];
|
||||
return NULL;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,50 +1,65 @@
|
||||
#ifndef TARGETGENERATOR_HPP
|
||||
#ifndef TARGETGENERATOR_HPP
|
||||
#define TARGETGENERATOR_HPP
|
||||
|
||||
# include <iostream>
|
||||
# include <string>
|
||||
# include "ATarget.hpp"
|
||||
# include <map>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
class TargetGenerator {
|
||||
#include "ATarget.hpp"
|
||||
|
||||
class TargetGenerator
|
||||
{
|
||||
private:
|
||||
TargetGenerator(TargetGenerator const & other);
|
||||
TargetGenerator & operator=(TargetGenerator const & other);
|
||||
|
||||
std::map<std::string, ATarget *> arr;
|
||||
std::map<std::string, ATarget*> arr;
|
||||
|
||||
public:
|
||||
TargetGenerator() {
|
||||
};
|
||||
~TargetGenerator() {
|
||||
std::map<std::string, ATarget *>::iterator it_begin = this->arr.begin();
|
||||
std::map<std::string, ATarget *>::iterator it_end = this->arr.end();
|
||||
while (it_begin != it_end) {
|
||||
delete it_begin->second;
|
||||
++it_begin;
|
||||
}
|
||||
TargetGenerator()
|
||||
{}
|
||||
~TargetGenerator()
|
||||
{
|
||||
std::map<std::string, ATarget*>::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<std::string, ATarget *>(
|
||||
{
|
||||
arr.insert(std::pair<std::string, ATarget*>
|
||||
(
|
||||
atarget->getType(),
|
||||
atarget->clone()
|
||||
));
|
||||
};
|
||||
void forgetTargetType(std::string const & name) {
|
||||
std::map<std::string, ATarget *>::iterator it = arr.find(name);
|
||||
}
|
||||
}
|
||||
void forgetTargetType(std::string const & type)
|
||||
{
|
||||
std::map<std::string, ATarget*>::iterator it;
|
||||
it = arr.find(type);
|
||||
if (it != arr.end())
|
||||
{
|
||||
delete it->second;
|
||||
arr.erase(name);
|
||||
};
|
||||
ATarget * createTarget(std::string const & name) {
|
||||
std::map<std::string, ATarget *>::iterator it = arr.find(name);
|
||||
arr.erase(type);
|
||||
}
|
||||
}
|
||||
|
||||
ATarget * createTarget(std::string const & type)
|
||||
{
|
||||
std::map<std::string, ATarget*>::iterator it;
|
||||
it = arr.find(type);
|
||||
if (it != arr.end())
|
||||
return arr[name];
|
||||
return arr[type]->clone();
|
||||
return NULL;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
#include "SpellBook.hpp"
|
||||
#include "Warlock.hpp"
|
||||
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
#ifndef WARLOCK_HPP
|
||||
# define WARLOCK_HPP
|
||||
#define WARLOCK_HPP
|
||||
|
||||
# include <iostream>
|
||||
# include <string>
|
||||
# include "ASpell.hpp"
|
||||
# include "ATarget.hpp"
|
||||
# include "SpellBook.hpp"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
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
|
||||
|
||||
|
||||
Binary file not shown.
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user