diff --git a/include/Jeu.h b/include/Jeu.h new file mode 100644 index 0000000..e7844dc --- /dev/null +++ b/include/Jeu.h @@ -0,0 +1,34 @@ +#ifndef JEU_H +#define JEU_H +#include +#include +#include +#include "Joueur.h" +#include "PiocheDeCartes.h" +#include "PiocheDeTortues.h" +#include "PlateauDeJeu.h" +using namespace std; + + +class Jeu +{ + public: + Jeu(); + void jouer(); + void recommencer(); + void manche(); + bool aTroisFeuillesDeSalade(); + int indexJoueurLePlusJeune(); + virtual ~Jeu(); + protected: + + private: + int nombreJoueurs; + vector tabJoueurs; + PiocheDeCartes* piocheDeCartes; + PiocheDeTortues* listeTortues; + PiocheDeTortues* tuiles; + PlateauDeJeu* plateauDeJeu; +}; + +#endif // JEU_H diff --git a/include/Joueur.h b/include/Joueur.h index 7994ade..f061120 100644 --- a/include/Joueur.h +++ b/include/Joueur.h @@ -1,16 +1,26 @@ #ifndef JOUEUR_H #define JOUEUR_H #include +#include "Carte.h" +#include "PiocheDeCartes.h" +#include "PiocheDeTortues.h" using namespace std; class Joueur { public: Joueur(); - Joueur(std::string nom, int age); virtual ~Joueur(); int getAge(); - void setNom(std::string nom); + void debutDeManche(PiocheDeCartes* piocheDeCartes, PiocheDeTortues* tuiles); + void finDeManche(); + Tortue* getTortueJoueur(); + void setTortueJoueur(Tortue* uneTortue); + Carte* getIndiceMainJoueur(int i); + void renouvelerCarte(PiocheDeCartes* piocheDeCartes, Carte* carteJouee); std::string getNom(); + void ajoutFeuilleDeSalade(); + int getNbFeuillesDeSalade(); + Carte* choixCarteJouee(); affichage_joueur(); protected: diff --git a/include/PiocheDeCartes.h b/include/PiocheDeCartes.h index 77d3fcd..cda3933 100644 --- a/include/PiocheDeCartes.h +++ b/include/PiocheDeCartes.h @@ -8,10 +8,10 @@ class PiocheDeCartes public: PiocheDeCartes(); virtual ~PiocheDeCartes(); - Carte* piocher(); + Carte* piocher_carte(); + void afficherPaquet(); protected: vector tas; - int nb_cartes_restantes; private: }; diff --git a/include/PiocheDeTortues.h b/include/PiocheDeTortues.h index 7aabfc0..afd392c 100644 --- a/include/PiocheDeTortues.h +++ b/include/PiocheDeTortues.h @@ -1,16 +1,22 @@ #ifndef PIOCHEDETORTUES_H #define PIOCHEDETORTUES_H +#include +#include "Tortue.h" +using namespace std; class PiocheDeTortues { public: PiocheDeTortues(); + void afficherPiocheDeTortues(); + Tortue* piocherTortue(); virtual ~PiocheDeTortues(); protected: private: + vector liste_tortues; }; #endif // PIOCHEDETORTUES_H diff --git a/include/PlateauDeJeu.h b/include/PlateauDeJeu.h new file mode 100644 index 0000000..762dfaf --- /dev/null +++ b/include/PlateauDeJeu.h @@ -0,0 +1,26 @@ +#ifndef PLATEAUDEJEU_H +#define PLATEAUDEJEU_H +#include +#include +#include "Tortue.h" +#include "PiocheDeTortues.h" +#include "Carte.h" +#include "constantes.h" + +class PlateauDeJeu +{ + public: + PlateauDeJeu(PiocheDeTortues* tortuesAuDepart); + void affichagePlateau(); + void actionCarte(Carte* carteJouee); + bool uneTortueEstArrivee(); + int* getOrdreArriveeTortue(); + virtual ~PlateauDeJeu(); + + protected: + Tortue* plateau[NB_POSITIONS][NB_TORTUES]; + + private: +}; + +#endif // PLATEAUDEJEU_H diff --git a/include/constantes.h b/include/constantes.h index e97a0ab..81fe771 100644 --- a/include/constantes.h +++ b/include/constantes.h @@ -1,6 +1,5 @@ #ifndef CONSTANTES_H -#define CONSTANTES_H - +#define CONSTANTES_H 1 #include using namespace std; /* @@ -24,7 +23,7 @@ using namespace std; #define C_JAUNE 4 #define C_VERT 5 -int TAB_COULEUR[5] = {C_ROUGE, C_BLEU, C_VIOLET, C_JAUNE, C_VERT}; +const int TAB_COULEUR[5] = {C_ROUGE, C_BLEU, C_VIOLET, C_JAUNE, C_VERT}; #define TAILLE_TAB_COULEUR 5 @@ -40,11 +39,15 @@ int TAB_COULEUR[5] = {C_ROUGE, C_BLEU, C_VIOLET, C_JAUNE, C_VERT}; #define T_PLUS1_DERNIERE 7 #define T_PLUS2_DERNIERE 8 -string AFFICHAGE_PLUS1 = "+"; -string AFFICHAGE_PLUS2 = "+ +"; -string AFFICHAGE_MOINS1 = "-"; -string AFFICHAGE_PLUS1_DERNIERE = ">"; -string AFFICHAGE_PLUS2_DERNIERE = "> >"; +const string AFFICHAGE_PLUS1 = "+"; +const string AFFICHAGE_PLUS2 = "++"; +const string AFFICHAGE_MOINS1 = "-"; +const string AFFICHAGE_PLUS1_DERNIERE = ">"; +const string AFFICHAGE_PLUS2_DERNIERE = ">>"; + +const string AFFICHAGE_VIDE = " " ; +const string AFFICHAGE_TORTUE = " T "; +const string AFFICHAGE_BASE = " >>>"; /* * WINDOWS diff --git a/include/utils.h b/include/utils.h new file mode 100644 index 0000000..9835b9f --- /dev/null +++ b/include/utils.h @@ -0,0 +1,10 @@ +#ifndef UTILS_H_INCLUDED +#define UTILS_H_INCLUDED +#include +#include +using namespace std; + + void printf_en_couleur(string texte, int couleur); + FARPROC getConsoleFunction(char *name); + +#endif // UTILS_H_INCLUDED diff --git a/main.cpp b/main.cpp deleted file mode 100644 index edbc4fc..0000000 --- a/main.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include -#include "Carte.h" -#include "Tortue.h" -#include "Joueur.h" -using namespace std; - -int main() -{ - Carte* uneCarte; - uneCarte = new Carte(); - Carte* uneAutre = new Carte(); - uneCarte->setCouleur(5); - uneCarte->afficher(); - uneAutre->setType(2); - uneAutre->afficher(); - Joueur* unJoueur; - unJoueur = new Joueur(); - Tortue* uneTortue; - uneTortue = new Tortue(3); - uneTortue->affichageTortue(); - return 0; -} diff --git a/src/Carte.cpp b/src/Carte.cpp index a0c9c64..3385e7b 100644 --- a/src/Carte.cpp +++ b/src/Carte.cpp @@ -1,31 +1,24 @@ #include #include "Carte.h" #include "constantes.h" +#include "../include/utils.h" using namespace std; -Carte::Carte() -{ - cout << "Création d'une nouvelle carte !" << endl; - this->couleur = 0; - this->type = 0; -} - Carte::Carte(int couleur, int type) { - this->setCouleur(couleur); - this->setType(type); + if(couleur < 0 || couleur > 5){ + exit(EXIT_FAILURE); + } + this->couleur = couleur; + this->type = type; } - - Carte::~Carte() { //dtor } - - string Carte::representation_type_carte(int type_carte) { switch (type_carte) @@ -46,34 +39,19 @@ string Carte::representation_type_carte(int type_carte) return ""; } void Carte::afficher(){ - cout<<"Représentation de la carte :"<representation_type_carte(this->type)<representation_type_carte(this->getType()), this->getCouleur()); + cout << endl; } -void Carte::setType(int type) { - this->type=type; -} int Carte::getType(){ return this->type; } - - -void Carte::setCouleur(int couleur){ - if(couleur<5){ - this->couleur=couleur; - } - else{ - this->couleur=0; - } -} - - - int Carte::getCouleur(){ - cout<<"acces a la variablle couleur de l'objet "<couleur; } -int deplacement_type_carte (int type_carte) + +int Carte::deplacement_type_carte(int type_carte) { return type_carte % 3; } diff --git a/src/Jeu.cpp b/src/Jeu.cpp new file mode 100644 index 0000000..6dd9483 --- /dev/null +++ b/src/Jeu.cpp @@ -0,0 +1,151 @@ +#include +#include +#include +#include "Jeu.h" +#include "Joueur.h" +#include "PiocheDeCartes.h" +#include "PiocheDeTortues.h" +#include "PlateauDeJeu.h" +#include "../include/utils.h" +#include "../include/constantes.h" +using namespace std; + +Jeu::Jeu() +{ + // init joueurs + // pour chaque manche + // init pioche + // init plateau de jeu + // choix tortue par chaque joueur + // remplacement main joueur + // ... déroulement manche + // free pioche + // free plateau de jeu + //puis: + // free joueurs + + int nbJoueurs = 0; + do + { + cout << "Combien y a-t-il de joueurs ?" << endl <<"(Entrez une valeur comprise entre 1 et " << NB_MAX_JOUEURS << ") "; + cin >> nbJoueurs; + } + while (nbJoueurs > NB_MAX_JOUEURS || nbJoueurs <= 0); + this->nombreJoueurs = nbJoueurs; + for (int indexJoueur = 0; indexJoueur < nbJoueurs; indexJoueur++) + { + Joueur* unJoueur; + unJoueur = new Joueur(); + this->tabJoueurs.push_back(unJoueur); + } +} + +void Jeu::jouer() +{ + do + { + this->piocheDeCartes = new PiocheDeCartes(); + this->listeTortues = new PiocheDeTortues(); + this->tuiles = new PiocheDeTortues(); + this->plateauDeJeu = new PlateauDeJeu(this->listeTortues); + for (int j = 0; j < this->nombreJoueurs; j++) + { + this->tabJoueurs[j]->debutDeManche(this->piocheDeCartes, this->tuiles); + } + + this->manche(); + + for (int j = 0; j < this->nombreJoueurs; j++) + { + this->tabJoueurs[j]->finDeManche(); + } + this->piocheDeCartes->~PiocheDeCartes(); + this->listeTortues->~PiocheDeTortues(); + this->tuiles->~PiocheDeTortues(); + this->plateauDeJeu->~PlateauDeJeu(); + } + while (!this->aTroisFeuillesDeSalade()); + Joueur* joueurVainqueur; + for (int j = 0; j < this->nombreJoueurs; j++) + { + if (this->tabJoueurs[j]->getNbFeuillesDeSalade() == NB_MAX_FEUILLES_SALADE) + { + joueurVainqueur = this->tabJoueurs[j]; + break; + } + } + cout << "Le/La Joueur(euse) " << joueurVainqueur->getNom() << "a gagné la partie ! Félicitations ! " << endl << "Merci d'avoir joué ! "; +} + +bool Jeu::aTroisFeuillesDeSalade() +{ + for (int i = 0; i < this->nombreJoueurs; i++ ) + { + if (this->tabJoueurs[i]->getNbFeuillesDeSalade() == NB_MAX_FEUILLES_SALADE) + { + return true; + } + } +} +void Jeu::manche() +{ + int joueurEnCours = this->indexJoueurLePlusJeune(); + cout << endl; + do + { + this->plateauDeJeu->affichagePlateau(); + Carte* carteJouee; + carteJouee = this->tabJoueurs[joueurEnCours]->choixCarteJouee(); + this->plateauDeJeu->actionCarte(carteJouee); + this->plateauDeJeu->affichagePlateau(); + this->tabJoueurs[joueurEnCours]->renouvelerCarte(this->piocheDeCartes, carteJouee); + carteJouee->~Carte(); + //this->piocheDeCartes->afficherPaquet(); + joueurEnCours = (joueurEnCours + 1)% this->nombreJoueurs; + } + while (! (this->plateauDeJeu->uneTortueEstArrivee())); + int* tabOrdreCouleursTortues = this->plateauDeJeu->getOrdreArriveeTortue(); + for (int o = 0; o < NB_TORTUES; o++) + { + for (int i = 0; i < this->nombreJoueurs; i++) + { + if (this->tabJoueurs[i]->getTortueJoueur()->Getcouleur() == tabOrdreCouleursTortues[o]) + { + this->tabJoueurs[i]->ajoutFeuilleDeSalade(); + cout << "Le Joueur " << this->tabJoueurs[i]->getNom() << " (" << this->tabJoueurs[i]->getAge() << " ans) a gagné la manche et a remporté une feuille de salade." << endl << "Il a maintenant " << this->tabJoueurs[i]->getNbFeuillesDeSalade() << " feuille(s)." << endl << "Il avait la tortue "; + this->tabJoueurs[i]->getTortueJoueur()->affichageTortue(); + cout << "." << endl; + goto finDeRecherche; //break n'aurait permis de ne sortir que d'un seul for + } + } + } + finDeRecherche: + if (!this->aTroisFeuillesDeSalade()) + { + cout << "Appuyez sur une touche (sauf ENTREE) puis appuyez ensuite sur ENTREE pour passer à la manche suivante" << endl; + char reponse; + cin >> reponse; + } +} + +int Jeu::indexJoueurLePlusJeune() +{ + int plusJeuneAge = -1; + int indexPlusJeuneAge = -1; + int ageJoueurEnCours; + for (int i = 0; i < this->nombreJoueurs; i++) + { + ageJoueurEnCours = this->tabJoueurs[i]->getAge(); + if (plusJeuneAge < 0 || ageJoueurEnCours < plusJeuneAge) + { + plusJeuneAge = ageJoueurEnCours; + indexPlusJeuneAge = i; + } + } + return indexPlusJeuneAge; +} + +Jeu::~Jeu() +{ + //dtor +} diff --git a/src/Joueur.cpp b/src/Joueur.cpp index 0cb5407..3a9ea8c 100644 --- a/src/Joueur.cpp +++ b/src/Joueur.cpp @@ -1,32 +1,114 @@ +#include +#include #include "Joueur.h" - +#include "Carte.h" +#include "../include/PiocheDeCartes.h" +#include "../include/PiocheDeTortues.h" +#include "constantes.h" Joueur::Joueur() { - std::cout << "Quel age as-tu ?" << std::endl; - std::cin >> this->age; - std::cout << this->age << std::endl; - std::cout << "Quel est ton nom ?"<> this->nom; - std::cout << "Ton nom est : " << this->nom << ", et ton age est"<< this->age << std::endl; - -} -Joueur::Joueur(std::string nom, int age) -{ - this->nom = nom; - this->age = age; + std::cout << "Quel age as-tu ?" << std::endl; + std::cin >> this->age; + std::cout << "Ton nom est : " << this->nom << ", et ton age est "<< this->age << std::endl; this->nb_feuilles_de_salade = 0; } + +void Joueur::renouvelerCarte(PiocheDeCartes* piocheDeCartes, Carte* carteJouee) +{ + Carte* cartePiochee = piocheDeCartes->piocher_carte(); + for (int i = 0; i < NB_CARTES_MAIN; i++) + { + if (this->mainJoueur[i] == carteJouee) + { + this->mainJoueur[i] = cartePiochee; + break; + } + } +} int Joueur::getAge() { return this->age; } + +void Joueur::debutDeManche(PiocheDeCartes* piocheDeCartes, PiocheDeTortues* tuiles) +{ + for (int c = 0; c < NB_CARTES_MAIN; c++) + { + this->mainJoueur[c] = piocheDeCartes->piocher_carte(); + } + this->tortueJoueur = tuiles->piocherTortue(); +} + +void Joueur::finDeManche() +{ + for (int c = 0; c < NB_CARTES_MAIN; c++) + { + this->mainJoueur[c]->~Carte(); + } + this->tortueJoueur->~Tortue(); +} + +Tortue* Joueur::getTortueJoueur() +{ + return this->tortueJoueur; +} + +void Joueur::setTortueJoueur(Tortue* uneTortue) +{ + this->tortueJoueur = uneTortue; +} + +Carte* Joueur::getIndiceMainJoueur(int i) +{ + return this->mainJoueur[i]; +} + std::string Joueur::getNom() { return this->nom; } +void Joueur::ajoutFeuilleDeSalade() +{ + this->nb_feuilles_de_salade = this->nb_feuilles_de_salade + 1; +} + +int Joueur::getNbFeuillesDeSalade() +{ + return this->nb_feuilles_de_salade; +} + +Carte* Joueur::choixCarteJouee() +{ + char saisie; + do + { + cout << this->nom << ", ("<< this->age << " ans) " << "appuie sur o puis sur ENTREE.." << endl; + cin >> saisie; + } + while (saisie != 'o'); + + cout << "Ta tortue : "; + this->tortueJoueur->affichageTortue(); + cout << endl; + cout << "Tes cartes :" << endl; + for (int i = 0; i < NB_CARTES_MAIN; i++) + { + cout << i+1 << " : " ; + this->mainJoueur[i]->afficher(); + } + int reponse = 0; + do + { + cout << endl <<"Quelle carte veux-tu jouer (entre 1 et " << NB_CARTES_MAIN << ")" << endl; + cin >> reponse; + } + while (reponse > NB_CARTES_MAIN || reponse <= 0); + return this->mainJoueur[reponse - 1]; +} Joueur::~Joueur() diff --git a/src/PiocheDeCartes.cpp b/src/PiocheDeCartes.cpp index 58f1a4a..7b1c1a3 100644 --- a/src/PiocheDeCartes.cpp +++ b/src/PiocheDeCartes.cpp @@ -1,37 +1,71 @@ #include "PiocheDeCartes.h" #include #include "constantes.h" +#include +#include "../include/utils.h" +#include +#include +#include using namespace std; PiocheDeCartes::PiocheDeCartes() { - int nbCartesCreees = 0; - cout << "Creation de la pioche !" << endl; + Carte* uneCarte; for (int index_couleur = 0; index_couleur < TAILLE_TAB_COULEUR; index_couleur++) { for (int nb_cartes = 0; nb_cartes < 5; nb_cartes++) { - Carte* uneCarte; uneCarte = new Carte(TAB_COULEUR[index_couleur], T_PLUS1_COULEUR); this->tas.push_back(uneCarte); - nbCartesCreees++; } + uneCarte = new Carte(TAB_COULEUR[index_couleur], T_PLUS2_COULEUR); + this->tas.push_back(uneCarte); for (int nb_cartes = 0; nb_cartes < 2; nb_cartes++) { - Carte* uneCarte; uneCarte = new Carte(TAB_COULEUR[index_couleur], T_MOINS1_COULEUR); this->tas.push_back(uneCarte); - nbCartesCreees++; } - Carte* uneCarte; - this->tas.push_back(uneCarte); - for (int nb_cartes = 0; nb_cartes < 5) } + for (int nb_cartes = 0; nb_cartes < 5; nb_cartes++) + { + uneCarte = new Carte(C_MULTI, T_PLUS1_MULTI ); + this->tas.push_back(uneCarte); + } + for (int nb_cartes = 0; nb_cartes < 2; nb_cartes++) + { + uneCarte = new Carte(C_MULTI, T_MOINS1_MULTI); + this->tas.push_back(uneCarte); + } + for (int nb_cartes = 0; nb_cartes < 3; nb_cartes++) + { + uneCarte = new Carte(C_MULTI, T_PLUS1_DERNIERE); + this->tas.push_back(uneCarte); + } + for (int nb_cartes = 0; nb_cartes < 2; nb_cartes++) + { + uneCarte = new Carte(C_MULTI, T_PLUS2_DERNIERE ); + this->tas.push_back(uneCarte); + } + //ctor } -Carte* PiocheDeCartes::piocher() +Carte* PiocheDeCartes::piocher_carte() { + int index_pioche = rand() % this->tas.size(); + Carte* carte_piochee = this->tas[index_pioche]; + //int indexSelectionne = this->0+ index_pioche; + this->tas.erase(tas.begin() + index_pioche); + return carte_piochee; +} + +void PiocheDeCartes::afficherPaquet() +{ + for (int c = 0; c < this->tas.size(); c++) + { + printf_en_couleur(this->tas[c]->representation_type_carte(this->tas[c]->getType()), this->tas[c]->getCouleur()); + } + cout << this->tas.size(); } PiocheDeCartes::~PiocheDeCartes() diff --git a/src/PiocheDeTortues.cpp b/src/PiocheDeTortues.cpp index 06dc455..7825df9 100644 --- a/src/PiocheDeTortues.cpp +++ b/src/PiocheDeTortues.cpp @@ -1,10 +1,51 @@ +#include +#include +#include +#include #include "PiocheDeTortues.h" +#include "Tortue.h" +#include "constantes.h" +using namespace std; PiocheDeTortues::PiocheDeTortues() { - //ctor -} + this->liste_tortues.clear(); + for (int i = 0; iliste_tortues.push_back(new Tortue(TAB_COULEUR[i])); + } //ctor +} +void PiocheDeTortues::afficherPiocheDeTortues() +{ + cout << "Taille debut constructeur :" << this->liste_tortues.size()<< endl ; + cout << "Tableau des pointeurs de tortues :" << endl; + for (int i = 0; i < this->liste_tortues.size(); i++) + { + if (i != 4) + { + cout << this->liste_tortues[i] << " "; + cout << "Taille a l'indice " << i << ": " << this->liste_tortues.size() << endl ; + } + else + { + cout << this->liste_tortues[i] << endl; + cout << "Taille a l'indice " << i << ": " << this->liste_tortues.size() << endl ; + } + } +} +Tortue* PiocheDeTortues::piocherTortue() +{ + if (this->liste_tortues.size() != 0) + { + int indexTortuePiochee = rand() % this->liste_tortues.size(); + Tortue* tortuePiochee; + tortuePiochee = this->liste_tortues[indexTortuePiochee]; + this->liste_tortues[indexTortuePiochee] = this->liste_tortues[this->liste_tortues.size() - 1 ]; + this->liste_tortues.pop_back(); + return tortuePiochee; + } +} PiocheDeTortues::~PiocheDeTortues() { //dtor diff --git a/src/PlateauDeJeu.cpp b/src/PlateauDeJeu.cpp new file mode 100644 index 0000000..436f008 --- /dev/null +++ b/src/PlateauDeJeu.cpp @@ -0,0 +1,152 @@ +#include +#include +#include "PlateauDeJeu.h" +#include "../include/PiocheDeTortues.h" +#include "../include/Tortue.h" +#include "../include/utils.h" +#include "../include/PlateauDeJeu.h" +#include "../include/Carte.h" +using namespace std; +PlateauDeJeu::PlateauDeJeu(PiocheDeTortues* tortuesAuDepart) +{ + for (int x = 0; x < NB_POSITIONS; x++) + { + for (int y = 0; y < NB_TORTUES; y++) + { + if (x == 0) + { + this->plateau[x][y] = tortuesAuDepart->piocherTortue(); + } + else + { + this->plateau[x][y] = 0; + } + } + } + //ctor +} + +void PlateauDeJeu::affichagePlateau() +{ + // cacher les informations du joueur précédent + system("@cls||clear"); + cout << "Plateau de Jeu :" << endl; + for (int y = NB_TORTUES - 1; y >= 0 ; y--) + { + for (int x = 0; x < NB_POSITIONS; x++) + { + if (this->plateau[x][y] != 0) + { + printf_en_couleur(AFFICHAGE_TORTUE, (plateau[x][y])->Getcouleur()); + } + else + { + cout << AFFICHAGE_VIDE; + } + } + cout << endl; + } + for (int x = 0; x < NB_POSITIONS; x++) + { + cout << AFFICHAGE_BASE; + } + cout << endl << endl; +} + +void PlateauDeJeu::actionCarte(Carte* carteJouee) +{ + int couleurCiblee = carteJouee->getCouleur(); + if ((carteJouee->getType()) == T_PLUS1_DERNIERE || (carteJouee->getType()) == T_PLUS2_DERNIERE) + { + for (int position = 0; position < NB_POSITIONS; position++) + { + if (this->plateau[position][0] != 0) + { + couleurCiblee = (this->plateau[position][0])->Getcouleur(); + break; + } + } + } + else if (couleurCiblee == C_MULTI) + { + for (int c = 0; c < TAILLE_TAB_COULEUR; c++) + { + cout <> choixCouleur; + } + while (choixCouleur > NB_TORTUES || choixCouleur <= 0); + couleurCiblee = TAB_COULEUR[choixCouleur - 1]; + } + for (int x = 0; x < NB_POSITIONS; x++) + { + for (int y = 0; y < NB_TORTUES; y++) + { + if (this->plateau[x][y] != 0 && (this->plateau[x][y]->Getcouleur()) == couleurCiblee) + { + // calculer le déplacement à appliquer + int deplacement = carteJouee->deplacement_type_carte(carteJouee->getType()); + if (x + deplacement < 0) + { + deplacement = -x; + } + else if (x + deplacement >= NB_POSITIONS) + { + deplacement = (NB_POSITIONS - 1) - x; + } + if (deplacement == 0) + { + return; + } + // trouver la nouvelle hauteur de la tortue ciblée + int y_cible; + for (y_cible = 0; this->plateau[x + deplacement][y_cible] != 0; y_cible++); + // poursuivre le parcours de la pile et faire le déplacement + for (; y < NB_TORTUES && this->plateau[x][y] != 0; y++, y_cible++) + { + this->plateau[x + deplacement][y_cible] = this->plateau[x][y]; + this->plateau[x][y] = 0; + } + // déplacement terminé + return; + } + } + } +} + + +bool PlateauDeJeu::uneTortueEstArrivee() +{ + return this->plateau[NB_POSITIONS - 1][0] != 0; +} + +int* PlateauDeJeu::getOrdreArriveeTortue() +{ + int indiceTabArriveeTortue = 0; + int* tabArriveeTortue = (int*)malloc(sizeof(int)* NB_TORTUES); + for (int i = (NB_POSITIONS - 1); i >= 0; i--) + { + for (int j = 0; j < NB_TORTUES; j++) + { + if (this->plateau[i][j] != 0) + { + tabArriveeTortue[indiceTabArriveeTortue] = this->plateau[i][j]->Getcouleur(); + indiceTabArriveeTortue++; + } + } + + } + return tabArriveeTortue; +} + +PlateauDeJeu::~PlateauDeJeu() +{ + //dtor +} diff --git a/src/Tortue.cpp b/src/Tortue.cpp index 7b8a0c1..7d4c0e6 100644 --- a/src/Tortue.cpp +++ b/src/Tortue.cpp @@ -2,6 +2,7 @@ #include #include #include "Tortue.h" +#include "../include/utils.h" using namespace std; Tortue::Tortue(int couleur_t) @@ -10,9 +11,8 @@ Tortue::Tortue(int couleur_t) { cerr << "Erreur dans la création de la tortue :" <couleur = couleur_t; - this->position = 0; + this->position = 1; //ctor } @@ -38,6 +38,5 @@ void Tortue::Setposition(int val) } void Tortue::affichageTortue() { - std::cout << "Affichage de la couleur : "<Getcouleur()<Getposition()<Getcouleur()); } diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..f856e8f --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,21 @@ +#include +#include +#include +#include +#include "PiocheDeCartes.h" +#include "../include/PiocheDeTortues.h" +#include "Carte.h" +#include "Tortue.h" +#include "Joueur.h" +#include "../include/PlateauDeJeu.h" +#include "../include/Jeu.h" +using namespace std; + +int main() +{ + Jeu* unJeu; + srand(time(NULL)); + unJeu = new Jeu(); + unJeu->jouer(); + return 0; +} diff --git a/src/utils.cpp b/src/utils.cpp new file mode 100644 index 0000000..7c0dff4 --- /dev/null +++ b/src/utils.cpp @@ -0,0 +1,51 @@ +#include +#include "../include/utils.h" +#include "../include/constantes.h" +using namespace std; + +FARPROC getConsoleFunction(char *name) { + static HMODULE kernel32=(HMODULE)0xffffffff; + if(kernel32==0) + return NULL; + if(kernel32==(HMODULE)0xffffffff) { + kernel32=LoadLibrary("kernel32.dll"); + if(kernel32==0) + return 0; + } + return GetProcAddress(kernel32,name); +} + + +void printf_en_couleur(string texte, int couleur) +{ + HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); + // pointer to the SetConsoleTextAttribute() winapi function + int (WINAPI* doSetConsoleTextAttribute)(HANDLE hConsoleOutput, WORD attr); + doSetConsoleTextAttribute = (int (__attribute__((__stdcall__)) *)(void*, short unsigned int)) getConsoleFunction("SetConsoleTextAttribute"); + int couleurWindows; + switch (couleur) + { + case C_VERT: + couleurWindows = 10; + break; + case C_BLEU: + couleurWindows = 9; + break; + case C_VIOLET: + couleurWindows = 13; + break; + case C_JAUNE: + couleurWindows = 14; + break; + case C_ROUGE: + couleurWindows = 12; + break; + case C_MULTI: + couleurWindows = 7*16; + break; + } + (*doSetConsoleTextAttribute)(hCon, couleurWindows); + cout << texte; + (*doSetConsoleTextAttribute)(hCon, 7); + +}