Compare commits

...

31 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
Lea
0d64de9007 modification des system("PAUSE>0"), 0 changé pour nul 2025-11-28 09:22:10 -05:00
Sunny
76fda40b38 Merge branch 'main' of https://gitea.zkd.ca/DEV_WEB/TicTacToe 2025-11-28 09:20:34 -05:00
Lea
0bfac9b55e fin de mise en page pour choix du thème 2025-11-28 09:20:21 -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
Lea
0e1a8f0ab2 mise en forme plus ample du choix de thème 2025-11-28 09:10:03 -05:00
Lea
14b6bcdcb6 ajout de initgrid dans le main 2025-11-28 08:56:28 -05:00
4 changed files with 186 additions and 146 deletions

View File

@@ -1 +1 @@
Press any key to continue . . .
Appuyez sur une touche pour continuer...

View File

@@ -17,6 +17,7 @@ using namespace std;
extern const int LARGTIC;
string iconJ1 = "X";
string iconJ2 = "O";
int gagnant;
string style = "themes/themeDefaut.txt";
int codeConsole = 0;
@@ -24,13 +25,15 @@ fstream monFlux;
HANDLE hconsole = GetStdHandle(STD_OUTPUT_HANDLE);
char carre = 219, choix;
//<2F> faire : <20>galit<69> et entrer de coordonn<6E>e
//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.
{
cout << "ERREUR: Impossible d'ouvrir le fichier!" << endl;
system("PAUSE>0");
system("PAUSE>null");
exit(1); //On quitte imm<6D>diatement le programme
}
}
@@ -87,15 +90,15 @@ void afficherImageMenu(std::fstream& monFlux) {
//G<>n<EFBFBD>ral (plusieurs options)
void initGrid(string grid[][LARGTIC]) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
for (int i = 0; i < LARGTIC; i++) {
for (int j = 0; j < LARGTIC; j++) {
grid[i][j] = "";
}
}
}
void afficherImageTableau(std::string grid[][LARGTIC], std::string style) {
SetConsoleOutputCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8); //affiche les <20>mojis
string emoteUp,
emoteDown,
emoteJ1,
@@ -180,88 +183,53 @@ void afficherImageTableau(std::string grid[][LARGTIC], std::string style) {
SetConsoleOutputCP(codeConsole);
}
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 > 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;
bool verifFinMatch(std::string grid[][LARGTIC], int compteur) {
bool fin = false;
int max = LARGTIC * LARGTIC;
if (compteur == max) {
return true;
}
else {
grid[verticale][horizontale] = iconJ2;
}
}
bool verifFinMatch(std::string grid[][LARGTIC]) {
bool fin = false;
// Valide horizontales
for (int i = 0; i < 2; i++) {
// Valide horizontales 00, 01, 02 || 10, 11, 12 || 20, 21, 22
for (int i = 0; i < LARGTIC; i++) {
fin = true;
for (int j = 0; j < 2; j++) {
for (int j = 0; j < LARGTIC - 1; j++) {
if (grid[i][j] == "") {
fin = false;
}
else {
fin = fin && (grid[i][j] == grid[i][j + 1]);
//cout << "comparaison de " << i << "," << j << " et " << i << "," << j+1 << endl;
}
}
if (fin == true) {
return fin;
}
}
// Valide verticales
for (int i = 0; i < 2; i++) {
if (fin == true) {
return fin;
}
// Valide verticales 00, 10, 20 || 01, 11, 21 || 02, 12, 22
for (int i = 0; i < LARGTIC; i++) {
fin = true;
for (int j = 0; j < 2; j++) {
if (grid[i][j] == "") {
for (int j = 0; j < LARGTIC - 1; j++) {
if (grid[j][i] == "") {
fin = false;
}
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) {
return fin;
}
}
if (fin == true) {
return fin;
}
// Valide diagonale de 00, 11, 22
fin = true;
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]);
}
}
if (fin == true) {
return fin;
}
}
}
void afficherFinMatch(string grid[][LARGTIC], int gagnant, int nbJoueurs) {
afficherImageTableau(grid, style);
@@ -298,35 +268,110 @@ 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 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 {
cout << "\n\nLe joueur " << gagnant
<< " a gagne la partie!";
cout << "\n\nPartie nulle!";
}
}
}
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
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.";
do {
tourJoueur(grid, 1);
gagnant = 1;
fin = verifFinMatch(grid);
compteur++;
fin = verifFinMatch(grid, compteur);
if (fin != true) {
tourOrdi(grid);
gagnant = 2;
system("PAUSE>0");
fin = verifFinMatch(grid);
system("PAUSE>nul");
compteur++;
fin = verifFinMatch(grid, compteur);
}
} while (fin != true);
gagnant = partieNulle(grid, compteur);
afficherFinMatch(grid, gagnant, nbJoueurs);
}
@@ -336,9 +381,10 @@ void tourOrdi(string grid[][LARGTIC]) {
cout << "\n\nTour de l'ordinateur" << endl;
do {
vertical = rand() % (3);
horizontal = rand() % (3);
vertical = rand() % (LARGTIC);
horizontal = rand() % (LARGTIC);
} while (grid[vertical][horizontal] != "");
grid[vertical][horizontal] = iconJ2;
afficherImageTableau(grid, style);
}
@@ -346,56 +392,58 @@ void tourOrdi(string grid[][LARGTIC]) {
//2 joueurs
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);
compteur++;
fin = verifFinMatch(grid, compteur);
if (fin != true) {
tourJoueur(grid, 2);
gagnant = 2;
fin = verifFinMatch(grid);
compteur++;
fin = verifFinMatch(grid, compteur);
}
} while (fin != true);
gagnant = partieNulle(grid, compteur);
afficherFinMatch(grid, gagnant, nbJoueurs);
}
//Changer le th<74>me
void changerLeTheme(bool& theme) {
void changerLeTheme() {
string grid[LARGTIC][LARGTIC];
system("cls");
cout << endl << "Changer le theme du jeu Tic Tac Toe" << endl;
do {
cout << endl << "Changer le theme du jeu Tic Tac Toe" << endl
<< "Options des styles: " << "\n-------------------------------------"
<< "\nA) Ocean"
cout << endl
<< "Options des styles: " << "\n\n-------------------------------------"
<< "\nA) Par defaut"
<< "\nB) Fantaisie" << "\nC) Espace"
<< "\nD) Animaux" << "\nE) Defaut" << "\nQ) Revenir en arriere"
<< "\nChoisir une option: ";
<< "\nD) Animaux" << "\nE) Ocean" << "\nQ) Revenir en arriere"
<< "\n\nChoisir une option: ";
choix = toupper(_getche());
cout << endl;
if (choix >= 'A' && choix <= 'D') {
theme = true;
}
switch (choix) {
case 'A':
style = "themes/themeSea.txt";
style = "themes/themeDefaut.txt";
afficherImageTableau(grid, style);
cout << "\n\nVoulez vous utiliser ce theme? ";
choix = toupper(_getche());
if (choix == 'O') {
style = "themes/themeSea.txt";
style = "themes/themeDefaut.txt";
cout << "\nTheme choisi. \n";
}
else {
style = "themes/themeDefaut.txt";
cout << "Le theme par defaut sera choisi.";
cout << "\nLe theme par defaut sera quand meme choisi. \n";
}
break;
@@ -409,11 +457,12 @@ void changerLeTheme(bool& theme) {
if (choix == 'O') {
style = "themes/themeFantasy.txt";
cout << "\nTheme choisi. \n";
}
else {
style = "themes/themeDefaut.txt";
cout << "Le theme par defaut sera choisi.";
cout << "\nLe theme par defaut sera choisi.\n";
}
break;
@@ -426,11 +475,12 @@ void changerLeTheme(bool& theme) {
if (choix == 'O') {
style = "themes/themeEspace.txt";
cout << "\nTheme choisi. \n";
}
else {
style = "themes/themeDefaut.txt";
cout << "Le theme par defaut sera choisi.";
cout << "\nLe theme par defaut sera choisi.\n";
}
break;
@@ -443,36 +493,39 @@ void changerLeTheme(bool& theme) {
if (choix == 'O') {
style = "themes/themeAnimaux.txt";
cout << "\nTheme choisi. \n";
}
else {
style = "themes/themeDefaut.txt";
cout << "Le theme par defaut sera choisi.";
cout << "\nLe theme par defaut sera choisi.\n";
}
break;
case 'E':
style = "themes/themeDefaut.txt";
style = "themes/themeSea.txt";
afficherImageTableau(grid, style);
cout << "\n\nVoulez vous utiliser ce theme? ";
choix = toupper(_getche());
if (choix == 'O') {
style = "themes/themeDefaut.txt";
style = "themes/themeSea.txt";
cout << "\nTheme choisi. \n";
}
else {
style = "themes/themeDefaut.txt";
cout << "Le theme par defaut sera quand meme choisi.";
cout << "\nLe theme par defaut sera choisi.\n";
}
break;
case 'Q':
cout << "\n\nRetour au menu principal";
break;
default:
cout << "\nChoisir une option valide. \n";
cout << "\n\nChoisir une option valide. \n";
break;
}
} while (choix != 'Q');

View File

@@ -24,8 +24,9 @@ void afficherImageMenu(std::fstream& monFlux);
//G<>n<EFBFBD>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]);
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]);
@@ -35,4 +36,4 @@ void tourOrdi(std::string grid[][LARGTIC]);
void jeuDeuxJoueurs(std::string grid[][LARGTIC]);
//Changer le th<74>me
void changerLeTheme(bool& theme);
void changerLeTheme();

View File

@@ -10,43 +10,29 @@ BUT : Main pour le jeu Tic Tac Toe
#include "fonctions.h"
using namespace std;
const string ICONJ1 = "X";
const string ICONJ2 = "O";
int main() {
srand(time(NULL));
bool theme = false;
char choix;
string grid[LARGTIC][LARGTIC];
do {
initGrid(grid);
afficherMenu(choix);
switch (choix) {
case 'A':
if (theme == true) {
system("cls");
jeuUnJoueur(grid);
}
else {
cout << "\n\nVeuillez choisir un theme d'abord.";
}
break;
case 'B':
if (theme == true) {
system("cls");
jeuDeuxJoueurs(grid);
}
else {
cout << "\n\nVeuillez choisir un theme d'abord.";
}
break;
case 'C':
changerLeTheme(theme);
theme = true;
changerLeTheme();
break;
case 'Q':