modifs du code avec les ajouts de Solène

This commit is contained in:
Lea
2025-11-21 14:38:06 -05:00
parent 977dd5ae9a
commit a15249f393
6 changed files with 108 additions and 54 deletions

1
TicTacToe/0 Normal file
View File

@@ -0,0 +1 @@
Appuyez sur une touche pour continuer...

View File

@@ -15,11 +15,14 @@ BUT : Fichier de fonctions Tic Tac Toe
using namespace std; using namespace std;
extern const int LARGTIC; extern const int LARGTIC;
const string ICONJ1 = { "X" };
const string ICONJ2 = { "O" };
fstream monFlux; fstream monFlux;
HANDLE hconsole = GetStdHandle(STD_OUTPUT_HANDLE); HANDLE hconsole = GetStdHandle(STD_OUTPUT_HANDLE);
char carre = 219, choix; char carre = 219, choix;
//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);
if (!monFlux) //On v<>rifie si le flux est "faux"/non fonctionnel. if (!monFlux) //On v<>rifie si le flux est "faux"/non fonctionnel.
@@ -34,6 +37,26 @@ void fermerFichier(std::fstream& monFlux) {
monFlux.close(); 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) { void afficherImageMenu(std::fstream& monFlux) {
int repet = 0; int repet = 0;
if (monFlux) { if (monFlux) {
@@ -59,6 +82,7 @@ void afficherImageMenu(std::fstream& monFlux) {
} }
} }
//G<>n<EFBFBD>ral (plusieurs options)
void afficherImageTableau(std::string grid[][LARGTIC]) { void afficherImageTableau(std::string grid[][LARGTIC]) {
SetConsoleOutputCP(CP_UTF8); SetConsoleOutputCP(CP_UTF8);
string emoteUp, 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 verifFinMatch(std::string grid[][LARGTIC]) {
bool fin = true; bool fin = true;
// Valide horizontales // Valide horizontales
@@ -166,38 +210,37 @@ bool verifFinMatch(std::string grid[][LARGTIC]) {
} }
} }
//Menu //1 joueur
void afficherMenu(char& choix) { void jeuUnJoueur(string grid[][LARGTIC]) {
system("cls"); bool fin;
//T I C T A C T O E cout << "\nUn joueur a ete choisi. Le joueur joue en premier.\n\n";
ouvrirFichier(monFlux, "menuTitre.txt");
afficherImageMenu(monFlux);
fermerFichier(monFlux);
// Menu do {
cout << endl << "MENU" << endl << "----------------------------------" << endl tourJoueur(grid, 1);
<< "A) 1 joueur" << endl tourOrdi(grid);
<< "B) 2 joueurs" << endl system("PAUSE>0");
<< "C) Montrer l'historique des scores" << endl fin = verifFinMatch(grid);
<< "D) Changer le style du jeu" << endl } while (fin = true);
<< "Q) Quitter" << endl << endl
<< "Quel est votre choix? ";
choix = toupper(_getche());
cout << endl;
} }
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]) { void jeuDeuxJoueurs(string grid[][LARGTIC]) {
bool fin; bool fin;
cout << endl << "Deux joueurs a ete choisi. Les tours seront l'un a la suite de l'autre." << endl << endl; cout << endl << "Deux joueurs a ete choisi. Les tours seront l'un a la suite de l'autre." << endl << endl;
do { do {
cout << "Tour du joueur" << endl; tourJoueur(grid, 1);
afficherImageTableau(grid); tourJoueur(grid, 2);
system("PAUSE");
fin = verifFinMatch(grid); fin = verifFinMatch(grid);
// la condition doit <20>tre une s<>rie de 3 chiffres // la condition doit <20>tre une s<>rie de 3 chiffres
} while (fin = true); } while (fin = true);

View File

@@ -9,18 +9,25 @@ BUT : D
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#pragma once #pragma once
const int LARGTIC = 3; const int LARGTIC = 3;
void afficherMenu(char& choix); //Fichiers
void afficherImageMenu(std::fstream& monFlux);
void ouvrirFichier(std::fstream& monFlux, std::string nomFichier); void ouvrirFichier(std::fstream& monFlux, std::string nomFichier);
void fermerFichier(std::fstream& monFlux); void fermerFichier(std::fstream& monFlux);
void initialiserGrid(std::string grid[][LARGTIC]); //Menu
void afficherMenu(char& choix);
void afficherImageMenu(std::fstream& monFlux);
//G<>n<EFBFBD>ral
void afficherImageTableau(std::string grid[][LARGTIC]); void afficherImageTableau(std::string grid[][LARGTIC]);
void tourJoueur(std::string grid[][LARGTIC], int joueur); //pour savoir quel icon utiliser
void jeuDeuxJoueurs(std::string grid[][LARGTIC]);
bool verifFinMatch(std::string grid[][LARGTIC]); 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]);

View File

@@ -10,42 +10,45 @@ BUT : Main pour le jeu Tic Tac Toe
#include "fonctions.h" #include "fonctions.h"
using namespace std; using namespace std;
extern const int LARGTIC; const string ICONJ1 = { "X" };
const string ICONJ2 = { "O" };
int main() { int main() {
char choix; srand(time(NULL));
string grid[LARGTIC][LARGTIC] = { "x", "o","x", "x", "o","x" , "x", "o","x" };
do { char choix;
afficherMenu(choix); string grid[LARGTIC][LARGTIC] = { " ", " ", " "," ", " ", " ", " ", " ", " "};
switch (choix) { do {
case 'A': afficherMenu(choix);
break; switch (choix) {
case 'A':
system("cls");
jeuUnJoueur(grid);
break;
case 'B': case 'B':
system("cls"); system("cls");
jeuDeuxJoueurs(grid); jeuDeuxJoueurs(grid);
break; break;
case 'C': case 'C':
break; break;
case 'D': case 'D':
break; break;
case 'Q': case 'Q':
cout << "Au revoir!"; cout << "\nAu revoir!";
break; break;
default:
cout << endl << "Saisissez un choix valide." << endl;
break;
}
system("PAUSE>0");
} while (choix != 'Q');
default:
cout << endl << "Saisissez un choix valide." << endl;
break;
}
system("PAUSE>0");
} while (choix != 'Q');
} }