#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 }