resolved one error and one segfault in xpp02

This commit is contained in:
lenovo
2022-12-12 22:34:11 +01:00
parent fecde1a8b1
commit 5b19461090
33 changed files with 567 additions and 326 deletions

View File

@@ -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