This commit is contained in:
Mylloon 2023-12-13 12:01:59 +01:00
parent 3a23bff56d
commit 5d3cd65112
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
14 changed files with 86 additions and 67 deletions

View file

@ -1,7 +1,6 @@
#pragma once #pragma once
#include <iostream> #include <iostream>
#include <ctime>
#include "../includes/Joueur.hpp" #include "../includes/Joueur.hpp"
#include "../includes/Plateau.hpp" #include "../includes/Plateau.hpp"
@ -25,7 +24,8 @@ public:
const Dames &operator=(const Dames &); // copy assignement const Dames &operator=(const Dames &); // copy assignement
// Vérifie si une prise est possible pour une pièce donnée // Vérifie si une prise est possible pour une pièce donnée
//J'ai des erreurs depuis que j'ai voulu faire cette fonction et je comprends pas pourquoi // J'ai des erreurs depuis que j'ai voulu faire cette fonction et je comprends
// pas pourquoi
bool prisePossible(Piece *piece); bool prisePossible(Piece *piece);
// Fonction d'initialisation du jeu // Fonction d'initialisation du jeu

View file

@ -29,7 +29,7 @@ public:
const std::vector<Piece *> getPieces() const { return pieces; } const std::vector<Piece *> getPieces() const { return pieces; }
// Getter pour le nom du joueur // Getter pour le nom du joueur
const std::string& getNom() const { return nom; } const std::string &getNom() const { return nom; }
// Fonction qui supprime une pièce de la liste de pièces du joueur // Fonction qui supprime une pièce de la liste de pièces du joueur
}; };

View file

