Compare commits
12 Commits
a10845eff2
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b488389d8a | ||
|
|
c928b9483d | ||
|
|
ffe4af9f93 | ||
|
|
1d513239d2 | ||
|
|
d445cda491 | ||
|
|
b991978b6d | ||
|
|
a72da69ea7 | ||
|
|
008f2a3329 | ||
|
|
00217eb38a | ||
|
|
548c4ed27e | ||
|
|
1a8a5dd8d7 | ||
|
|
82cbc90c4c |
@@ -28,7 +28,7 @@ char carre = 219, choix;
|
|||||||
//<2F> faire : <20>galit<69> et entrer de coordonn<6E>e
|
//<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.
|
||||||
{
|
{
|
||||||
@@ -38,7 +38,7 @@ void ouvrirFichier(std::fstream& monFlux, std::string nomFichier) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void fermerFichier(std::fstream& monFlux) {
|
void fermerFichier(std::fstream & monFlux) {
|
||||||
monFlux.close();
|
monFlux.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,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()) {
|
||||||
@@ -183,46 +183,53 @@ void afficherImageTableau(std::string grid[][LARGTIC], std::string style) {
|
|||||||
SetConsoleOutputCP(codeConsole);
|
SetConsoleOutputCP(codeConsole);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool verifFinMatch(std::string grid[][LARGTIC]) {
|
bool verifFinMatch(std::string grid[][LARGTIC], int compteur) {
|
||||||
bool fin = false;
|
bool fin = false;
|
||||||
int max = LARGTIC * LARGTIC;
|
int max = LARGTIC * LARGTIC;
|
||||||
int compteur = 0;
|
|
||||||
if (compteur == max) {
|
if (compteur == max) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
compteur++;
|
// Valide horizontales 00, 01, 02 || 10, 11, 12 || 20, 21, 22
|
||||||
// Valide horizontales
|
for (int i = 0; i < LARGTIC; i++) {
|
||||||
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++) {
|
||||||
@@ -261,14 +268,37 @@ 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 {
|
||||||
|
cout << "\n\nPartie nulle!";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int partieNulle(string grid[][LARGTIC], int compteur) {
|
||||||
|
int max = LARGTIC * LARGTIC;
|
||||||
|
int temp = gagnant;
|
||||||
|
if (compteur == max) {
|
||||||
|
gagnant = 3;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cout << "\n\nLe joueur " << gagnant
|
gagnant = temp;
|
||||||
<< " a gagne la partie!";
|
|
||||||
}
|
}
|
||||||
|
return gagnant;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Joueur
|
// Joueur
|
||||||
@@ -301,7 +331,7 @@ void tourJoueur(string grid[][LARGTIC], int joueur) {
|
|||||||
horizontale -= 1;
|
horizontale -= 1;
|
||||||
|
|
||||||
while (grid[verticale][horizontale] == iconJ1 || grid[verticale][horizontale] == iconJ2) {
|
while (grid[verticale][horizontale] == iconJ1 || grid[verticale][horizontale] == iconJ2) {
|
||||||
|
|
||||||
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;
|
||||||
@@ -323,24 +353,25 @@ void tourJoueur(string grid[][LARGTIC], int joueur) {
|
|||||||
//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.";
|
||||||
|
|
||||||
//AJOUTER UN COMPTEUR DE TOURS POUR LES EXAEQUO!!!!!!
|
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,21 +392,24 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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], int gagnant);
|
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]);
|
||||||
|
|||||||
@@ -21,23 +21,23 @@ int main() {
|
|||||||
afficherMenu(choix);
|
afficherMenu(choix);
|
||||||
|
|
||||||
switch (choix) {
|
switch (choix) {
|
||||||
case 'A':
|
case 'A':
|
||||||
system("cls");
|
system("cls");
|
||||||
jeuUnJoueur(grid);
|
jeuUnJoueur(grid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'B':
|
case 'B':
|
||||||
system("cls");
|
system("cls");
|
||||||
jeuDeuxJoueurs(grid);
|
jeuDeuxJoueurs(grid);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'C':
|
case 'C':
|
||||||
changerLeTheme();
|
changerLeTheme();
|
||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user