From 548c4ed27e4b56dd2ff61263bc2d4245b8c03a4b Mon Sep 17 00:00:00 2001 From: Sunny Date: Fri, 5 Dec 2025 09:38:29 -0500 Subject: [PATCH] confusion --- TicTacToe/fonctions.cpp | 42 +++++++++++++++++++++++++++++------------ TicTacToe/fonctions.h | 3 ++- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/TicTacToe/fonctions.cpp b/TicTacToe/fonctions.cpp index e0523e8..f5976f7 100644 --- a/TicTacToe/fonctions.cpp +++ b/TicTacToe/fonctions.cpp @@ -183,10 +183,9 @@ void afficherImageTableau(std::string grid[][LARGTIC], std::string style) { SetConsoleOutputCP(codeConsole); } -bool verifFinMatch(std::string grid[][LARGTIC]) { +bool verifFinMatch(std::string grid[][LARGTIC], int compteur) { bool fin = false; int max = LARGTIC * LARGTIC; - int compteur = 0; if (compteur == max) { return true; } @@ -199,7 +198,6 @@ bool verifFinMatch(std::string grid[][LARGTIC]) { if (grid[i][j] == "") { fin = false; } - else { fin = fin && (grid[i][j] == grid[i][j + 1]); } @@ -261,13 +259,29 @@ void afficherFinMatch(string grid[][LARGTIC], int gagnant, int nbJoueurs) { if (gagnant == 1) { cout << "\n\nLe joueur a gagne la partie!"; } - else { + else if (gagnant == 2) { cout << "\n\nL'ordinateur a gagne la partie!"; } + else { + cout << "\n\nPartie nulle!"; + } } else { - cout << "\n\nLe joueur " << gagnant - << " a gagne la partie!"; + if (gagnant == 3) { + cout << "\n\nPartie nulle!"; + } + else { + cout << "\n\nLe joueur " << gagnant + << " a gagne la partie!"; + } + } +} + +int partieNulle(string grid[][LARGTIC], int compteur) { + int max = LARGTIC * LARGTIC; + if (compteur == max) { + gagnant = 3; + return gagnant; } } @@ -325,20 +339,20 @@ void jeuUnJoueur(string grid[][LARGTIC]) { bool fin; int gagnant; int nbJoueurs = 1; + int compteur = 0; cout << "Un joueur a ete choisi. Le joueur joue en premier."; - //AJOUTER UN COMPTEUR DE TOURS POUR LES EXAEQUO!!!!!! - do { tourJoueur(grid, 1); gagnant = 1; - fin = verifFinMatch(grid); + fin = verifFinMatch(grid, compteur); + gagnant = partieNulle(grid, compteur); if (fin != true) { tourOrdi(grid); gagnant = 2; system("PAUSE>nul"); - fin = verifFinMatch(grid); + fin = verifFinMatch(grid, compteur); } } while (fin != true); afficherFinMatch(grid, gagnant, nbJoueurs); @@ -363,17 +377,21 @@ void jeuDeuxJoueurs(string grid[][LARGTIC]) { bool fin; int gagnant; int nbJoueurs = 2; + int compteur = 0; cout << "\nDeux joueurs a ete choisi. Les tours seront l'un a la suite de l'autre.\n\n"; do { tourJoueur(grid, 1); gagnant = 1; - fin = verifFinMatch(grid); + fin = verifFinMatch(grid, compteur); + compteur++; + gagnant = partieNulle(grid, compteur); if (fin != true) { tourJoueur(grid, 2); gagnant = 2; - fin = verifFinMatch(grid); + fin = verifFinMatch(grid, compteur); + compteur++; } } while (fin != true); afficherFinMatch(grid, gagnant, nbJoueurs); diff --git a/TicTacToe/fonctions.h b/TicTacToe/fonctions.h index a6fb097..ac903f6 100644 --- a/TicTacToe/fonctions.h +++ b/TicTacToe/fonctions.h @@ -24,8 +24,9 @@ void afficherImageMenu(std::fstream& monFlux); //Général void afficherImageTableau(std::string grid[][LARGTIC], std::string style); void tourJoueur(std::string grid[][LARGTIC], int joueur); //pour savoir quel icon utiliser -bool verifFinMatch(std::string grid[][LARGTIC], int gagnant); +bool verifFinMatch(std::string grid[][LARGTIC], int compteur); void afficherFinMatch(std::string grid[][LARGTIC], int gagnant, int nbJoueurs); +int partieNulle(std::string grid[][LARGTIC], int compteur); //1 joueur void jeuUnJoueur(std::string grid[][LARGTIC]);