From 182106d95b0a64bbb0fe5a42bb8675ff7ee6845a Mon Sep 17 00:00:00 2001 From: Lea Date: Fri, 21 Nov 2025 12:16:54 -0500 Subject: [PATCH 1/4] ajouter fonctions.cpp --- TicTacToe/TicTacToe.vcxproj | 1 + TicTacToe/TicTacToe.vcxproj.filters | 3 +++ TicTacToe/fonctions.cpp | 0 3 files changed, 4 insertions(+) create mode 100644 TicTacToe/fonctions.cpp diff --git a/TicTacToe/TicTacToe.vcxproj b/TicTacToe/TicTacToe.vcxproj index 0dc3f5c..c70ca2c 100644 --- a/TicTacToe/TicTacToe.vcxproj +++ b/TicTacToe/TicTacToe.vcxproj @@ -127,6 +127,7 @@ + diff --git a/TicTacToe/TicTacToe.vcxproj.filters b/TicTacToe/TicTacToe.vcxproj.filters index 13c19ba..34c81d4 100644 --- a/TicTacToe/TicTacToe.vcxproj.filters +++ b/TicTacToe/TicTacToe.vcxproj.filters @@ -26,5 +26,8 @@ Source Files + + Source Files + \ No newline at end of file diff --git a/TicTacToe/fonctions.cpp b/TicTacToe/fonctions.cpp new file mode 100644 index 0000000..e69de29 From 1c7df22efdf600aadba4938adae52b7495a70970 Mon Sep 17 00:00:00 2001 From: Lea Date: Fri, 21 Nov 2025 12:19:14 -0500 Subject: [PATCH 2/4] ok --- TicTacToe/fonctions.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/TicTacToe/fonctions.cpp b/TicTacToe/fonctions.cpp index e69de29..b5754e2 100644 --- a/TicTacToe/fonctions.cpp +++ b/TicTacToe/fonctions.cpp @@ -0,0 +1 @@ +ok \ No newline at end of file From 977dd5ae9a50ee5dd00bbdef93e0da0c7134491e Mon Sep 17 00:00:00 2001 From: Lea Date: Fri, 21 Nov 2025 12:22:29 -0500 Subject: [PATCH 3/4] Ajout de tout le code --- TicTacToe/TicTacToe.vcxproj | 3 + TicTacToe/TicTacToe.vcxproj.filters | 5 + TicTacToe/fonctions.cpp | 205 +++++++++++++++++++++++++++- TicTacToe/fonctions.h | 26 ++++ TicTacToe/main.cpp | 51 +++++++ menuTitre.txt | 8 ++ themes/themeSea.txt | 3 + 7 files changed, 300 insertions(+), 1 deletion(-) create mode 100644 TicTacToe/fonctions.h create mode 100644 menuTitre.txt create mode 100644 themes/themeSea.txt diff --git a/TicTacToe/TicTacToe.vcxproj b/TicTacToe/TicTacToe.vcxproj index c70ca2c..5cd7403 100644 --- a/TicTacToe/TicTacToe.vcxproj +++ b/TicTacToe/TicTacToe.vcxproj @@ -130,6 +130,9 @@ + + + diff --git a/TicTacToe/TicTacToe.vcxproj.filters b/TicTacToe/TicTacToe.vcxproj.filters index 34c81d4..6da88d3 100644 --- a/TicTacToe/TicTacToe.vcxproj.filters +++ b/TicTacToe/TicTacToe.vcxproj.filters @@ -30,4 +30,9 @@ Source Files + + + Header Files + + \ No newline at end of file diff --git a/TicTacToe/fonctions.cpp b/TicTacToe/fonctions.cpp index b5754e2..2d27b70 100644 --- a/TicTacToe/fonctions.cpp +++ b/TicTacToe/fonctions.cpp @@ -1 +1,204 @@ -ok \ No newline at end of file +/*==================================== +AUTEURS : Léa Dezothez et Solène Baillargeon +PROJET : Final +NOM DU FICHIER : fonctions.cpp +DATE : 2025-11-14 +BUT : Fichier de fonctions Tic Tac Toe +====================================*/ + +#include "fonctions.h" +#include +#include +#include +#include +#include +using namespace std; + +extern const int LARGTIC; + +fstream monFlux; +HANDLE hconsole = GetStdHandle(STD_OUTPUT_HANDLE); +char carre = 219, choix; + +void ouvrirFichier(std::fstream& monFlux, std::string nomFichier) { + monFlux.open(nomFichier, ios::in); + if (!monFlux) //On vérifie si le flux est "faux"/non fonctionnel. + { + cout << "ERREUR: Impossible d'ouvrir le fichier!" << endl; + system("PAUSE>0"); + exit(1); //On quitte immédiatement le programme + } +} + +void fermerFichier(std::fstream& monFlux) { + monFlux.close(); +} + +void afficherImageMenu(std::fstream& monFlux) { + int repet = 0; + if (monFlux) { + while (!monFlux.eof()) { + monFlux >> repet; + if (repet == 99) { + cout << endl; + } + else if (repet == 0) { + cout << " "; + } + else { + SetConsoleTextAttribute(hconsole, 15); + cout << carre << carre; + } + } + monFlux.close(); + cout << endl; + } + else { + cout << "ERREUR : Impossible d’ouvrir le fichier! " << endl; + exit(1); + } +} + +void afficherImageTableau(std::string grid[][LARGTIC]) { + SetConsoleOutputCP(CP_UTF8); + string emoteUp, + emoteLine, + emoteDown; + ouvrirFichier(monFlux, "themes/themeSea.txt"); + if (monFlux) { + while (!monFlux.eof()) { + monFlux >> emoteUp >> emoteLine >> emoteDown; + } + monFlux.close(); + cout << endl; + } + else { + cout << "ERREUR : Impossible d’ouvrir le fichier! " << endl; + exit(1); + } + fermerFichier(monFlux); + + cout << " "; + for (int i = 0; i < LARGTIC; i++) { + cout << " " << i + 1 << " "; + } + cout << " " << endl << " "; + for (int k = 0; k < LARGTIC; k++) { + + for (int i = 0; i < LARGTIC; i++) { + for (int j = 0; j < 2; j++) { + cout << emoteUp << " "; + } + } + cout << endl << " "; + + for (int i = 0; i < LARGTIC; i++) { + cout << emoteLine; + for (int j = 0; j < 3; j++) { + cout << " "; + } + } + cout << emoteLine << endl << " " << k + 1 << " "; + + + for (int i = 0; i < LARGTIC; i++) { + cout << emoteLine << " " << grid[k][i] << " "; + + } + cout << emoteLine << endl << " "; + + for (int i = 0; i < LARGTIC; i++) { + cout << emoteLine; + for (int j = 0; j < 3; j++) { + cout << " "; + } + } + cout << emoteLine << endl << " "; + + } + + for (int i = 0; i < LARGTIC; i++) { + for (int j = 0; j < 2; j++) { + cout << emoteDown << " "; + } + } + cout << endl; + +} + +bool verifFinMatch(std::string grid[][LARGTIC]) { + bool fin = true; + // Valide horizontales + for (int i = 0; i < 2; i++) { + fin = true; + for (int j = 0; j < 2; j++) { + fin = fin && grid[i][j] == grid[i][j + 1]; + } + if (fin == true) { + return fin; + } + } + // Valide verticales + for (int i = 0; i < 2; i++) { + fin = true; + for (int j = 0; j < 2; j++) { + fin = fin && grid[i][j] == grid[i + 1][j]; + } + if (fin == true) { + return fin; + } + } + // Valide diagonale de 00, 11, 22 + fin = true; + for (int i = 0; i < 2; i++) { + fin = fin && grid[i][i] == grid[i + 1][i + 1]; + if (fin == true) { + return fin; + } + } + + // Valide diagonale 02, 11, 20 + for (int i = 2; i > 0; i--) { + fin = fin && grid[i][i] == grid[i - 1][i - 1]; + if (fin == true) { + return fin; + } + } +} + +//Menu +void afficherMenu(char& choix) { + system("cls"); + //T I C T A C T O E + ouvrirFichier(monFlux, "menuTitre.txt"); + afficherImageMenu(monFlux); + fermerFichier(monFlux); + + // Menu + cout << endl << "MENU" << endl << "----------------------------------" << endl + << "A) 1 joueur" << endl + << "B) 2 joueurs" << endl + << "C) Montrer l'historique des scores" << endl + << "D) Changer le style du jeu" << endl + << "Q) Quitter" << endl << endl + << "Quel est votre choix? "; + choix = toupper(_getche()); + cout << endl; +} + +void initialiserGrid(string grid[][LARGTIC]) { + +} + +void jeuDeuxJoueurs(string grid[][LARGTIC]) { + bool fin; + cout << endl << "Deux joueurs a ete choisi. Les tours seront l'un a la suite de l'autre." << endl << endl; + + do { + cout << "Tour du joueur" << endl; + afficherImageTableau(grid); + system("PAUSE"); + fin = verifFinMatch(grid); + // la condition doit être une série de 3 chiffres + } while (fin = true); +} \ No newline at end of file diff --git a/TicTacToe/fonctions.h b/TicTacToe/fonctions.h new file mode 100644 index 0000000..3c229ed --- /dev/null +++ b/TicTacToe/fonctions.h @@ -0,0 +1,26 @@ +/*==================================== +AUTEURS : Léa Dezothez et Solène Baillargeon +PROJET : Final +NOM DU FICHIER : fonctions.h +DATE : 2025-11-14 +BUT : Déclaration fonctions pour le jeu Tic Tac Toe +====================================*/ + +#include +#include +#pragma once +const int LARGTIC = 3; + +void afficherMenu(char& choix); +void afficherImageMenu(std::fstream& monFlux); + +void ouvrirFichier(std::fstream& monFlux, std::string nomFichier); +void fermerFichier(std::fstream& monFlux); + +void initialiserGrid(std::string grid[][LARGTIC]); + +void afficherImageTableau(std::string grid[][LARGTIC]); + +void jeuDeuxJoueurs(std::string grid[][LARGTIC]); + +bool verifFinMatch(std::string grid[][LARGTIC]); diff --git a/TicTacToe/main.cpp b/TicTacToe/main.cpp index e69de29..4ecc1d0 100644 --- a/TicTacToe/main.cpp +++ b/TicTacToe/main.cpp @@ -0,0 +1,51 @@ +/*==================================== +AUTEURS : Léa Dezothez et Solène Baillargeon +PROJET : Final +NOM DU FICHIER : main.cpp +DATE : 2025-11-14 +BUT : Main pour le jeu Tic Tac Toe +====================================*/ + +#include +#include "fonctions.h" +using namespace std; + +extern const int LARGTIC; + +int main() { + char choix; + string grid[LARGTIC][LARGTIC] = { "x", "o","x", "x", "o","x" , "x", "o","x" }; + + do { + afficherMenu(choix); + + switch (choix) { + case 'A': + + break; + + case 'B': + system("cls"); + jeuDeuxJoueurs(grid); + break; + + case 'C': + + break; + + case 'D': + + break; + + case 'Q': + cout << "Au revoir!"; + break; + + default: + cout << endl << "Saisissez un choix valide." << endl; + break; + } + system("PAUSE>0"); + } while (choix != 'Q'); + +} \ No newline at end of file diff --git a/menuTitre.txt b/menuTitre.txt new file mode 100644 index 0000000..9d061a1 --- /dev/null +++ b/menuTitre.txt @@ -0,0 +1,8 @@ +2 2 2 2 2 0 2 2 2 2 2 0 2 2 2 2 0 0 2 2 2 2 2 0 0 2 2 2 0 0 2 2 2 2 0 0 2 2 2 2 2 0 0 2 2 2 0 0 2 2 2 2 99 +0 0 2 0 0 0 0 0 2 0 0 0 2 0 0 0 0 0 0 0 2 0 0 0 2 0 0 0 2 0 2 0 0 0 0 0 0 0 2 0 0 0 2 0 0 0 2 0 2 0 0 0 99 +0 0 2 0 0 0 0 0 2 0 0 0 2 0 0 0 0 0 0 0 2 0 0 0 2 0 0 0 2 0 2 0 0 0 0 0 0 0 2 0 0 0 2 0 0 0 2 0 2 0 0 0 99 +0 0 2 0 0 0 0 0 2 0 0 0 2 0 0 0 0 0 0 0 2 0 0 0 2 0 0 0 2 0 2 0 0 0 0 0 0 0 2 0 0 0 2 0 0 0 2 0 2 2 2 2 99 +0 0 2 0 0 0 0 0 2 0 0 0 2 0 0 0 0 0 0 0 2 0 0 0 2 2 2 2 2 0 2 0 0 0 0 0 0 0 2 0 0 0 2 0 0 0 2 0 2 0 0 0 99 +0 0 2 0 0 0 0 0 2 0 0 0 2 0 0 0 0 0 0 0 2 0 0 0 2 0 0 0 2 0 2 0 0 0 0 0 0 0 2 0 0 0 2 0 0 0 2 0 2 0 0 0 99 +0 0 2 0 0 0 2 2 2 2 2 0 2 2 2 2 0 0 0 0 2 0 0 0 2 0 0 0 2 0 2 2 2 2 0 0 0 0 2 0 0 0 0 2 2 2 0 0 2 2 2 2 99 + diff --git a/themes/themeSea.txt b/themes/themeSea.txt new file mode 100644 index 0000000..cc332be --- /dev/null +++ b/themes/themeSea.txt @@ -0,0 +1,3 @@ +🌊 +🔹 +🪸 \ No newline at end of file From a15249f393b8fea26f2b3b04c11d53f9a0a16106 Mon Sep 17 00:00:00 2001 From: Lea Date: Fri, 21 Nov 2025 14:38:06 -0500 Subject: [PATCH 4/4] =?UTF-8?q?modifs=20du=20code=20avec=20les=20ajouts=20?= =?UTF-8?q?de=20Sol=C3=A8ne?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TicTacToe/0 | 1 + TicTacToe/fonctions.cpp | 85 +++++++++++++++++------ TicTacToe/fonctions.h | 21 ++++-- TicTacToe/main.cpp | 55 ++++++++------- menuTitre.txt => TicTacToe/menuTitre.txt | 0 {themes => TicTacToe/themes}/themeSea.txt | 0 6 files changed, 108 insertions(+), 54 deletions(-) create mode 100644 TicTacToe/0 rename menuTitre.txt => TicTacToe/menuTitre.txt (100%) rename {themes => TicTacToe/themes}/themeSea.txt (100%) diff --git a/TicTacToe/0 b/TicTacToe/0 new file mode 100644 index 0000000..d7619da --- /dev/null +++ b/TicTacToe/0 @@ -0,0 +1 @@ +Appuyez sur une touche pour continuer... \ No newline at end of file diff --git a/TicTacToe/fonctions.cpp b/TicTacToe/fonctions.cpp index 2d27b70..7ef2ec4 100644 --- a/TicTacToe/fonctions.cpp +++ b/TicTacToe/fonctions.cpp @@ -15,11 +15,14 @@ BUT : Fichier de fonctions Tic Tac Toe using namespace std; extern const int LARGTIC; +const string ICONJ1 = { "X" }; +const string ICONJ2 = { "O" }; fstream monFlux; HANDLE hconsole = GetStdHandle(STD_OUTPUT_HANDLE); char carre = 219, choix; +//Fichiers void ouvrirFichier(std::fstream& monFlux, std::string nomFichier) { monFlux.open(nomFichier, ios::in); if (!monFlux) //On vérifie si le flux est "faux"/non fonctionnel. @@ -34,6 +37,26 @@ void fermerFichier(std::fstream& monFlux) { monFlux.close(); } +//Menu +void afficherMenu(char& choix) { + system("cls"); + //T I C T A C T O E + ouvrirFichier(monFlux, "menuTitre.txt"); + afficherImageMenu(monFlux); + fermerFichier(monFlux); + + // Menu + cout << endl << "MENU" << endl << "----------------------------------" << endl + << "A) 1 joueur" << endl + << "B) 2 joueurs" << endl + << "C) Montrer l'historique des scores" << endl + << "D) Changer le style du jeu" << endl + << "Q) Quitter" << endl << endl + << "Quel est votre choix? "; + choix = toupper(_getche()); + cout << endl; +} + void afficherImageMenu(std::fstream& monFlux) { int repet = 0; if (monFlux) { @@ -59,6 +82,7 @@ void afficherImageMenu(std::fstream& monFlux) { } } +//Général (plusieurs options) void afficherImageTableau(std::string grid[][LARGTIC]) { SetConsoleOutputCP(CP_UTF8); string emoteUp, @@ -126,6 +150,26 @@ void afficherImageTableau(std::string grid[][LARGTIC]) { } +void tourJoueur(string grid[][LARGTIC], int joueur) { + int verticale, + horizontale; + + cout << "\n\nTour du joueur " << joueur << endl; + afficherImageTableau(grid); + + cout << "\n\nEntrez une coordonnee verticale : "; + cin >> verticale; + cout << "\nEntrez une coordonnee horizontale : "; + cin >> horizontale; + + if (joueur == 1) { + grid[verticale - 1][horizontale - 1] = ICONJ1; + } + else { + grid[verticale - 1][horizontale - 1] = ICONJ2; + } +} + bool verifFinMatch(std::string grid[][LARGTIC]) { bool fin = true; // Valide horizontales @@ -166,38 +210,37 @@ bool verifFinMatch(std::string grid[][LARGTIC]) { } } -//Menu -void afficherMenu(char& choix) { - system("cls"); - //T I C T A C T O E - ouvrirFichier(monFlux, "menuTitre.txt"); - afficherImageMenu(monFlux); - fermerFichier(monFlux); +//1 joueur +void jeuUnJoueur(string grid[][LARGTIC]) { + bool fin; + cout << "\nUn joueur a ete choisi. Le joueur joue en premier.\n\n"; - // Menu - cout << endl << "MENU" << endl << "----------------------------------" << endl - << "A) 1 joueur" << endl - << "B) 2 joueurs" << endl - << "C) Montrer l'historique des scores" << endl - << "D) Changer le style du jeu" << endl - << "Q) Quitter" << endl << endl - << "Quel est votre choix? "; - choix = toupper(_getche()); - cout << endl; + do { + tourJoueur(grid, 1); + tourOrdi(grid); + system("PAUSE>0"); + fin = verifFinMatch(grid); + } while (fin = true); } -void initialiserGrid(string grid[][LARGTIC]) { +void tourOrdi(string grid[][LARGTIC]) { + int vertical = rand() % (3); + int horizontal = rand() % (3); + cout << "\n\nTour de l'ordinateur" << endl; + afficherImageTableau(grid); + + grid[vertical][horizontal] = ICONJ2; } +//2 joueurs void jeuDeuxJoueurs(string grid[][LARGTIC]) { bool fin; cout << endl << "Deux joueurs a ete choisi. Les tours seront l'un a la suite de l'autre." << endl << endl; do { - cout << "Tour du joueur" << endl; - afficherImageTableau(grid); - system("PAUSE"); + tourJoueur(grid, 1); + tourJoueur(grid, 2); fin = verifFinMatch(grid); // la condition doit être une série de 3 chiffres } while (fin = true); diff --git a/TicTacToe/fonctions.h b/TicTacToe/fonctions.h index 3c229ed..1f03117 100644 --- a/TicTacToe/fonctions.h +++ b/TicTacToe/fonctions.h @@ -9,18 +9,25 @@ BUT : D #include #include #pragma once + const int LARGTIC = 3; -void afficherMenu(char& choix); -void afficherImageMenu(std::fstream& monFlux); - +//Fichiers void ouvrirFichier(std::fstream& monFlux, std::string nomFichier); void fermerFichier(std::fstream& monFlux); -void initialiserGrid(std::string grid[][LARGTIC]); +//Menu +void afficherMenu(char& choix); +void afficherImageMenu(std::fstream& monFlux); +//Général void afficherImageTableau(std::string grid[][LARGTIC]); - -void jeuDeuxJoueurs(std::string grid[][LARGTIC]); - +void tourJoueur(std::string grid[][LARGTIC], int joueur); //pour savoir quel icon utiliser bool verifFinMatch(std::string grid[][LARGTIC]); + +//1 joueur +void jeuUnJoueur(std::string grid[][LARGTIC]); +void tourOrdi(std::string grid[][LARGTIC]); + +//2 joueurs +void jeuDeuxJoueurs(std::string grid[][LARGTIC]); \ No newline at end of file diff --git a/TicTacToe/main.cpp b/TicTacToe/main.cpp index 4ecc1d0..bf77ba4 100644 --- a/TicTacToe/main.cpp +++ b/TicTacToe/main.cpp @@ -10,42 +10,45 @@ BUT : Main pour le jeu Tic Tac Toe #include "fonctions.h" using namespace std; -extern const int LARGTIC; +const string ICONJ1 = { "X" }; +const string ICONJ2 = { "O" }; int main() { - char choix; - string grid[LARGTIC][LARGTIC] = { "x", "o","x", "x", "o","x" , "x", "o","x" }; + srand(time(NULL)); - do { - afficherMenu(choix); + char choix; + string grid[LARGTIC][LARGTIC] = { " ", " ", " "," ", " ", " ", " ", " ", " "}; - switch (choix) { - case 'A': + do { + afficherMenu(choix); - break; + switch (choix) { + case 'A': + system("cls"); + jeuUnJoueur(grid); + break; - case 'B': - system("cls"); - jeuDeuxJoueurs(grid); - break; + case 'B': + system("cls"); + jeuDeuxJoueurs(grid); + break; - case 'C': + case 'C': - break; + break; - case 'D': + case 'D': - break; + break; - case 'Q': - cout << "Au revoir!"; - break; - - default: - cout << endl << "Saisissez un choix valide." << endl; - break; - } - system("PAUSE>0"); - } while (choix != 'Q'); + case 'Q': + cout << "\nAu revoir!"; + break; + default: + cout << endl << "Saisissez un choix valide." << endl; + break; + } + system("PAUSE>0"); + } while (choix != 'Q'); } \ No newline at end of file diff --git a/menuTitre.txt b/TicTacToe/menuTitre.txt similarity index 100% rename from menuTitre.txt rename to TicTacToe/menuTitre.txt diff --git a/themes/themeSea.txt b/TicTacToe/themes/themeSea.txt similarity index 100% rename from themes/themeSea.txt rename to TicTacToe/themes/themeSea.txt