Ajouts et modifications
- lancerSimulation() créer l'univers et ajoute les organismes - arreterSimulation() supprime l'univers
This commit is contained in:
parent
802cc75d1e
commit
02e7abd13d
1 changed files with 29 additions and 3 deletions
32
main.cpp
32
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<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
|
||||
|
@ -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;
|
||||
}
|
||||
|
|
Reference in a new issue