Jeu fini sauf bug avec cin

master
Alexandre 2020-05-04 17:19:21 +02:00
parent e68f62b756
commit 0ae431d4d4
17 changed files with 670 additions and 95 deletions

34
include/Jeu.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef JEU_H
#define JEU_H
#include <vector>
#include <string>
#include <windows.h>
#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<Joueur*> tabJoueurs;
PiocheDeCartes* piocheDeCartes;
PiocheDeTortues* listeTortues;
PiocheDeTortues* tuiles;
PlateauDeJeu* plateauDeJeu;
};
#endif // JEU_H

View File

@ -1,16 +1,26 @@
#ifndef JOUEUR_H
#define JOUEUR_H
#include <iostream>
#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:

View File

@ -8,10 +8,10 @@ class PiocheDeCartes
public:
PiocheDeCartes();
virtual ~PiocheDeCartes();
Carte* piocher();
Carte* piocher_carte();
void afficherPaquet();
protected:
vector<Carte*> tas;
int nb_cartes_restantes;
private:
};

View File

@ -1,16 +1,22 @@
#ifndef PIOCHEDETORTUES_H
#define PIOCHEDETORTUES_H
#include <vector>
#include "Tortue.h"
using namespace std;
class PiocheDeTortues
{
public:
PiocheDeTortues();
void afficherPiocheDeTortues();
Tortue* piocherTortue();
virtual ~PiocheDeTortues();
protected:
private:
vector<Tortue*> liste_tortues;
};
#endif // PIOCHEDETORTUES_H

26
include/PlateauDeJeu.h Normal file
View File

@ -0,0 +1,26 @@
#ifndef PLATEAUDEJEU_H
#define PLATEAUDEJEU_H
#include <vector>
#include <windows.h>
#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

View File

@ -1,6 +1,5 @@
#ifndef CONSTANTES_H
#define CONSTANTES_H
#define CONSTANTES_H 1
#include <string>
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

10
include/utils.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef UTILS_H_INCLUDED
#define UTILS_H_INCLUDED
#include <string>
#include <windows.h>
using namespace std;
void printf_en_couleur(string texte, int couleur);
FARPROC getConsoleFunction(char *name);
#endif // UTILS_H_INCLUDED

View File

@ -1,23 +0,0 @@
#include <iostream>
#include <vector>
#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;
}

View File

@ -1,31 +1,24 @@
#include <iostream>
#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 :"<<this->representation_type_carte(this->type)<<endl;
printf_en_couleur(this->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 "<<this<<endl;
return this->couleur;
}
int deplacement_type_carte (int type_carte)
int Carte::deplacement_type_carte(int type_carte)
{
return type_carte % 3;
}

151
src/Jeu.cpp Normal file
View File

@ -0,0 +1,151 @@
#include <iostream>
#include <windows.h>
#include <string>
#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
}

View File

@ -1,32 +1,114 @@
#include <iostream>
#include <vector>
#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 ?"<<std::endl;
std::cin >> 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()

View File

@ -1,37 +1,71 @@
#include "PiocheDeCartes.h"
#include <iostream>
#include "constantes.h"
#include <windows.h>
#include "../include/utils.h"
#include <vector>
#include <cstdlib>
#include <time.h>
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()

View File

@ -1,10 +1,51 @@
#include <iostream>
#include <vector>
#include <cstdlib>
#include <time.h>
#include "PiocheDeTortues.h"
#include "Tortue.h"
#include "constantes.h"
using namespace std;
PiocheDeTortues::PiocheDeTortues()
{
//ctor
}
this->liste_tortues.clear();
for (int i = 0; i<NB_TORTUES; i++)
{
this->liste_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

152
src/PlateauDeJeu.cpp Normal file
View File

@ -0,0 +1,152 @@
#include <iostream>
#include <windows.h>
#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 <<c+1<<":" ;
printf_en_couleur(AFFICHAGE_TORTUE, TAB_COULEUR[c]);
cout << "\t\t";
}
cout << endl;
int choixCouleur;
do
{
cout <<"Quelle tortue veux-tu deplacer (entre 1 et " << NB_TORTUES << ")";
cin >> 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
}

View File

@ -2,6 +2,7 @@
#include <cstdlib>
#include <string>
#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 :" <<endl;
}
cout<< "Création d'une tortue !"<<endl;
this->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 : "<<this->Getcouleur()<<std::endl;
std::cout << "Affichage de la position : "<<this->Getposition()<<std::endl;
printf_en_couleur("T", this->Getcouleur());
}

21
src/main.cpp Normal file
View File

@ -0,0 +1,21 @@
#include <iostream>
#include <vector>
#include <time.h>
#include <cstdlib>
#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;
}

51
src/utils.cpp Normal file
View File

@ -0,0 +1,51 @@
#include <iostream>
#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);
}