diff --git a/includes/herbe.hpp b/includes/herbe.hpp index 6358895..784b743 100644 --- a/includes/herbe.hpp +++ b/includes/herbe.hpp @@ -4,10 +4,15 @@ #include "organisme.hpp" class Herbe: public Organisme { + const char _m_lettre = ' '; + public: // ID de l'univers, index dans l'univers Herbe(const int, const int); + // ID de l'univers + Herbe(const int); + // Renvoie faux bool animal(void) const noexcept; }; diff --git a/includes/loup.hpp b/includes/loup.hpp index cccee22..8f1d72f 100644 --- a/includes/loup.hpp +++ b/includes/loup.hpp @@ -4,6 +4,8 @@ #include "animal.hpp" class Loup: public Animal { + const char _m_lettre = 'L'; + int generationVitesse(void) const noexcept; public: diff --git a/includes/mouton.hpp b/includes/mouton.hpp index 15ef276..e812ed0 100644 --- a/includes/mouton.hpp +++ b/includes/mouton.hpp @@ -4,6 +4,8 @@ #include "animal.hpp" class Mouton: public Animal { + const char _m_lettre = 'M'; + int generationVitesse(void) const noexcept; public: diff --git a/includes/organisme.hpp b/includes/organisme.hpp index bfebc6b..7a051c8 100644 --- a/includes/organisme.hpp +++ b/includes/organisme.hpp @@ -23,6 +23,9 @@ class Organisme { // ID de l'Univers, index dans l'univers Organisme(const int, const int); + // ID de l'Univers (index aléatoire) + Organisme(const int); + virtual ~Organisme(void); // Renvoie la lettre correspondant à l'ID diff --git a/includes/sel.hpp b/includes/sel.hpp index 2183cfb..ba89695 100644 --- a/includes/sel.hpp +++ b/includes/sel.hpp @@ -4,10 +4,15 @@ #include "organisme.hpp" class Sel: public Organisme { + const char _m_lettre = '-'; + public: // ID de l'univers, index dans l'univers Sel(const int, const int); + // ID de l'univers + Sel(const int); + // Renvoie faux bool animal(void) const noexcept; }; diff --git a/src/animal.cpp b/src/animal.cpp index a3c7c9a..c8a4965 100644 --- a/src/animal.cpp +++ b/src/animal.cpp @@ -1,15 +1,15 @@ #include "../includes/animal.hpp" -Animal::Animal(const int univers_ID, const int age_max, const int age, const int vitesse): Organisme(univers_ID, recuperationIndexLibre(univers_ID)), // position aléatoire - m_vitesse(vitesse), // par des coordonées - m_age_max(age_max), // d'un index de - m_age(age) { } // indexLibres (listeUnivers[ID].first) - Animal::Animal(const int univers_ID, const int index, const int age_max, const int age, const int vitesse): Organisme(univers_ID, index), m_vitesse(vitesse), m_age_max(age_max), m_age(age) { } +Animal::Animal(const int univers_ID, const int age_max, const int age, const int vitesse): Organisme(univers_ID), + m_vitesse(vitesse), + m_age_max(age_max), + m_age(age) { } + Animal::~Animal(void) { } bool Animal::animal(void) const noexcept { diff --git a/src/herbe.cpp b/src/herbe.cpp index 33f2151..4c58324 100644 --- a/src/herbe.cpp +++ b/src/herbe.cpp @@ -1,7 +1,11 @@ #include "../includes/herbe.hpp" Herbe::Herbe(const int univers_ID, const int index): Organisme(univers_ID, index) { - m_correspondance[ID] = ' '; + m_correspondance[ID] = _m_lettre; +} + +Herbe::Herbe(const int univers_ID): Organisme(univers_ID) { + m_correspondance[ID] = _m_lettre; } bool Herbe::animal(void) const noexcept { diff --git a/src/loup.cpp b/src/loup.cpp index 7c0fd46..6451c6b 100644 --- a/src/loup.cpp +++ b/src/loup.cpp @@ -1,11 +1,11 @@ #include "../includes/loup.hpp" Loup::Loup(const int univers_ID): Animal(univers_ID, 60, 0, Loup::generationVitesse()) { - m_correspondance[ID] = 'L'; + m_correspondance[ID] = _m_lettre; } Loup::Loup(const int univers_ID, const int index): Animal(univers_ID, index, 60, 0, Loup::generationVitesse()) { - m_correspondance[ID] = 'L'; + m_correspondance[ID] = _m_lettre; } Loup::~Loup(void) { } diff --git a/src/mouton.cpp b/src/mouton.cpp index 5312a96..d51f0c3 100644 --- a/src/mouton.cpp +++ b/src/mouton.cpp @@ -1,11 +1,11 @@ #include "../includes/mouton.hpp" Mouton::Mouton(const int univers_ID): Animal(univers_ID, 50, 0, Mouton::generationVitesse()) { - m_correspondance[ID] = 'M'; + m_correspondance[ID] = _m_lettre; } Mouton::Mouton(const int univers_ID, const int index): Animal(univers_ID, index, 50, 0, Mouton::generationVitesse()) { - m_correspondance[ID] = 'M'; + m_correspondance[ID] = _m_lettre; } int Mouton::generationVitesse(void) const noexcept { diff --git a/src/organisme.cpp b/src/organisme.cpp index d9eb4d5..1602cf9 100644 --- a/src/organisme.cpp +++ b/src/organisme.cpp @@ -1,7 +1,7 @@ #include "../includes/univers.hpp" #include "../includes/organisme.hpp" -Organisme::Organisme(const int universID_p, const int index_p): m_univers_ID(universID_p), m_index(index_p), ID(m_total_ID + 1) { +Organisme::Organisme(const int univers_ID, const int index): m_univers_ID(univers_ID), m_index(index), ID(m_total_ID + 1) { if(Univers::m_liste_univers[m_univers_ID].first.size() == 0) { // si il n'y a plus d'index de libres throw std::domain_error("Trop d'organismes pour l'univers."); } @@ -9,6 +9,8 @@ Organisme::Organisme(const int universID_p, const int index_p): m_univers_ID(uni Univers::m_liste_univers[m_univers_ID].second.push_back(this); } +Organisme::Organisme(const int univers_ID): Organisme(univers_ID, recuperationIndexLibre(univers_ID)) {} + Organisme::~Organisme(void) { // TODO: rendre son ancienne position de nouveau disponible, re-shuffle après ajout ? } diff --git a/src/sel.cpp b/src/sel.cpp index d9161c2..67660c8 100644 --- a/src/sel.cpp +++ b/src/sel.cpp @@ -1,7 +1,11 @@ #include "../includes/sel.hpp" Sel::Sel(const int univers_ID, const int index): Organisme(univers_ID, index) { - m_correspondance[ID] = '-'; + m_correspondance[ID] = _m_lettre; +} + +Sel::Sel(const int univers_ID): Organisme(univers_ID) { + m_correspondance[ID] = _m_lettre; } bool Sel::animal(void) const noexcept { diff --git a/src/univers.cpp b/src/univers.cpp index 01862e7..8ef0e60 100644 --- a/src/univers.cpp +++ b/src/univers.cpp @@ -19,8 +19,7 @@ Univers::Univers(const int longueur, const int largeur): m_longueur(longueur), // Remplie quelques valeurs du tableau avec de l'herbe while(m_liste_univers[ID].first.size() > static_cast(m_taille_univers - m_taille_univers / 2)) { // cast static grâce à "-Wold-style-cast" et "-Wsign-conversion" (syntaxe C++) - new Herbe(ID, m_liste_univers[ID].first.back()); - m_liste_univers[ID].first.pop_back(); + new Herbe(ID); } // On stocke les dimensions pour chaque univers dans une map