From 370b31ce46c1d428a5071db750dc3549606ac61e Mon Sep 17 00:00:00 2001 From: Lea Date: Fri, 28 Nov 2025 08:42:36 -0500 Subject: [PATCH] =?UTF-8?q?modification=20des=20modifications=20de=20r?= =?UTF-8?q?=C3=A9solution=20de=20probl=C3=A8mes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TicTacToe/fonctions.cpp | 42 ++++++++++++++++++++++++----------------- TicTacToe/fonctions.h | 2 +- TicTacToe/main.cpp | 2 +- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/TicTacToe/fonctions.cpp b/TicTacToe/fonctions.cpp index 102c7c7..00743fa 100644 --- a/TicTacToe/fonctions.cpp +++ b/TicTacToe/fonctions.cpp @@ -15,8 +15,8 @@ BUT : Fichier de fonctions Tic Tac Toe using namespace std; extern const int LARGTIC; -string ICONJ1 = "X"; -string ICONJ2 = "O"; +string iconJ1 = "X"; +string iconJ2 = "O"; string style = "themes/themeSea.txt"; int codeConsole = 0; @@ -90,15 +90,15 @@ void afficherImageTableau(std::string grid[][LARGTIC], std::string style) { SetConsoleOutputCP(CP_UTF8); string emoteUp, emoteDown, - iconJ1, - iconJ2; + emoteJ1, + emoteJ2; // Faire une fonction pour retenir le thème sélectionné par le joueur!!!! ouvrirFichier(monFlux, style); if (monFlux) { while (!monFlux.eof()) { - monFlux >> emoteUp >> emoteDown >> ICONJ1 >> ICONJ2; + monFlux >> emoteUp >> emoteDown >> emoteJ1 >> emoteJ2; } monFlux.close(); cout << endl; @@ -132,15 +132,16 @@ void afficherImageTableau(std::string grid[][LARGTIC], std::string style) { for (int j = 0; j < 3; j++) { cout << " "; } + cout << " "; } cout << "|" << endl << " " << k + 1 << " "; for (int i = 0; i < LARGTIC; i++) { - cout << "|" << " " ; + cout << "|" << " "; if (grid[k][i] == "X") { cout << emoteJ1; - } + } else if (grid[k][i] == "O") { cout << emoteJ2; } @@ -156,6 +157,7 @@ void afficherImageTableau(std::string grid[][LARGTIC], std::string style) { for (int j = 0; j < 3; j++) { cout << " "; } + cout << " "; } cout << "|" << endl << " "; @@ -198,20 +200,23 @@ void tourJoueur(string grid[][LARGTIC], int joueur) { verticale -= 1; horizontale -= 1; - while (grid[verticale][horizontale] == ICONJ1 || grid[verticale][horizontale] == ICONJ2) { + while (grid[verticale][horizontale] == iconJ1 || grid[verticale][horizontale] == iconJ2) { // VÉRIFIER LE CIN D'ERREUR!!!!! cout << "\n\nVeuillez choisir une case vide.\n" << "\n\nEntrez une coordonnee verticale : "; cin >> verticale; cout << "\nEntrez une coordonnee horizontale : "; cin >> horizontale; + + verticale--; + horizontale--; } if (joueur == 1) { - grid[verticale][horizontale] = ICONJ1; + grid[verticale][horizontale] = iconJ1; } else { - grid[verticale][horizontale] = ICONJ2; + grid[verticale][horizontale] = iconJ2; } } @@ -222,7 +227,7 @@ bool verifFinMatch(std::string grid[][LARGTIC]) { for (int i = 0; i < 2; i++) { fin = true; for (int j = 0; j < 2; j++) { - if (grid[i][j] == " ") { + if (grid[i][j] == "") { fin = false; } @@ -238,7 +243,7 @@ bool verifFinMatch(std::string grid[][LARGTIC]) { for (int i = 0; i < 2; i++) { fin = true; for (int j = 0; j < 2; j++) { - if (grid[i][j] == " ") { + if (grid[i][j] == "") { fin = false; } else { @@ -252,7 +257,7 @@ bool verifFinMatch(std::string grid[][LARGTIC]) { // Valide diagonale de 00, 11, 22 fin = true; for (int i = 0; i < 2; i++) { - if (grid[i][i] == " ") { + if (grid[i][i] == "") { fin = false; } else { @@ -266,7 +271,7 @@ bool verifFinMatch(std::string grid[][LARGTIC]) { // Valide diagonale 02, 11, 20 fin = true; for (int i = 2; i > 0; i--) { - if (grid[i][i] == " ") { + if (grid[i][i] == "") { fin = false; } else { @@ -280,7 +285,7 @@ bool verifFinMatch(std::string grid[][LARGTIC]) { void afficherFinMatch(string grid[][LARGTIC], int gagnant, int nbJoueurs) { afficherImageTableau(grid, style); - + if (nbJoueurs == 1) { if (gagnant == 1) { cout << "\n\nLe joueur a gagne la partie!"; @@ -326,7 +331,7 @@ void tourOrdi(string grid[][LARGTIC]) { vertical = rand() % (3); horizontal = rand() % (3); } while (grid[vertical][horizontal] != ""); - grid[vertical][horizontal] = ICONJ2; + grid[vertical][horizontal] = iconJ2; afficherImageTableau(grid, style); } @@ -352,7 +357,7 @@ void jeuDeuxJoueurs(string grid[][LARGTIC]) { } //Changer le thème -void changerLeTheme() { +void changerLeTheme(bool& theme) { string grid[LARGTIC][LARGTIC]; system("cls"); do { @@ -364,6 +369,9 @@ void changerLeTheme() { choix = toupper(_getche()); cout << endl; + if (choix >= 'A' && choix <= 'D') { + theme = true; + } switch (choix) { case 'A': style = "themes/themeSea.txt"; diff --git a/TicTacToe/fonctions.h b/TicTacToe/fonctions.h index 4f45821..3519995 100644 --- a/TicTacToe/fonctions.h +++ b/TicTacToe/fonctions.h @@ -35,5 +35,5 @@ void tourOrdi(std::string grid[][LARGTIC]); void jeuDeuxJoueurs(std::string grid[][LARGTIC]); //Changer le thème -void changerLeTheme(); +void changerLeTheme(bool &theme); diff --git a/TicTacToe/main.cpp b/TicTacToe/main.cpp index 32e08ba..ec710bd 100644 --- a/TicTacToe/main.cpp +++ b/TicTacToe/main.cpp @@ -57,6 +57,6 @@ int main() { cout << endl << "Saisissez un choix valide." << endl; break; } - system("PAUSE>0"); + system("PAUSE>nul"); } while (choix != 'Q'); } \ No newline at end of file