From 02e7abd13d2d178d9a14d5c11e41943c5f94b886 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 2 Apr 2022 00:42:16 +0200 Subject: [PATCH] =?UTF-8?q?Ajouts=20et=20modifications=20-=20lancerSimulat?= =?UTF-8?q?ion()=20cr=C3=A9er=20l'univers=20et=20ajoute=20les=20organismes?= =?UTF-8?q?=20-=20arreterSimulation()=20supprime=20l'univers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index 3679c3d..f1d9e04 100644 --- a/main.cpp +++ b/main.cpp @@ -1,7 +1,25 @@ #include "univers.hpp" -void lancerSimulation(int m, int n, int nb_moutons, int nb_loups) { - Univers univers(m, n); +void lancerSimulation(Univers * univers, int m, int n, int nb_moutons, int nb_loups) { + univers = new Univers(m, n); + + std::vector 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 @@ -26,7 +44,15 @@ int main(int argc, char const *argv[]) { 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; }