Compare commits

..

24 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
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 127 additions and 80 deletions

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,8 +25,10 @@ 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) {
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.
{
@@ -35,7 +38,7 @@ void ouvrirFichier(std::fstream& monFlux, std::string nomFichier) {
}
}
void fermerFichier(std::fstream& monFlux) {
void fermerFichier(std::fstream & monFlux) {
monFlux.close();
}
@@ -60,7 +63,7 @@ void afficherMenu(char& choix) {
cout << endl;
}
void afficherImageMenu(std::fstream& monFlux) {
void afficherImageMenu(std::fstream & monFlux) {
int repet = 0;
if (monFlux) {
while (!monFlux.eof()) {
@@ -87,8 +90,8 @@ 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] = "";
}
}
@@ -180,41 +183,53 @@ 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;
// Valide horizontales
for (int i = 0; i < 2; i++) {
int max = LARGTIC * LARGTIC;
if (compteur == max) {
return true;
}
else {
// 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++) {
@@ -239,9 +254,11 @@ 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) {
@@ -251,14 +268,37 @@ 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
@@ -272,7 +312,7 @@ void tourJoueur(string grid[][LARGTIC], int joueur) {
cout << "\n\nEntrez une coordonnee verticale : ";
cin >> verticale;
while (verticale < 1 || verticale > 3) {
while (verticale < 1 || verticale > LARGTIC) {
cout << "\n\nVeuillez entrer une donnee valide.\n"
<< "\n\nEntrez une coordonnee verticale : ";
cin >> verticale;
@@ -281,7 +321,7 @@ void tourJoueur(string grid[][LARGTIC], int joueur) {
cout << "\nEntrez une coordonnee horizontale : ";
cin >> horizontale;
while (horizontale < 1 || horizontale > 3) {
while (horizontale < 1 || horizontale > LARGTIC) {
cout << "\n\nVeuillez entrer une donnee valide.\n"
<< "\n\nEntrez une coordonnee horizontale : ";
cin >> horizontale;
@@ -291,7 +331,7 @@ void tourJoueur(string grid[][LARGTIC], int joueur) {
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;
@@ -313,22 +353,25 @@ void tourJoueur(string grid[][LARGTIC], int joueur) {
//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>nul");
fin = verifFinMatch(grid);
compteur++;
fin = verifFinMatch(grid, compteur);
}
} while (fin != true);
gagnant = partieNulle(grid, compteur);
afficherFinMatch(grid, gagnant, nbJoueurs);
}
@@ -338,8 +381,8 @@ 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;
@@ -349,21 +392,24 @@ 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);
}

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]);