2022-03-31 13:31:37 +02:00
|
|
|
#ifndef _UNIVERS_HPP_
|
|
|
|
#define _UNIVERS_HPP_ 1
|
|
|
|
|
2022-04-01 23:43:58 +02:00
|
|
|
#include <iostream>
|
|
|
|
#include <vector>
|
2022-04-02 13:08:26 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <random>
|
2022-04-01 23:43:58 +02:00
|
|
|
|
|
|
|
class Organisme;
|
2022-04-02 01:39:36 +02:00
|
|
|
class Animal;
|
2022-04-01 23:43:58 +02:00
|
|
|
|
2022-03-31 13:31:37 +02:00
|
|
|
class Univers {
|
2022-03-31 16:09:34 +02:00
|
|
|
friend class Organisme;
|
|
|
|
|
2022-04-02 13:08:26 +02:00
|
|
|
const int _m, _n, _tailleUnivers;
|
2022-04-02 01:39:36 +02:00
|
|
|
int _tour, _nbAnimaux;
|
2022-03-31 16:09:34 +02:00
|
|
|
int * _plateau;
|
2022-04-02 13:08:26 +02:00
|
|
|
std::vector<int> indexLibres;
|
2022-03-31 13:31:37 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
Univers(int, int);
|
2022-04-02 00:46:38 +02:00
|
|
|
~Univers(void);
|
2022-04-01 23:43:58 +02:00
|
|
|
|
2022-04-02 01:39:36 +02:00
|
|
|
// Ajoute des animaux à l'univers
|
|
|
|
void ajoutAnimaux(std::vector<Animal*>);
|
2022-04-02 00:46:38 +02:00
|
|
|
|
2022-04-02 16:03:20 +02:00
|
|
|
/* Modifie un organisme
|
2022-04-02 01:39:36 +02:00
|
|
|
* Attention, écrase l'organisme précédent */
|
2022-04-02 16:03:20 +02:00
|
|
|
void modificationOrganisme(Organisme *, int);
|
2022-04-02 01:39:36 +02:00
|
|
|
|
|
|
|
// Affiche l'univers à l'instant présent
|
2022-04-02 16:03:20 +02:00
|
|
|
void affichage(void) const noexcept;
|
2022-04-02 01:39:36 +02:00
|
|
|
|
|
|
|
// Vérifie s'il y a de la vie dans l'univers
|
|
|
|
bool enVie(void) const noexcept;
|
2022-03-31 13:31:37 +02:00
|
|
|
};
|
|
|
|
|
2022-03-31 16:09:34 +02:00
|
|
|
class Organisme {
|
|
|
|
public:
|
|
|
|
Organisme(void);
|
2022-04-02 00:46:38 +02:00
|
|
|
|
2022-04-02 01:39:36 +02:00
|
|
|
/* Renvoie l'ID de l'organisme
|
|
|
|
* Si `ID < 0` -> non vivant
|
|
|
|
* Si `ID > 0` -> vivant
|
|
|
|
* Si `ID == 0` -> Herbe */
|
2022-04-02 13:08:26 +02:00
|
|
|
virtual short id(void) const noexcept = 0;
|
2022-03-31 16:09:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class Animal: public Organisme {
|
|
|
|
public:
|
|
|
|
Animal(void);
|
2022-04-01 23:43:58 +02:00
|
|
|
|
2022-04-02 00:46:38 +02:00
|
|
|
// Animal carnivore ?
|
2022-04-02 01:39:36 +02:00
|
|
|
virtual bool carnivore(void) const noexcept = 0;
|
2022-03-31 16:09:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class Herbe: public Organisme {
|
|
|
|
public:
|
|
|
|
Herbe(void);
|
2022-04-02 00:46:38 +02:00
|
|
|
|
|
|
|
// Représenté par "0" dans l'univers
|
2022-04-02 13:08:26 +02:00
|
|
|
short id(void) const noexcept;
|
2022-03-31 16:09:34 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class Sel: public Organisme {
|
|
|
|
public:
|
|
|
|
Sel(void);
|
|
|
|
|
2022-04-02 01:48:38 +02:00
|
|
|
// Représenté par "-1" dans l'univers
|
2022-04-02 13:08:26 +02:00
|
|
|
short id(void) const noexcept;
|
2022-04-02 00:46:38 +02:00
|
|
|
};
|
2022-03-31 16:09:34 +02:00
|
|
|
|
|
|
|
class Mouton: public Animal {
|
|
|
|
public:
|
|
|
|
Mouton(void);
|
2022-04-01 23:43:58 +02:00
|
|
|
|
2022-04-02 01:39:36 +02:00
|
|
|
bool carnivore(void) const noexcept;
|
2022-04-02 00:46:38 +02:00
|
|
|
|
2022-04-02 01:48:38 +02:00
|
|
|
// Représenté par "1" dans l'univers
|
2022-04-02 13:08:26 +02:00
|
|
|
short id(void) const noexcept;
|
2022-03-31 16:09:34 +02:00
|
|
|
};
|
|
|
|
|
2022-04-02 00:46:38 +02:00
|
|
|
|
2022-04-01 23:43:58 +02:00
|
|
|
class Loup: public Animal {
|
2022-03-31 16:09:34 +02:00
|
|
|
public:
|
2022-04-01 23:43:58 +02:00
|
|
|
Loup(void);
|
|
|
|
|
2022-04-02 01:39:36 +02:00
|
|
|
bool carnivore(void) const noexcept;
|
2022-04-02 00:46:38 +02:00
|
|
|
|
2022-04-02 01:48:38 +02:00
|
|
|
// Représenté par "2" dans l'univers
|
2022-04-02 13:08:26 +02:00
|
|
|
short id(void) const noexcept;
|
2022-03-31 16:09:34 +02:00
|
|
|
};
|
|
|
|
|
2022-03-31 13:31:37 +02:00
|
|
|
#endif
|