Compare commits
41 Commits
1f71c6d5bb
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b488389d8a | ||
|
|
c928b9483d | ||
|
|
ffe4af9f93 | ||
|
|
1d513239d2 | ||
|
|
d445cda491 | ||
|
|
b991978b6d | ||
|
|
a72da69ea7 | ||
|
|
008f2a3329 | ||
|
|
00217eb38a | ||
|
|
548c4ed27e | ||
|
|
1a8a5dd8d7 | ||
|
|
82cbc90c4c | ||
|
|
a10845eff2 | ||
|
|
763aba1a13 | ||
|
|
1d28babc6e | ||
|
|
d6ead0a3e1 | ||
|
|
d4d337a648 | ||
|
|
7c539b8612 | ||
|
|
5ed7712c24 | ||
|
|
74ec166daf | ||
| 4740f1e484 | |||
|
|
d8889c6f4f | ||
|
|
3ac1c10f8a | ||
|
|
1124360a0f | ||
|
|
0d64de9007 | ||
|
|
76fda40b38 | ||
|
|
0bfac9b55e | ||
|
|
b94a724c06 | ||
|
|
fa685095fc | ||
|
|
0e1a8f0ab2 | ||
|
|
14b6bcdcb6 | ||
|
|
c9fea5f30d | ||
|
|
8fa7df8845 | ||
|
|
2729753e21 | ||
|
|
f7ae8f438c | ||
|
|
370b31ce46 | ||
|
|
b7dae93147 | ||
|
|
f60ebf6b42 | ||
|
|
b627bfe215 | ||
|
|
c03375610e | ||
|
|
614c11ec23 |
@@ -1 +1 @@
|
|||||||
Press any key to continue . . .
|
Appuyez sur une touche pour continuer...
|
||||||
|
|||||||
@@ -15,27 +15,30 @@ BUT : Fichier de fonctions Tic Tac Toe
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
extern const int LARGTIC;
|
extern const int LARGTIC;
|
||||||
string ICONJ1 = "X";
|
string iconJ1 = "X";
|
||||||
string ICONJ2 = "O";
|
string iconJ2 = "O";
|
||||||
string style = "themes/themeSea.txt";
|
int gagnant;
|
||||||
|
string style = "themes/themeDefaut.txt";
|
||||||
int codeConsole = 0;
|
int codeConsole = 0;
|
||||||
|
|
||||||
fstream monFlux;
|
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);
|
||||||
if (!monFlux) //On v<>rifie si le flux est "faux"/non fonctionnel.
|
if (!monFlux) //On v<>rifie si le flux est "faux"/non fonctionnel.
|
||||||
{
|
{
|
||||||
cout << "ERREUR: Impossible d'ouvrir le fichier!" << endl;
|
cout << "ERREUR: Impossible d'ouvrir le fichier!" << endl;
|
||||||
system("PAUSE>0");
|
system("PAUSE>null");
|
||||||
exit(1); //On quitte imm<6D>diatement le programme
|
exit(1); //On quitte imm<6D>diatement le programme
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void fermerFichier(std::fstream& monFlux) {
|
void fermerFichier(std::fstream & monFlux) {
|
||||||
monFlux.close();
|
monFlux.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +63,7 @@ void afficherMenu(char& choix) {
|
|||||||
cout << endl;
|
cout << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void afficherImageMenu(std::fstream& monFlux) {
|
void afficherImageMenu(std::fstream & monFlux) {
|
||||||
int repet = 0;
|
int repet = 0;
|
||||||
if (monFlux) {
|
if (monFlux) {
|
||||||
while (!monFlux.eof()) {
|
while (!monFlux.eof()) {
|
||||||
@@ -86,19 +89,27 @@ void afficherImageMenu(std::fstream& monFlux) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//G<>n<EFBFBD>ral (plusieurs options)
|
//G<>n<EFBFBD>ral (plusieurs options)
|
||||||
|
void initGrid(string grid[][LARGTIC]) {
|
||||||
|
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) {
|
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,
|
||||||
iconJ1,
|
emoteJ1,
|
||||||
iconJ2;
|
emoteJ2;
|
||||||
|
|
||||||
// Faire une fonction pour retenir le th<74>me s<>lectionn<6E> par le joueur!!!!
|
// Faire une fonction pour retenir le th<74>me s<>lectionn<6E> par le joueur!!!!
|
||||||
|
|
||||||
ouvrirFichier(monFlux, style);
|
ouvrirFichier(monFlux, style);
|
||||||
if (monFlux) {
|
if (monFlux) {
|
||||||
while (!monFlux.eof()) {
|
while (!monFlux.eof()) {
|
||||||
monFlux >> emoteUp >> emoteDown >> ICONJ1 >> ICONJ2;
|
monFlux >> emoteUp >> emoteDown >> emoteJ1 >> emoteJ2;
|
||||||
}
|
}
|
||||||
monFlux.close();
|
monFlux.close();
|
||||||
cout << endl;
|
cout << endl;
|
||||||
@@ -109,8 +120,8 @@ void afficherImageTableau(std::string grid[][LARGTIC], std::string style) {
|
|||||||
}
|
}
|
||||||
fermerFichier(monFlux);
|
fermerFichier(monFlux);
|
||||||
|
|
||||||
grid[0][0] = ICONJ1;
|
// Lignes de code pour faire afficher le Tic Tac Toe une fois que les symboles ont <20>t<EFBFBD> ajout<75>s
|
||||||
grid[0][1] = ICONJ2;
|
cout << "Joueur 1: " << emoteJ1 << " Joueur 2: " << emoteJ2 << endl << endl;
|
||||||
|
|
||||||
// Lignes de code pour faire afficher le Tic Tac Toe une fois que les symboles ont <20>t<EFBFBD> ajout<75>s
|
// Lignes de code pour faire afficher le Tic Tac Toe une fois que les symboles ont <20>t<EFBFBD> ajout<75>s
|
||||||
cout << " ";
|
cout << " ";
|
||||||
@@ -132,21 +143,32 @@ void afficherImageTableau(std::string grid[][LARGTIC], std::string style) {
|
|||||||
for (int j = 0; j < 3; j++) {
|
for (int j = 0; j < 3; j++) {
|
||||||
cout << " ";
|
cout << " ";
|
||||||
}
|
}
|
||||||
|
cout << " ";
|
||||||
}
|
}
|
||||||
cout << "|" << endl << " " << k + 1 << " ";
|
cout << "|" << endl << " " << k + 1 << " ";
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < LARGTIC; i++) {
|
for (int i = 0; i < LARGTIC; i++) {
|
||||||
cout << "|" << " " << grid[k][i] << " ";
|
cout << "|" << " ";
|
||||||
|
if (grid[k][i] == "X") {
|
||||||
|
cout << emoteJ1;
|
||||||
|
}
|
||||||
|
else if (grid[k][i] == "O") {
|
||||||
|
cout << emoteJ2;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
cout << " ";
|
||||||
|
}
|
||||||
|
cout << " ";
|
||||||
}
|
}
|
||||||
cout << " |" << endl << " ";
|
cout << "|" << endl << " ";
|
||||||
|
|
||||||
for (int i = 0; i < LARGTIC; i++) {
|
for (int i = 0; i < LARGTIC; i++) {
|
||||||
cout << "|";
|
cout << "|";
|
||||||
for (int j = 0; j < 3; j++) {
|
for (int j = 0; j < 3; j++) {
|
||||||
cout << " ";
|
cout << " ";
|
||||||
}
|
}
|
||||||
|
cout << " ";
|
||||||
}
|
}
|
||||||
cout << "|" << endl << " ";
|
cout << "|" << endl << " ";
|
||||||
|
|
||||||
@@ -161,6 +183,125 @@ void afficherImageTableau(std::string grid[][LARGTIC], std::string style) {
|
|||||||
SetConsoleOutputCP(codeConsole);
|
SetConsoleOutputCP(codeConsole);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool verifFinMatch(std::string grid[][LARGTIC], int compteur) {
|
||||||
|
bool fin = false;
|
||||||
|
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 < 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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 < LARGTIC - 1; j++) {
|
||||||
|
if (grid[j][i] == "") {
|
||||||
|
fin = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
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++) {
|
||||||
|
if (grid[i][i] == "") {
|
||||||
|
fin = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fin = fin && (grid[i][i] == grid[i + 1][i + 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (fin == true) {
|
||||||
|
return fin;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Valide diagonale 02, 11, 20
|
||||||
|
fin = true;
|
||||||
|
for (int i = 2; i > 0; i--) {
|
||||||
|
if (grid[i][i] == "") {
|
||||||
|
fin = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
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);
|
||||||
|
|
||||||
|
if (nbJoueurs == 1) {
|
||||||
|
if (gagnant == 1) {
|
||||||
|
cout << "\n\nLe joueur a gagne la partie!";
|
||||||
|
}
|
||||||
|
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\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) {
|
void tourJoueur(string grid[][LARGTIC], int joueur) {
|
||||||
int verticale,
|
int verticale,
|
||||||
horizontale;
|
horizontale;
|
||||||
@@ -171,7 +312,7 @@ void tourJoueur(string grid[][LARGTIC], int joueur) {
|
|||||||
cout << "\n\nEntrez une coordonnee verticale : ";
|
cout << "\n\nEntrez une coordonnee verticale : ";
|
||||||
cin >> verticale;
|
cin >> verticale;
|
||||||
|
|
||||||
while (verticale < 1 || verticale > 3) {
|
while (verticale < 1 || verticale > LARGTIC) {
|
||||||
cout << "\n\nVeuillez entrer une donnee valide.\n"
|
cout << "\n\nVeuillez entrer une donnee valide.\n"
|
||||||
<< "\n\nEntrez une coordonnee verticale : ";
|
<< "\n\nEntrez une coordonnee verticale : ";
|
||||||
cin >> verticale;
|
cin >> verticale;
|
||||||
@@ -180,7 +321,7 @@ void tourJoueur(string grid[][LARGTIC], int joueur) {
|
|||||||
cout << "\nEntrez une coordonnee horizontale : ";
|
cout << "\nEntrez une coordonnee horizontale : ";
|
||||||
cin >> horizontale;
|
cin >> horizontale;
|
||||||
|
|
||||||
while (horizontale < 1 || horizontale > 3) {
|
while (horizontale < 1 || horizontale > LARGTIC) {
|
||||||
cout << "\n\nVeuillez entrer une donnee valide.\n"
|
cout << "\n\nVeuillez entrer une donnee valide.\n"
|
||||||
<< "\n\nEntrez une coordonnee horizontale : ";
|
<< "\n\nEntrez une coordonnee horizontale : ";
|
||||||
cin >> horizontale;
|
cin >> horizontale;
|
||||||
@@ -189,122 +330,48 @@ void tourJoueur(string grid[][LARGTIC], int joueur) {
|
|||||||
verticale -= 1;
|
verticale -= 1;
|
||||||
horizontale -= 1;
|
horizontale -= 1;
|
||||||
|
|
||||||
while (grid[verticale][horizontale] == ICONJ1 || grid[verticale][horizontale] == ICONJ2) {
|
while (grid[verticale][horizontale] == iconJ1 || grid[verticale][horizontale] == iconJ2) {
|
||||||
// V<>RIFIER LE CIN D'ERREUR!!!!!
|
|
||||||
cout << "\n\nVeuillez choisir une case vide.\n"
|
cout << "\n\nVeuillez choisir une case vide.\n"
|
||||||
<< "\n\nEntrez une coordonnee verticale : ";
|
<< "\n\nEntrez une coordonnee verticale : ";
|
||||||
cin >> verticale;
|
cin >> verticale;
|
||||||
cout << "\nEntrez une coordonnee horizontale : ";
|
cout << "\nEntrez une coordonnee horizontale : ";
|
||||||
cin >> horizontale;
|
cin >> horizontale;
|
||||||
|
|
||||||
|
verticale--;
|
||||||
|
horizontale--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (joueur == 1) {
|
if (joueur == 1) {
|
||||||
grid[verticale][horizontale] = ICONJ1;
|
grid[verticale][horizontale] = iconJ1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
grid[verticale][horizontale] = ICONJ2;
|
grid[verticale][horizontale] = iconJ2;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool verifFinMatch(std::string grid[][LARGTIC]) {
|
|
||||||
bool fin = false;
|
|
||||||
|
|
||||||
// Valide horizontales
|
|
||||||
for (int i = 0; i < 2; i++) {
|
|
||||||
fin = true;
|
|
||||||
for (int j = 0; j < 2; j++) {
|
|
||||||
if (grid[i][j] == " ") {
|
|
||||||
fin = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
else {
|
|
||||||
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++) {
|
|
||||||
if (grid[i][j] == " ") {
|
|
||||||
fin = false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
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++) {
|
|
||||||
if (grid[i][i] == " ") {
|
|
||||||
fin = false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fin = fin && (grid[i][i] == grid[i + 1][i + 1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (fin == true) {
|
|
||||||
return fin;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Valide diagonale 02, 11, 20
|
|
||||||
fin = true;
|
|
||||||
for (int i = 2; i > 0; i--) {
|
|
||||||
if (grid[i][i] == " ") {
|
|
||||||
fin = false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
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);
|
|
||||||
|
|
||||||
if (nbJoueurs == 1) {
|
|
||||||
if (gagnant == 1) {
|
|
||||||
cout << "\n\nLe joueur a gagne la partie!";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cout << "\n\nL'ordinateur a gagne la partie!";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
cout << "\n\nLe joueur " << gagnant
|
|
||||||
<< " a gagne la partie!";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//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>0");
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -314,31 +381,35 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
//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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -346,41 +417,115 @@ void jeuDeuxJoueurs(string grid[][LARGTIC]) {
|
|||||||
void changerLeTheme() {
|
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;
|
||||||
do {
|
do {
|
||||||
cout << endl << "Changer le theme du jeu Tic Tac Toe" << endl
|
cout << endl
|
||||||
<< "Options des styles: " << "\nA) Ocean"
|
<< "Options des styles: " << "\n\n-------------------------------------"
|
||||||
|
<< "\nA) Par defaut"
|
||||||
<< "\nB) Fantaisie" << "\nC) Espace"
|
<< "\nB) Fantaisie" << "\nC) Espace"
|
||||||
<< "\nD) Animaux" << "\nQ) Revenir en arriere"
|
<< "\nD) Animaux" << "\nE) Ocean" << "\nQ) Revenir en arriere"
|
||||||
<< "\nChoisir une option: ";
|
<< "\n\nChoisir une option: ";
|
||||||
choix = toupper(_getche());
|
choix = toupper(_getche());
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
switch (choix) {
|
switch (choix) {
|
||||||
case 'A':
|
case 'A':
|
||||||
style = "themes/themeSea.txt";
|
style = "themes/themeDefaut.txt";
|
||||||
afficherImageTableau(grid, style);
|
afficherImageTableau(grid, style);
|
||||||
|
|
||||||
|
cout << "\n\nVoulez vous utiliser ce theme? ";
|
||||||
|
choix = toupper(_getche());
|
||||||
|
|
||||||
|
if (choix == 'O') {
|
||||||
|
style = "themes/themeDefaut.txt";
|
||||||
|
cout << "\nTheme choisi. \n";
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
style = "themes/themeDefaut.txt";
|
||||||
|
cout << "\nLe theme par defaut sera quand meme choisi. \n";
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'B':
|
case 'B':
|
||||||
style = "themes/themeFantasy.txt";
|
style = "themes/themeFantasy.txt";
|
||||||
afficherImageTableau(grid, style);
|
afficherImageTableau(grid, style);
|
||||||
|
|
||||||
|
cout << "\n\nVoulez vous utiliser ce theme? ";
|
||||||
|
choix = toupper(_getche());
|
||||||
|
|
||||||
|
if (choix == 'O') {
|
||||||
|
style = "themes/themeFantasy.txt";
|
||||||
|
cout << "\nTheme choisi. \n";
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
style = "themes/themeDefaut.txt";
|
||||||
|
cout << "\nLe theme par defaut sera choisi.\n";
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'C':
|
case 'C':
|
||||||
style = "themes/themeEspace.txt";
|
style = "themes/themeEspace.txt";
|
||||||
afficherImageTableau(grid, style);
|
afficherImageTableau(grid, style);
|
||||||
|
|
||||||
|
cout << "\n\nVoulez vous utiliser ce theme? ";
|
||||||
|
choix = toupper(_getche());
|
||||||
|
|
||||||
|
if (choix == 'O') {
|
||||||
|
style = "themes/themeEspace.txt";
|
||||||
|
cout << "\nTheme choisi. \n";
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
style = "themes/themeDefaut.txt";
|
||||||
|
cout << "\nLe theme par defaut sera choisi.\n";
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'D':
|
case 'D':
|
||||||
style = "themes/themeAnimaux.txt";
|
style = "themes/themeAnimaux.txt";
|
||||||
afficherImageTableau(grid, style);
|
afficherImageTableau(grid, style);
|
||||||
|
|
||||||
|
cout << "\n\nVoulez vous utiliser ce theme? ";
|
||||||
|
choix = toupper(_getche());
|
||||||
|
|
||||||
|
if (choix == 'O') {
|
||||||
|
style = "themes/themeAnimaux.txt";
|
||||||
|
cout << "\nTheme choisi. \n";
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
style = "themes/themeDefaut.txt";
|
||||||
|
cout << "\nLe theme par defaut sera choisi.\n";
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'E':
|
||||||
|
style = "themes/themeSea.txt";
|
||||||
|
afficherImageTableau(grid, style);
|
||||||
|
|
||||||
|
cout << "\n\nVoulez vous utiliser ce theme? ";
|
||||||
|
choix = toupper(_getche());
|
||||||
|
|
||||||
|
if (choix == 'O') {
|
||||||
|
style = "themes/themeSea.txt";
|
||||||
|
cout << "\nTheme choisi. \n";
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
style = "themes/themeDefaut.txt";
|
||||||
|
cout << "\nLe theme par defaut sera choisi.\n";
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'Q':
|
case 'Q':
|
||||||
|
cout << "\n\nRetour au menu principal";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
cout << "\nChoisir une option valide. \n";
|
cout << "\n\nChoisir une option valide. \n";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (choix != 'Q');
|
} while (choix != 'Q');
|
||||||
|
|||||||
@@ -17,15 +17,16 @@ void ouvrirFichier(std::fstream& monFlux, std::string nomFichier);
|
|||||||
void fermerFichier(std::fstream& monFlux);
|
void fermerFichier(std::fstream& monFlux);
|
||||||
|
|
||||||
//Menu
|
//Menu
|
||||||
|
void initGrid(std::string grid[][LARGTIC]);
|
||||||
void afficherMenu(char& choix);
|
void afficherMenu(char& choix);
|
||||||
void afficherImageMenu(std::fstream& monFlux);
|
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 changerLeTheme();
|
|
||||||
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,5 +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();
|
void changerLeTheme();
|
||||||
|
|
||||||
@@ -10,53 +10,39 @@ BUT : Main pour le jeu Tic Tac Toe
|
|||||||
#include "fonctions.h"
|
#include "fonctions.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
const string ICONJ1 = "X";
|
|
||||||
const string ICONJ2 = "O";
|
|
||||||
|
|
||||||
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];
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
initGrid(grid);
|
||||||
afficherMenu(choix);
|
afficherMenu(choix);
|
||||||
|
|
||||||
switch (choix) {
|
switch (choix) {
|
||||||
case 'A':
|
case 'A':
|
||||||
if (theme == true) {
|
|
||||||
system("cls");
|
system("cls");
|
||||||
jeuUnJoueur(grid);
|
jeuUnJoueur(grid);
|
||||||
}
|
break;
|
||||||
else {
|
|
||||||
cout << "\n\nVeuillez choisir un theme d'abord.";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'B':
|
case 'B':
|
||||||
if (theme == true) {
|
|
||||||
system("cls");
|
system("cls");
|
||||||
jeuDeuxJoueurs(grid);
|
jeuDeuxJoueurs(grid);
|
||||||
}
|
break;
|
||||||
else {
|
|
||||||
cout << "\n\nVeuillez choisir un theme d'abord.";
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'C':
|
case 'C':
|
||||||
changerLeTheme();
|
changerLeTheme();
|
||||||
theme = true;
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case 'Q':
|
case 'Q':
|
||||||
cout << "\nAu revoir!";
|
cout << "\nAu revoir!";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
cout << endl << "Saisissez un choix valide." << endl;
|
cout << endl << "Saisissez un choix valide." << endl;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
system("PAUSE>0");
|
system("PAUSE>nul");
|
||||||
} while (choix != 'Q');
|
} while (choix != 'Q');
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user