resolved one error and one segfault in xpp02
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user