From 895dd9e0832afb8a0623722592c622ac5bd3a288 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Sat, 2 Apr 2022 21:22:37 +0200 Subject: [PATCH] =?UTF-8?q?S=C3=A9paration=20des=20classes=20dans=20plusie?= =?UTF-8?q?urs=20fichiers?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/animal.hpp | 15 +++++++++ includes/herbe.hpp | 14 +++++++++ includes/loup.hpp | 17 ++++++++++ includes/mouton.hpp | 17 ++++++++++ includes/organisme.hpp | 22 +++++++++++++ includes/sel.hpp | 14 +++++++++ includes/univers.hpp | 69 ++-------------------------------------- src/animal.cpp | 5 +++ src/herbe.cpp | 9 ++++++ src/loup.cpp | 15 +++++++++ src/main.cpp | 2 ++ src/mouton.cpp | 15 +++++++++ src/organisme.cpp | 7 +++++ src/sel.cpp | 9 ++++++ src/univers.cpp | 71 +----------------------------------------- 15 files changed, 164 insertions(+), 137 deletions(-) create mode 100644 includes/animal.hpp create mode 100644 includes/herbe.hpp create mode 100644 includes/loup.hpp create mode 100644 includes/mouton.hpp create mode 100644 includes/organisme.hpp create mode 100644 includes/sel.hpp create mode 100644 src/animal.cpp create mode 100644 src/herbe.cpp create mode 100644 src/loup.cpp create mode 100644 src/mouton.cpp create mode 100644 src/organisme.cpp create mode 100644 src/sel.cpp diff --git a/includes/animal.hpp b/includes/animal.hpp new file mode 100644 index 0000000..bcfa225 --- /dev/null +++ b/includes/animal.hpp @@ -0,0 +1,15 @@ +#ifndef _ANIMAL_HPP_ +#define _ANIMAL_HPP_ 1 + +#include "organisme.hpp" + +class Animal: public Organisme { + public: + Animal(void); + virtual ~Animal(void); + + // Animal carnivore ? + virtual bool carnivore(void) const noexcept = 0; +}; + +#endif diff --git a/includes/herbe.hpp b/includes/herbe.hpp new file mode 100644 index 0000000..05c5ef5 --- /dev/null +++ b/includes/herbe.hpp @@ -0,0 +1,14 @@ +#ifndef _HERBE_HPP_ +#define _HERBE_HPP_ 1 + +#include "organisme.hpp" + +class Herbe: public Organisme { + public: + Herbe(void); + + // Représenté par "0" dans l'univers + short id(void) const noexcept; +}; + +#endif diff --git a/includes/loup.hpp b/includes/loup.hpp new file mode 100644 index 0000000..debe017 --- /dev/null +++ b/includes/loup.hpp @@ -0,0 +1,17 @@ +#ifndef _LOUP_HPP_ +#define _LOUP_HPP_ 1 + +#include "animal.hpp" + +class Loup: public Animal { + public: + Loup(void); + ~Loup(void); + + bool carnivore(void) const noexcept; + + // Représenté par "2" dans l'univers + short id(void) const noexcept; +}; + +#endif diff --git a/includes/mouton.hpp b/includes/mouton.hpp new file mode 100644 index 0000000..700d873 --- /dev/null +++ b/includes/mouton.hpp @@ -0,0 +1,17 @@ +#ifndef _MOUTON_HPP_ +#define _MOUTON_HPP_ 1 + +#include "animal.hpp" + +class Mouton: public Animal { + public: + Mouton(void); + ~Mouton(void); + + bool carnivore(void) const noexcept; + + // Représenté par "1" dans l'univers + short id(void) const noexcept; +}; + +#endif diff --git a/includes/organisme.hpp b/includes/organisme.hpp new file mode 100644 index 0000000..32d2ed6 --- /dev/null +++ b/includes/organisme.hpp @@ -0,0 +1,22 @@ +#ifndef _ORGANISME_HPP_ +#define _ORGANISME_HPP_ 1 + +#include + +class Organisme { + protected: + static inline std::map _correspondance; + + public: + Organisme(void); + + /* Renvoie l'ID de l'organisme + * Si `ID < 0` -> non vivant + * Si `ID > 0` -> vivant + * Si `ID == 0` -> Herbe */ + virtual short id(void) const noexcept = 0; + + static char correspondance(int); +}; + +#endif diff --git a/includes/sel.hpp b/includes/sel.hpp new file mode 100644 index 0000000..86ab804 --- /dev/null +++ b/includes/sel.hpp @@ -0,0 +1,14 @@ +#ifndef _SEL_HPP_ +#define _SEL_HPP_ 1 + +#include "organisme.hpp" + +class Sel: public Organisme { + public: + Sel(void); + + // Représenté par "-1" dans l'univers + short id(void) const noexcept; +}; + +#endif diff --git a/includes/univers.hpp b/includes/univers.hpp index a0bb0b7..301010f 100644 --- a/includes/univers.hpp +++ b/includes/univers.hpp @@ -5,10 +5,9 @@ #include #include #include -#include -class Organisme; -class Animal; +#include "animal.hpp" +#include "organisme.hpp" class Univers { friend class Organisme; @@ -36,68 +35,4 @@ class Univers { bool enVie(void) const noexcept; }; -class Organisme { - protected: - static inline std::map _correspondance; - - public: - Organisme(void); - - /* Renvoie l'ID de l'organisme - * Si `ID < 0` -> non vivant - * Si `ID > 0` -> vivant - * Si `ID == 0` -> Herbe */ - virtual short id(void) const noexcept = 0; - - static char correspondance(int); -}; - -class Animal: public Organisme { - public: - Animal(void); - virtual ~Animal(void); - - // Animal carnivore ? - virtual bool carnivore(void) const noexcept = 0; -}; - -class Herbe: public Organisme { - public: - Herbe(void); - - // Représenté par "0" dans l'univers - short id(void) const noexcept; -}; - -class Sel: public Organisme { - public: - Sel(void); - - // Représenté par "-1" dans l'univers - short id(void) const noexcept; -}; - -class Mouton: public Animal { - public: - Mouton(void); - ~Mouton(void); - - bool carnivore(void) const noexcept; - - // Représenté par "1" dans l'univers - short id(void) const noexcept; -}; - - -class Loup: public Animal { - public: - Loup(void); - ~Loup(void); - - bool carnivore(void) const noexcept; - - // Représenté par "2" dans l'univers - short id(void) const noexcept; -}; - #endif diff --git a/src/animal.cpp b/src/animal.cpp new file mode 100644 index 0000000..feb6755 --- /dev/null +++ b/src/animal.cpp @@ -0,0 +1,5 @@ +#include "../includes/animal.hpp" + +Animal::Animal(void): Organisme() { } + +Animal::~Animal(void) { } diff --git a/src/herbe.cpp b/src/herbe.cpp new file mode 100644 index 0000000..868aee1 --- /dev/null +++ b/src/herbe.cpp @@ -0,0 +1,9 @@ +#include "../includes/herbe.hpp" + +Herbe::Herbe(void): Organisme() { + _correspondance[id()] = ' '; +} + +short Herbe::id(void) const noexcept { + return 0; +} diff --git a/src/loup.cpp b/src/loup.cpp new file mode 100644 index 0000000..d5491c6 --- /dev/null +++ b/src/loup.cpp @@ -0,0 +1,15 @@ +#include "../includes/loup.hpp" + +Loup::Loup(void): Animal() { + _correspondance[id()] = 'L'; +} + +Loup::~Loup(void) { } + +bool Loup::carnivore(void) const noexcept { + return true; +} + +short Loup::id(void) const noexcept { + return 2; +} diff --git a/src/main.cpp b/src/main.cpp index 3ebe36b..85e4700 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,6 @@ #include "../includes/univers.hpp" +#include "../includes/mouton.hpp" +#include "../includes/loup.hpp" void lancerSimulation(Univers ** univers, int m, int n, int nb_moutons, int nb_loups) { *univers = new Univers(m, n); diff --git a/src/mouton.cpp b/src/mouton.cpp new file mode 100644 index 0000000..a302cfd --- /dev/null +++ b/src/mouton.cpp @@ -0,0 +1,15 @@ +#include "../includes/mouton.hpp" + +Mouton::Mouton(void): Animal() { + _correspondance[id()] = 'M'; +} + +Mouton::~Mouton(void) { } + +bool Mouton::carnivore(void) const noexcept { + return false; +} + +short Mouton::id(void) const noexcept { + return 1; +} diff --git a/src/organisme.cpp b/src/organisme.cpp new file mode 100644 index 0000000..326f358 --- /dev/null +++ b/src/organisme.cpp @@ -0,0 +1,7 @@ +#include "../includes/organisme.hpp" + +Organisme::Organisme(void) { } + +char Organisme::correspondance(int id) { + return _correspondance[id]; +} diff --git a/src/sel.cpp b/src/sel.cpp new file mode 100644 index 0000000..ee3ed88 --- /dev/null +++ b/src/sel.cpp @@ -0,0 +1,9 @@ +#include "../includes/sel.hpp" + +Sel::Sel(void): Organisme() { + _correspondance[id()] = 'S'; +} + +short Sel::id(void) const noexcept { + return -1; +} diff --git a/src/univers.cpp b/src/univers.cpp index 422c0bb..0a8fe7e 100644 --- a/src/univers.cpp +++ b/src/univers.cpp @@ -1,4 +1,5 @@ #include "../includes/univers.hpp" +#include "../includes/herbe.hpp" // -------- Univers -------- @@ -96,73 +97,3 @@ void Univers::affichage(void) const noexcept { bool Univers::enVie(void) const noexcept { return _nbAnimaux > 0; } - - -// -------- Organisme -------- - -Organisme::Organisme(void) { } - -char Organisme::correspondance(int id) { - return _correspondance[id]; -} - -// -------- Animal -------- - -Animal::Animal(void): Organisme() { } - -Animal::~Animal(void) { } - -// -------- Herbe -------- - -Herbe::Herbe(void): Organisme() { - _correspondance[id()] = ' '; -} - -short Herbe::id(void) const noexcept { - return 0; -} - - -// -------- Sel -------- - -Sel::Sel(void): Organisme() { - _correspondance[id()] = 'S'; -} - -short Sel::id(void) const noexcept { - return -1; -} - - -// -------- Mouton -------- - -Mouton::Mouton(void): Animal() { - _correspondance[id()] = 'M'; -} - -Mouton::~Mouton(void) { } - -bool Mouton::carnivore(void) const noexcept { - return false; -} - -short Mouton::id(void) const noexcept { - return 1; -} - - -// -------- Loup -------- - -Loup::Loup(void): Animal() { - _correspondance[id()] = 'L'; -} - -Loup::~Loup(void) { } - -bool Loup::carnivore(void) const noexcept { - return true; -} - -short Loup::id(void) const noexcept { - return 2; -}