From 51ccb97cf057c1bc3a81b93f78d8ca12b010d13d Mon Sep 17 00:00:00 2001 From: Mylloon Date: Fri, 1 Dec 2023 15:26:34 +0100 Subject: [PATCH] split classes into multiples files --- includes/Dames.hpp | 2 +- includes/Joueur.hpp | 1 - includes/Piece.hpp | 14 -------------- includes/PieceButin.hpp | 14 ++++++++++++++ includes/PieceDames.hpp | 12 ++++++++++++ includes/Plateau.hpp | 3 --- src/Dames.cpp | 11 ++++++----- src/PieceButin.cpp | 7 +++++++ src/PieceDames.cpp | 7 +++++++ src/Plateau.cpp | 4 ++-- src/main.cpp | 8 +++++++- 11 files changed, 56 insertions(+), 27 deletions(-) create mode 100644 includes/PieceButin.hpp create mode 100644 includes/PieceDames.hpp create mode 100644 src/PieceButin.cpp create mode 100644 src/PieceDames.cpp diff --git a/includes/Dames.hpp b/includes/Dames.hpp index b4b5bfc..7057690 100644 --- a/includes/Dames.hpp +++ b/includes/Dames.hpp @@ -21,7 +21,7 @@ public: Dames(Joueur &joueur1, Joueur &joueur2); // constructor virtual ~Dames(); // destructor - Dames(const Dames &d); // copy constructor + Dames(const Dames &); // copy constructor const Dames &operator=(const Dames &); // copy assignement // Fonction d'initialisation du jeu diff --git a/includes/Joueur.hpp b/includes/Joueur.hpp index df0fa4c..c5e7873 100644 --- a/includes/Joueur.hpp +++ b/includes/Joueur.hpp @@ -2,7 +2,6 @@ #define JOUEUR #include "../includes/Piece.hpp" -#include #include class Joueur { diff --git a/includes/Piece.hpp b/includes/Piece.hpp index 21a8c04..d0c7697 100644 --- a/includes/Piece.hpp +++ b/includes/Piece.hpp @@ -17,18 +17,4 @@ public: const Piece &operator=(const Piece &); // copy assignement }; -class PieceDames : public Piece { -public: - PieceDames(std::string categorie); - virtual ~PieceDames(); -}; - -class PieceButin : public Piece { - int points; - -public: - PieceButin(std::string categorie); - virtual ~PieceButin(); -}; - #endif diff --git a/includes/PieceButin.hpp b/includes/PieceButin.hpp new file mode 100644 index 0000000..6693cb4 --- /dev/null +++ b/includes/PieceButin.hpp @@ -0,0 +1,14 @@ +#ifndef PIECEEE +#define PIECEEE + +#include "Piece.hpp" + +class PieceButin : public Piece { + int points; + +public: + PieceButin(std::string categorie); + virtual ~PieceButin(); +}; + +#endif diff --git a/includes/PieceDames.hpp b/includes/PieceDames.hpp new file mode 100644 index 0000000..26a7053 --- /dev/null +++ b/includes/PieceDames.hpp @@ -0,0 +1,12 @@ +#ifndef PIECEE +#define PIECEE + +#include "Piece.hpp" + +class PieceDames : public Piece { +public: + PieceDames(std::string categorie); + virtual ~PieceDames(); +}; + +#endif diff --git a/includes/Plateau.hpp b/includes/Plateau.hpp index d67aae7..3a37532 100644 --- a/includes/Plateau.hpp +++ b/includes/Plateau.hpp @@ -2,8 +2,6 @@ #define PLATEAU #include "../includes/Joueur.hpp" -#include "../includes/Piece.hpp" -#include class Plateau { friend std::ostream &operator<<(std::ostream &, const Plateau &); @@ -15,7 +13,6 @@ class Plateau { Piece ***plateau; public: - Plateau(); Plateau(int taille); // constructor virtual ~Plateau(); // destructor diff --git a/src/Dames.cpp b/src/Dames.cpp index 15790f1..2ecbbad 100644 --- a/src/Dames.cpp +++ b/src/Dames.cpp @@ -1,16 +1,17 @@ #include "../includes/Dames.hpp" Dames::Dames(Joueur &j1, Joueur &j2) - : joueur1{j1}, joueur2{j2}, joueurCourant{j1} { - Plateau p(10); - this->plateau = p; + : plateau(Plateau(10)), joueur1{j1}, joueur2{j2}, joueurCourant{j1} { plateau.initialiserPlateau(j1, j2); } Dames::~Dames() {} -Dames::Dames(const Dames &d) - : joueur1{d.joueur1}, joueur2{d.joueur2}, joueurCourant{d.joueurCourant} {} +Dames::Dames(const Dames &src) + : plateau(Plateau(10)), joueur1{src.joueur1}, joueur2{src.joueur2}, + joueurCourant{src.joueurCourant} { + plateau.initialiserPlateau(joueur1, joueur2); +} const Dames &Dames::operator=(const Dames &src) { if (this == &src) { diff --git a/src/PieceButin.cpp b/src/PieceButin.cpp new file mode 100644 index 0000000..0cb829c --- /dev/null +++ b/src/PieceButin.cpp @@ -0,0 +1,7 @@ +#include "../includes/PieceButin.hpp" + +PieceButin::PieceButin(const std::string cat) : Piece(cat) { + std::cout << "pièce - " << cat << "\n"; +} + +PieceButin::~PieceButin() {} diff --git a/src/PieceDames.cpp b/src/PieceDames.cpp new file mode 100644 index 0000000..6522f0f --- /dev/null +++ b/src/PieceDames.cpp @@ -0,0 +1,7 @@ +#include "../includes/PieceDames.hpp" + +PieceDames::PieceDames(const std::string cat) : Piece(cat) { + std::cout << "pièce - " << cat << "\n"; +} + +PieceDames::~PieceDames() {} diff --git a/src/Plateau.cpp b/src/Plateau.cpp index 5995b5b..d658ea8 100644 --- a/src/Plateau.cpp +++ b/src/Plateau.cpp @@ -1,6 +1,5 @@ #include "../includes/Plateau.hpp" - -Plateau::Plateau() {} +#include "../includes/PieceDames.hpp" Plateau::Plateau(int t) { // Création du plateau vide @@ -39,6 +38,7 @@ void Plateau::initialiserPlateau(Joueur &j1, Joueur &j2) { } } } + for (int i = 6; i < 10; i++) { for (int j = 0; j < 10; j++) { if ((i % 2 == 0 && j % 2 == 1) || (i % 2 == 1 && j % 2 == 0)) { diff --git a/src/main.cpp b/src/main.cpp index d38ae81..f47c1bb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,2 +1,8 @@ +#include "../includes/Ecran.hpp" -int main() { return 0; } +int main() { + Ecran e; + e.afficher(); + + return 0; +}