Skip to content
Snippets Groups Projects
Commit 451538ec authored by Aymeric berthoumieu's avatar Aymeric berthoumieu
Browse files

allways get fearfull names when killing pets

parent 6d2ba590
No related branches found
No related tags found
1 merge request!20Aymeric
...@@ -17,9 +17,12 @@ Aquarium::Aquarium( int width, int height, int _delay, int startingNbOfAnimals, ...@@ -17,9 +17,12 @@ Aquarium::Aquarium( int width, int height, int _delay, int startingNbOfAnimals,
int screenHeight = 1024; //screen_height(); int screenHeight = 1024; //screen_height();
cout << "const Aquarium" << endl; cout << "const Aquarium" << endl;
string gregariousName = (GregariousBehaviour::getBehaviourInstance())->getBehaviourName();
string fearfulName = (FearfulBehaviour::getBehaviourInstance())->getBehaviourName();
string kamikazeName = (KamikazeBehaviour::getBehaviourInstance())->getBehaviourName();
// TODO : fixer la liste des availableCaptorsAndAccessories // TODO : fixer la liste des availableCaptorsAndAccessories
Statistics* statistics = new Statistics({Fin::getName(), Eyes::getName()}); Statistics* statistics = new Statistics({"b_multiple", gregariousName, fearfulName, kamikazeName, Fin::getName(), Eyes::getName()});
// TODO : fixer la liste des availableCaptorsAndAccessories // TODO : fixer la liste des availableCaptorsAndAccessories
AnimalFactory* factory = new PetFactory(width, height, animalsDistribution, {Fin::getName(), Eyes::getName()}, *statistics); AnimalFactory* factory = new PetFactory(width, height, animalsDistribution, {Fin::getName(), Eyes::getName()}, *statistics);
......
...@@ -8,8 +8,7 @@ ...@@ -8,8 +8,7 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
const std: string multiple = "b_multiple"; // name for multiple behaviour
string multiple = "b_multiple" // name for multiple behaviour
const T Environment::white[] = {(T) 255, (T) 255, (T) 255}; const T Environment::white[] = {(T) 255, (T) 255, (T) 255};
Environment::Environment(int _width, int _height, int nbAnimalsToStartWith, AnimalFactory& factory, Statistics& stats): Environment::Environment(int _width, int _height, int nbAnimalsToStartWith, AnimalFactory& factory, Statistics& stats):
...@@ -58,20 +57,15 @@ void Environment::step() { ...@@ -58,20 +57,15 @@ void Environment::step() {
this->die(); // delete the dead animals this->die(); // delete the dead animals
} }
void Environment::addMember(const Animal &a) { void Environment::addMember(Animal* a) {
// add an animal to the ecosystem // add an animal to the ecosystem
this->animals.push_back(a); this->animals.push_back(a);
this->animals.back().initCoords(width, height); this->animals.back()->initCoords(width, height);
} }
bool mustDie(Animal const &p) { bool mustDie(Animal * p) {
// return true if the p has a life < 0. It means p must die at the end of the step // return true if the p has a life < 0. It means p must die at the end of the step
return p.getLife() <= 0; return p->getLife() <= 0;
}
void Environment::addMember(Animal* a) {
this->animals.push_back(a);
this->animals.back()->initCoords(width, height);
} }
...@@ -89,23 +83,27 @@ void Environment::die() { ...@@ -89,23 +83,27 @@ void Environment::die() {
// kill animal in the ecosystem at the end of the step // kill animal in the ecosystem at the end of the step
// first we identify the animals to remove (if any) // first we identify the animals to remove (if any)
auto it = std::remove_if(animals.begin(), animals.end(), mustDie); std::vector<Animal*>::iterator it = std::remove_if(animals.begin(), animals.end(), mustDie);
// then we update Statistics // then we update Statistics
for (std::vector<Animal>::iterator iter = it; iter != animals.end(); ++iter) { for (std::vector<Animal*>::iterator iter = it; iter != animals.end(); ++iter) {
// All animal at the end of the vector at this step are going to die // All animal at the end of the vector at this step are going to die
// Behaviours // Behaviours
if (iter->getIsMultiple()) {
if ((*iter)->getIsMultiple()) {
cout << "In Environment::die(), isMultiple= " << (*iter)->getIsMultiple() << endl;
statistics.modifyData(multiple, false); statistics.modifyData(multiple, false);
} else { } else {
std::string behaviour = iter->getBehaviourName(); cout << "In Environment::die(), not multiple so = " << (*iter)->getBehaviourName() << endl;
std::string behaviour = (*iter)->getBehaviourName();
statistics.modifyData(behaviour, false); statistics.modifyData(behaviour, false);
} }
// Captors and accessories // Captors and accessories
std::vector <std::string> acc = iter->getAccessoriesAndCaptors(); // TODO
for (string element : acc) { /*std::vector <std::string> acc = (*iter)->getAccessoriesAndCaptors();
for (std::string element : acc) {
statistics.modifyData(element, false); statistics.modifyData(element, false);
} }*/
} }
// Finally, we delete the relevant animals // Finally, we delete the relevant animals
animals.erase(it, animals.end()); animals.erase(it, animals.end());
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include <limits> #include <limits>
std::string KamikazeBehaviour::NAME = "B_Kamikaze"; std::string KamikazeBehaviour::NAME = "b_Kamikaze";
std::string KamikazeBehaviour::getBehaviourName(){ std::string KamikazeBehaviour::getBehaviourName(){
......
...@@ -65,18 +65,18 @@ Animal* PetFactory::createMember(string behaviour) { ...@@ -65,18 +65,18 @@ Animal* PetFactory::createMember(string behaviour) {
// choosing and adding captors and accessories to the returned pet // choosing and adding captors and accessories to the returned pet
unordered_set<string> captorsAndAccessories = choose_elements(this->availableAccessoriesAndCaptors); unordered_set<string> captorsAndAccessories = choose_elements(this->availableAccessoriesAndCaptors);
for (string e : captorsAndAccessories) { for (string e : captorsAndAccessories) {
if (e == "fin") { if (e == "a_fin") {
pet = new Fin(*pet); pet = new Fin(*pet);
} }
else{ else{
if (e == "eyes") { if (e == "c_eyes") {
pet = new Eyes(*pet); pet = new Eyes(*pet);
} }
} }
} }
// adding the requested behaviour the returned pet // adding the requested behaviour the returned pet
if (behaviour == "multiple"){ if (behaviour == "b_multiple"){
pet->setBehaviourAsMultiple(); pet->setBehaviourAsMultiple();
} }
else{ else{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment