Compare commits

..

27 Commits

Author SHA1 Message Date
Sunny
b488389d8a TOUT MARRRRRCHE!!! 2025-12-05 10:45:49 -05:00
Lea
c928b9483d modification de la fonction partie nulle 2025-12-05 10:22:44 -05:00
Sunny
ffe4af9f93 Merge branch 'main' of https://gitea.zkd.ca/DEV_WEB/TicTacToe 2025-12-05 10:13:11 -05:00
Sunny
1d513239d2 WTF 2025-12-05 10:12:30 -05:00
Lea
d445cda491 wijhfkjdfns 2025-12-05 10:09:50 -05:00
Sunny
b991978b6d Idk, dude 2025-12-05 10:02:20 -05:00
Sunny
a72da69ea7 Work 2025-12-05 09:51:51 -05:00
Lea
008f2a3329 l'affichage de partie nulle fonctionne, mais le vainqueur est affiché comme étant joueur 9 2025-12-05 09:51:40 -05:00
Sunny
00217eb38a Merge branch 'main' of https://gitea.zkd.ca/DEV_WEB/TicTacToe 2025-12-05 09:38:34 -05:00
Sunny
548c4ed27e confusion 2025-12-05 09:38:29 -05:00
Lea
1a8a5dd8d7 Merge branch 'main' of https://gitea.zkd.ca/Dev_Web/TicTacToe 2025-12-05 09:26:59 -05:00
Lea
82cbc90c4c correction de la vérif fin match, tout fonctionne mtn pour cette fonction 2025-12-05 09:26:53 -05:00
Sunny
a10845eff2 La vérif verticale marche toujours pas et jsp comment faire la partie nulle ;-; 2025-12-05 08:40:19 -05:00
Lea
763aba1a13 modification de la vérification de la fin de match avec un compteur 2025-12-05 08:30:54 -05:00
Lea
1d28babc6e Modification des 3 pour la variable constante LARGTIC 2025-11-28 10:55:42 -05:00
Lea
d6ead0a3e1 Merge branch 'main' of https://gitea.zkd.ca/Dev_Web/TicTacToe 2025-11-28 10:20:22 -05:00
Lea
d4d337a648 Ajout des trucs à terminer 2025-11-28 10:20:16 -05:00
Sunny
7c539b8612 Hi x2 2025-11-28 10:18:10 -05:00
Sunny
5ed7712c24 Hi 2025-11-28 10:17:41 -05:00
Sunny
74ec166daf Merge branch 'main' of https://gitea.zkd.ca/DEV_WEB/TicTacToe 2025-11-28 10:02:50 -05:00
lea
4740f1e484 Merge pull request 'Lea' (#1) from Lea into main
Reviewed-on: #1
2025-11-28 10:00:46 -05:00
Lea
d8889c6f4f modifications sur plusieurs niveaux 2025-11-28 09:58:25 -05:00
Lea
3ac1c10f8a création d'une branche secondaire (je pense que ç'a marché) 2025-11-28 09:42:12 -05:00
Sunny
1124360a0f Merge branch 'main' of https://gitea.zkd.ca/DEV_WEB/TicTacToe 2025-11-28 09:29:02 -05:00
Sunny
76fda40b38 Merge branch 'main' of https://gitea.zkd.ca/DEV_WEB/TicTacToe 2025-11-28 09:20:34 -05:00
Sunny
b94a724c06 Merge branch 'main' of https://gitea.zkd.ca/DEV_WEB/TicTacToe 2025-11-28 09:18:25 -05:00
Sunny
fa685095fc IDK 2025-11-28 09:18:21 -05:00
3 changed files with 160 additions and 125 deletions

View File

@@ -17,6 +17,7 @@ using namespace std;
extern const int LARGTIC; extern const int LARGTIC;
string iconJ1 = "X"; string iconJ1 = "X";
string iconJ2 = "O"; string iconJ2 = "O";
int gagnant;
string style = "themes/themeDefaut.txt"; string style = "themes/themeDefaut.txt";
int codeConsole = 0; int codeConsole = 0;
@@ -24,6 +25,8 @@ fstream monFlux;
HANDLE hconsole = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE hconsole = GetStdHandle(STD_OUTPUT_HANDLE);
char carre = 219, choix; char carre = 219, choix;
//<2F> faire : <20>galit<69> et entrer de coordonn<6E>e
//Fichiers //Fichiers
void ouvrirFichier(std::fstream & monFlux, std::string nomFichier) { void ouvrirFichier(std::fstream & monFlux, std::string nomFichier) {
monFlux.open(nomFichier, ios::in); monFlux.open(nomFichier, ios::in);
@@ -87,15 +90,15 @@ void afficherImageMenu(std::fstream& monFlux) {
//G<>n<EFBFBD>ral (plusieurs options) //G<>n<EFBFBD>ral (plusieurs options)
void initGrid(string grid[][LARGTIC]) { void initGrid(string grid[][LARGTIC]) {
for (int i = 0; i < 3; i++) { for (int i = 0; i < LARGTIC; i++) {
for (int j = 0; j < 3; j++) { for (int j = 0; j < LARGTIC; j++) {
grid[i][j] = ""; grid[i][j] = "";
} }
} }
} }
void afficherImageTableau(std::string grid[][LARGTIC], std::string style) { void afficherImageTableau(std::string grid[][LARGTIC], std::string style) {
SetConsoleOutputCP(CP_UTF8); SetConsoleOutputCP(CP_UTF8); //affiche les <20>mojis
string emoteUp, string emoteUp,
emoteDown, emoteDown,
emoteJ1, emoteJ1,
@@ -180,88 +183,53 @@ void afficherImageTableau(std::string grid[][LARGTIC], std::string style) {
SetConsoleOutputCP(codeConsole); SetConsoleOutputCP(codeConsole);
} }
void tourJoueur(string grid[][LARGTIC], int joueur) { bool verifFinMatch(std::string grid[][LARGTIC], int compteur) {
int verticale, bool fin = false;
horizontale; int max = LARGTIC * LARGTIC;
if (compteur == max) {
cout << "\n\nTour du joueur " << joueur << endl; return true;
afficherImageTableau(grid, style);
cout << "\n\nEntrez une coordonnee verticale : ";
cin >> verticale;
while (verticale < 1 || verticale > 3) {
cout << "\n\nVeuillez entrer une donnee valide.\n"
<< "\n\nEntrez une coordonnee verticale : ";
cin >> verticale;
}
cout << "\nEntrez une coordonnee horizontale : ";
cin >> horizontale;
while (horizontale < 1 || horizontale > 3) {
cout << "\n\nVeuillez entrer une donnee valide.\n"
<< "\n\nEntrez une coordonnee horizontale : ";
cin >> horizontale;
}
verticale -= 1;
horizontale -= 1;
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;
} }
else { else {
grid[verticale][horizontale] = iconJ2; // Valide horizontales 00, 01, 02 || 10, 11, 12 || 20, 21, 22
} for (int i = 0; i < LARGTIC; i++) {
}
bool verifFinMatch(std::string grid[][LARGTIC]) {
bool fin = false;
// Valide horizontales
for (int i = 0; i < 2; i++) {
fin = true; fin = true;
for (int j = 0; j < 2; j++) { for (int j = 0; j < LARGTIC - 1; j++) {
if (grid[i][j] == "") { if (grid[i][j] == "") {
fin = false; fin = false;
} }
else { else {
fin = fin && (grid[i][j] == grid[i][j + 1]); fin = fin && (grid[i][j] == grid[i][j + 1]);
//cout << "comparaison de " << i << "," << j << " et " << i << "," << j+1 << endl;
} }
} }
if (fin == true) { if (fin == true) {
return fin; return fin;
} }
} }
// Valide verticales if (fin == true) {
for (int i = 0; i < 2; i++) { return fin;
}
// Valide verticales 00, 10, 20 || 01, 11, 21 || 02, 12, 22
for (int i = 0; i < LARGTIC; i++) {
fin = true; fin = true;
for (int j = 0; j < 2; j++) { for (int j = 0; j < LARGTIC - 1; j++) {
if (grid[i][j] == "") { if (grid[j][i] == "") {
fin = false; fin = false;
} }
else { else {
fin = fin && (grid[i][j] == grid[i + 1][j]); fin = fin && (grid[j][i] == grid[j + 1][i]);
//cout << "comparaison de" << j << "," << i << " et " << j + 1 << "," << i << endl;
} }
} }
if (fin == true) { if (fin == true) {
return fin; return fin;
} }
} }
if (fin == true) {
return fin;
}
// Valide diagonale de 00, 11, 22 // Valide diagonale de 00, 11, 22
fin = true; fin = true;
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
@@ -286,10 +254,12 @@ bool verifFinMatch(std::string grid[][LARGTIC]) {
fin = fin && (grid[i][i] == grid[i - 1][i - 1]); fin = fin && (grid[i][i] == grid[i - 1][i - 1]);
} }
} }
if (fin == true) { if (fin == true) {
return fin; return fin;
} }
} }
}
void afficherFinMatch(string grid[][LARGTIC], int gagnant, int nbJoueurs) { void afficherFinMatch(string grid[][LARGTIC], int gagnant, int nbJoueurs) {
afficherImageTableau(grid, style); afficherImageTableau(grid, style);
@@ -298,35 +268,110 @@ void afficherFinMatch(string grid[][LARGTIC], int gagnant, int nbJoueurs) {
if (gagnant == 1) { if (gagnant == 1) {
cout << "\n\nLe joueur a gagne la partie!"; cout << "\n\nLe joueur a gagne la partie!";
} }
else { else if (gagnant == 2) {
cout << "\n\nL'ordinateur a gagne la partie!"; cout << "\n\nL'ordinateur a gagne la partie!";
} }
else {
cout << "\n\nPartie nulle!";
}
}
else if (nbJoueurs == 2){
if (gagnant == 1) {
cout << "\n\nJoueur 1 a gagne la partie!";
}
else if (gagnant == 2) {
cout << "\n\nJoueur 2 a gagne la partie!";
} }
else { else {
cout << "\n\nLe joueur " << gagnant cout << "\n\nPartie nulle!";
<< " a gagne la partie!"; }
}
}
int partieNulle(string grid[][LARGTIC], int compteur) {
int max = LARGTIC * LARGTIC;
int temp = gagnant;
if (compteur == max) {
gagnant = 3;
}
else {
gagnant = temp;
}
return gagnant;
}
// Joueur
void tourJoueur(string grid[][LARGTIC], int joueur) {
int verticale,
horizontale;
cout << "\n\nTour du joueur " << joueur << endl;
afficherImageTableau(grid, style);
cout << "\n\nEntrez une coordonnee verticale : ";
cin >> verticale;
while (verticale < 1 || verticale > LARGTIC) {
cout << "\n\nVeuillez entrer une donnee valide.\n"
<< "\n\nEntrez une coordonnee verticale : ";
cin >> verticale;
}
cout << "\nEntrez une coordonnee horizontale : ";
cin >> horizontale;
while (horizontale < 1 || horizontale > LARGTIC) {
cout << "\n\nVeuillez entrer une donnee valide.\n"
<< "\n\nEntrez une coordonnee horizontale : ";
cin >> horizontale;
}
verticale -= 1;
horizontale -= 1;
while (grid[verticale][horizontale] == iconJ1 || grid[verticale][horizontale] == iconJ2) {
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;
}
else {
grid[verticale][horizontale] = iconJ2;
} }
} }
//1 joueur //1 joueur
void jeuUnJoueur(string grid[][LARGTIC]) { void jeuUnJoueur(string grid[][LARGTIC]) {
bool fin; bool fin;
int gagnant;
int nbJoueurs = 1; int nbJoueurs = 1;
int compteur = 0;
cout << "Un joueur a ete choisi. Le joueur joue en premier."; cout << "Un joueur a ete choisi. Le joueur joue en premier.";
do { do {
tourJoueur(grid, 1); tourJoueur(grid, 1);
gagnant = 1; gagnant = 1;
fin = verifFinMatch(grid); compteur++;
fin = verifFinMatch(grid, compteur);
if (fin != true) { if (fin != true) {
tourOrdi(grid); tourOrdi(grid);
gagnant = 2; gagnant = 2;
system("PAUSE>nul"); system("PAUSE>nul");
fin = verifFinMatch(grid); compteur++;
fin = verifFinMatch(grid, compteur);
} }
} while (fin != true); } while (fin != true);
gagnant = partieNulle(grid, compteur);
afficherFinMatch(grid, gagnant, nbJoueurs); afficherFinMatch(grid, gagnant, nbJoueurs);
} }
@@ -336,9 +381,10 @@ void tourOrdi(string grid[][LARGTIC]) {
cout << "\n\nTour de l'ordinateur" << endl; cout << "\n\nTour de l'ordinateur" << endl;
do { do {
vertical = rand() % (3); vertical = rand() % (LARGTIC);
horizontal = rand() % (3); horizontal = rand() % (LARGTIC);
} while (grid[vertical][horizontal] != ""); } while (grid[vertical][horizontal] != "");
grid[vertical][horizontal] = iconJ2; grid[vertical][horizontal] = iconJ2;
afficherImageTableau(grid, style); afficherImageTableau(grid, style);
} }
@@ -346,26 +392,29 @@ void tourOrdi(string grid[][LARGTIC]) {
//2 joueurs //2 joueurs
void jeuDeuxJoueurs(string grid[][LARGTIC]) { void jeuDeuxJoueurs(string grid[][LARGTIC]) {
bool fin; bool fin;
int gagnant;
int nbJoueurs = 2; 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"; cout << "\nDeux joueurs a ete choisi. Les tours seront l'un a la suite de l'autre.\n\n";
do { do {
tourJoueur(grid, 1); tourJoueur(grid, 1);
gagnant = 1; gagnant = 1;
fin = verifFinMatch(grid); compteur++;
fin = verifFinMatch(grid, compteur);
if (fin != true) { if (fin != true) {
tourJoueur(grid, 2); tourJoueur(grid, 2);
gagnant = 2; gagnant = 2;
fin = verifFinMatch(grid); compteur++;
fin = verifFinMatch(grid, compteur);
} }
} while (fin != true); } while (fin != true);
gagnant = partieNulle(grid, compteur);
afficherFinMatch(grid, gagnant, nbJoueurs); afficherFinMatch(grid, gagnant, nbJoueurs);
} }
//Changer le th<74>me //Changer le th<74>me
void changerLeTheme(bool& theme) { void changerLeTheme() {
string grid[LARGTIC][LARGTIC]; string grid[LARGTIC][LARGTIC];
system("cls"); system("cls");
cout << endl << "Changer le theme du jeu Tic Tac Toe" << endl; cout << endl << "Changer le theme du jeu Tic Tac Toe" << endl;
@@ -379,9 +428,6 @@ void changerLeTheme(bool& theme) {
choix = toupper(_getche()); choix = toupper(_getche());
cout << endl; cout << endl;
if (choix >= 'A' && choix <= 'D') {
theme = true;
}
switch (choix) { switch (choix) {
case 'A': case 'A':
style = "themes/themeDefaut.txt"; style = "themes/themeDefaut.txt";

View File

@@ -24,8 +24,9 @@ void afficherImageMenu(std::fstream& monFlux);
//G<>n<EFBFBD>ral //G<>n<EFBFBD>ral
void afficherImageTableau(std::string grid[][LARGTIC], std::string style); void afficherImageTableau(std::string grid[][LARGTIC], std::string style);
void tourJoueur(std::string grid[][LARGTIC], int joueur); //pour savoir quel icon utiliser void tourJoueur(std::string grid[][LARGTIC], int joueur); //pour savoir quel icon utiliser
bool verifFinMatch(std::string grid[][LARGTIC]); bool verifFinMatch(std::string grid[][LARGTIC], int compteur);
void afficherFinMatch(std::string grid[][LARGTIC], int gagnant, int nbJoueurs); void afficherFinMatch(std::string grid[][LARGTIC], int gagnant, int nbJoueurs);
int partieNulle(std::string grid[][LARGTIC], int compteur);
//1 joueur //1 joueur
void jeuUnJoueur(std::string grid[][LARGTIC]); void jeuUnJoueur(std::string grid[][LARGTIC]);
@@ -35,4 +36,4 @@ void tourOrdi(std::string grid[][LARGTIC]);
void jeuDeuxJoueurs(std::string grid[][LARGTIC]); void jeuDeuxJoueurs(std::string grid[][LARGTIC]);
//Changer le th<74>me //Changer le th<74>me
void changerLeTheme(bool& theme); void changerLeTheme();

View File

@@ -13,7 +13,6 @@ using namespace std;
int main() { int main() {
srand(time(NULL)); srand(time(NULL));
bool theme = false;
char choix; char choix;
string grid[LARGTIC][LARGTIC]; string grid[LARGTIC][LARGTIC];
@@ -23,28 +22,17 @@ int main() {
switch (choix) { switch (choix) {
case 'A': case 'A':
if (theme == true) {
system("cls"); system("cls");
jeuUnJoueur(grid); jeuUnJoueur(grid);
}
else {
cout << "\n\nVeuillez choisir un theme d'abord.";
}
break; break;
case 'B': case 'B':
if (theme == true) {
system("cls"); system("cls");
jeuDeuxJoueurs(grid); jeuDeuxJoueurs(grid);
}
else {
cout << "\n\nVeuillez choisir un theme d'abord.";
}
break; break;
case 'C': case 'C':
changerLeTheme(theme); changerLeTheme();
theme = true;
break; break;
case 'Q': case 'Q':