@ -5,6 +5,7 @@
class PieceDames : public Piece { class PieceDames : public Piece {
// True si la piece est une dame // True si la piece est une dame
bool dame; bool dame;
public: public:
PieceDames(std::string categorie); PieceDames(std::string categorie);
virtual ~PieceDames(); virtual ~PieceDames();

View file

@ -7,6 +7,7 @@ class Plateau {
// Taille du plateau // Taille du plateau
int taille; int taille;
protected: protected:
// Tableau représentant le plateau de jeu // Tableau représentant le plateau de jeu
Piece ***plateau; Piece ***plateau;

View file

@ -2,7 +2,6 @@
#include "Plateau.hpp" #include "Plateau.hpp"
class PlateauButin : public Plateau { class PlateauButin : public Plateau {
public: public:
PlateauButin(int taille); PlateauButin(int taille);

View file

@ -2,11 +2,8 @@
#include "Plateau.hpp" #include "Plateau.hpp"
class PlateauSafari : public Plateau { class PlateauSafari : public Plateau {
public: public:
PlateauSafari(int taille); PlateauSafari(int taille);
virtual ~PlateauSafari(); virtual ~PlateauSafari();
}; };

View file

@ -3,8 +3,8 @@
#include <iostream> #include <iostream>
#include "../includes/Joueur.hpp" #include "../includes/Joueur.hpp"
#include "../includes/PlateauSafari.hpp"
#include "../includes/PieceSafari.hpp" #include "../includes/PieceSafari.hpp"
#include "../includes/PlateauSafari.hpp"
class Safari { class Safari {
friend std::ostream &operator<<(std::ostream &, const Safari &); friend std::ostream &operator<<(std::ostream &, const Safari &);
@ -12,7 +12,7 @@ class Safari {
// Plateau de jeu // Plateau de jeu
PlateauSafari plateau; PlateauSafari plateau;
//Barrières // Barrières
std::vector<PieceSafari *> barrieres; std::vector<PieceSafari *> barrieres;
// Joueurs // Joueurs
@ -31,4 +31,3 @@ public:
// Fonction d'initialisation du jeu // Fonction d'initialisation du jeu
void choixAnimal(std::string animal); void choixAnimal(std::string animal);
}; };

View file

@ -1,7 +1,7 @@
#include "../includes/Butin.hpp" #include "../includes/Butin.hpp"
Butin::Butin(Joueur &j1, Joueur &j2) Butin::Butin(Joueur &j1, Joueur &j2)
: plateau(PlateauButin(8)), joueur1{j1}, joueur2{j2}, joueurCourant{j1}{ : plateau(PlateauButin(8)), joueur1{j1}, joueur2{j2}, joueurCourant{j1} {
plateau.initialiserPlateau(j1, j2); plateau.initialiserPlateau(j1, j2);
} }
@ -11,7 +11,7 @@ Butin::Butin(const Butin &src)
: plateau(PlateauButin(8)), joueur1{src.joueur1}, joueur2{src.joueur2}, : plateau(PlateauButin(8)), joueur1{src.joueur1}, joueur2{src.joueur2},
joueurCourant{src.joueurCourant} { joueurCourant{src.joueurCourant} {
plateau.initialiserPlateau(joueur1, joueur2); plateau.initialiserPlateau(joueur1, joueur2);
} }
const Butin &Butin::operator=(const Butin &src) { const Butin &Butin::operator=(const Butin &src) {
if (this == &src) { if (this == &src) {

View file

@ -1,16 +1,19 @@
#include "../includes/Dames.hpp" #include "../includes/Dames.hpp"
#include "Dames.hpp"
Dames::Dames(Joueur &j1, Joueur &j2) Dames::Dames(Joueur &j1, Joueur &j2)
: plateau(Plateau(10)), joueur1(j1), joueur2(j2), joueurCourant(j1) { : plateau(Plateau(10)), joueur1(j1), joueur2(j2), joueurCourant(j1) {
std::srand(static_cast<unsigned int>(std::time(0))); std::srand(static_cast<unsigned int>(time(0)));
int r = std::rand() % 2; int r = std::rand() % 2;
if(r==0){ if (r == 0) {
joueurCourant = j1; joueurCourant = j1;
std::cout << j1.getNom() << " jouera avec les pièces blanches et commencera la partie." << std::endl; std::cout << j1.getNom()
}else{ << " jouera avec les pièces blanches et commencera la partie."
<< std::endl;
} else {
joueurCourant = j2; joueurCourant = j2;
std::cout << j2.getNom() << " jouera avec les pièces blanches et commencera la partie." << std::endl; std::cout << j2.getNom()
<< " jouera avec les pièces blanches et commencera la partie."
<< std::endl;
} }
plateau.initialiserPlateau(j1, j2); plateau.initialiserPlateau(j1, j2);
} }
@ -31,10 +34,10 @@ const Dames &Dames::operator=(const Dames &src) {
return *this; return *this;
} }
//A continuer // A continuer
bool Dames::prisePossible(Piece *piece){ bool Dames::prisePossible(Piece *piece) {
if(!piece->dame) /* if (!piece->dame)
if() if () */
return false; return false;
} }

View file

@ -2,9 +2,15 @@
PieceButin::PieceButin(const std::string cat) : Piece(cat) { PieceButin::PieceButin(const std::string cat) : Piece(cat) {
std::cout << "pièce - " << cat << "\n"; std::cout << "pièce - " << cat << "\n";
if(cat=="jaune") this->points=1; if (cat == "jaune") {
if(cat=="rouge") this->points=2; this->points = 1;
if(cat=="noire") this->points=3; }
if (cat == "rouge") {
this->points = 2;
}
if (cat == "noire") {
this->points = 3;
}
} }
PieceButin::~PieceButin() {} PieceButin::~PieceButin() {}

View file

@ -8,24 +8,31 @@ PlateauButin::PlateauButin(int t) : Plateau(t) {}
PlateauButin::~PlateauButin() {} PlateauButin::~PlateauButin() {}
// On utilise pas les arguments ici, à voir si il faut vraiment faire un
// On utilise pas les arguments ici, à voir si il faut vraiment faire un override // override
void PlateauButin::initialiserPlateau(Joueur &j1, Joueur &j2){ void PlateauButin::initialiserPlateau(Joueur &j1, Joueur &j2) {
// Vecteur de toutes les pièeces du jeu // Vecteur de toutes les pièeces du jeu
std::vector<PieceButin> pieces; std::vector<PieceButin> pieces;
for(int i=0;i<34;i++) pieces.push_back(PieceButin("jaune")); for (int i = 0; i < 34; i++) {
for(int i=0;i<20;i++) pieces.push_back(PieceButin("rouge")); pieces.push_back(PieceButin("jaune"));
for(int i=0;i<10;i++) pieces.push_back(PieceButin("noire")); }
for (int i = 0; i < 20; i++) {
pieces.push_back(PieceButin("rouge"));
}
for (int i = 0; i < 10; i++) {
pieces.push_back(PieceButin("noire"));
}
// Mélange le vecteur de pièces (j'ai jamais utilisé ça pour randomiser faudra que je test que ça fonctionne bien) // Mélange le vecteur de pièces (j'ai jamais utilisé ça pour randomiser faudra
// que je test que ça fonctionne bien)
std::random_device rd; std::random_device rd;
std::mt19937 g(rd()); std::mt19937 g(rd());
std::shuffle(pieces.begin(), pieces.end(), g); std::shuffle(pieces.begin(), pieces.end(), g);
// Place toutes les pieces sur le plateau // Place toutes les pieces sur le plateau
int index=0; int index = 0;
for(int i=0;i<8;i++){ for (int i = 0; i < 8; i++) {
for(int j=0;j<8;j++){ for (int j = 0; j < 8; j++) {
plateau[i][j] = &pieces[index++]; plateau[i][j] = &pieces[index++];
} }
} }

View file

@ -1,19 +1,22 @@
#include "../includes/Safari.hpp" #include "../includes/Safari.hpp"
Safari::Safari(Joueur &j1, Joueur &j2, Joueur &j3) Safari::Safari(Joueur &j1, Joueur &j2, Joueur &j3)
: plateau(PlateauSafari(8)), joueur1{j1}, joueur2{j2}, joueur3{j3}, joueurCourant{j1}{ : plateau(PlateauSafari(8)), joueur1{j1}, joueur2{j2}, joueur3{j3},
for(int i=0;i<50;i++) joueurCourant{j1} {
for (int i = 0; i < 50; i++) {
barrieres.push_back(new PieceSafari("barriere")); barrieres.push_back(new PieceSafari("barriere"));
}
} }
Safari::~Safari() {} Safari::~Safari() {}
Safari::Safari(const Safari &src) Safari::Safari(const Safari &src)
: plateau(PlateauSafari(8)), joueur1{src.joueur1}, joueur2{src.joueur2}, joueur3{src.joueur3}, : plateau(PlateauSafari(8)), joueur1{src.joueur1}, joueur2{src.joueur2},
joueurCourant{src.joueurCourant} { joueur3{src.joueur3}, joueurCourant{src.joueurCourant} {
for(int i=0;i<50;i++) for (int i = 0; i < 50; i++) {
barrieres.push_back(new PieceSafari("barriere")); barrieres.push_back(new PieceSafari("barriere"));
} }
}
const Safari &Safari::operator=(const Safari &src) { const Safari &Safari::operator=(const Safari &src) {
if (this == &src) { if (this == &src) {
@ -23,10 +26,13 @@ const Safari &Safari::operator=(const Safari &src) {
return *this; return *this;
} }
void Safari::choixAnimal(std::string animal){ void Safari::choixAnimal(std::string animal) {
if(animal!="éléphant" || animal!="rhinocéros" || animal!="lion") if (animal != "éléphant" || animal != "rhinocéros" || animal != "lion") {
throw std::invalid_argument("Animal non valide"); throw std::invalid_argument("Animal non valide");
if(joueurCourant.getPieces().empty()) }
for(int i=0;i<3;i++) if (joueurCourant.getPieces().empty()) {
for (int i = 0; i < 3; i++) {
joueurCourant.ajoutPiece(new PieceSafari(animal)); joueurCourant.ajoutPiece(new PieceSafari(animal));
}
}
} }