Ajouts et modifications

- lancerSimulation() créer l'univers et ajoute les organismes
- arreterSimulation() supprime l'univers
This commit is contained in:
Mylloon 2022-04-02 00:42:16 +02:00
parent 802cc75d1e
commit 02e7abd13d
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -1,7 +1,25 @@
#include "univers.hpp" #include "univers.hpp"
void lancerSimulation(int m, int n, int nb_moutons, int nb_loups) { void lancerSimulation(Univers * univers, int m, int n, int nb_moutons, int nb_loups) {
Univers univers(m, n); univers = new Univers(m, n);
std::vector<Organisme*> organismes;
while(nb_moutons > 0) {
organismes.push_back(new Mouton());
nb_moutons--;
}
while(nb_loups > 0) {
organismes.push_back(new Loup());
nb_loups--;
}
univers->ajoutOrganismes(organismes);
}
void arreterSimulation(Univers * univers) {
delete univers;
univers = nullptr;
} }
/* m x n = taille de l'univers /* m x n = taille de l'univers
@ -26,7 +44,15 @@ int main(int argc, char const *argv[]) {
nb_loups = 2; nb_loups = 2;
} }
lancerSimulation(m, n, nb_moutons, nb_loups); Univers * univers = nullptr;
try {
lancerSimulation(univers, m, n, nb_moutons, nb_loups);
arreterSimulation(univers);
} catch(const std::exception& e) {
std::cerr << e.what() << std::endl;
return 1;
}
return 0; return 0;
} }