From 4e2b25c9069228191766ef311587a2279c2a8713 Mon Sep 17 00:00:00 2001 From: William Date: Fri, 28 Nov 2025 09:36:43 -0500 Subject: [PATCH] rework de tout le code --- main.cpp | 51 ++++++++++++++++++++++++------------------------ mesFonctions.cpp | 37 ++++++++++++++++------------------- mesFonctions.h | 2 +- 3 files changed, 44 insertions(+), 46 deletions(-) diff --git a/main.cpp b/main.cpp index 78ecd67..0f5583f 100644 --- a/main.cpp +++ b/main.cpp @@ -25,6 +25,7 @@ int main() { bool quitter = false; //Quitter le jeu int nbMot3lettre = 15; //Nombre de mot présent dans le fichier int temp = 0; //TODO: Variable temporaire + string motRandom; // Mot random while (quitter == false) { curseur(false); @@ -34,33 +35,33 @@ int main() { int choixMenu = _getch(); switch (choixMenu) { - case '1': - afficherMenu("AfficheMenu/TaxonOption1.txt"); - delai(); - curseur(true); - system("cls"); - background(temp); - choisirMot("Mots/mot3lettres.txt", nbMot3lettre); - afficherMenuJouer(); - break; + case '1': + afficherMenu("AfficheMenu/TaxonOption1.txt"); + delai(); + curseur(true); + system("cls"); + background(temp); + motRandom = choisirMot("Mots/mot3lettres.txt", nbMot3lettre); + afficherMenuJouer(); + break; - case '2': - afficherMenu("AfficheMenu/TaxonOption2.txt"); - delai(); - curseur(true); - system("cls"); - temp = demanderBackground(); - background(temp); - break; + case '2': + afficherMenu("AfficheMenu/TaxonOption2.txt"); + delai(); + curseur(true); + system("cls"); + temp = demanderBackground(); + background(temp); + break; - case '3': - afficherMenu("AfficheMenu/TaxonOption3.txt"); - delai(); - background('1'); - afficherMenu("AfficheMenu/Quitter.txt"); - quitter = true; - break; - } + case '3': + afficherMenu("AfficheMenu/TaxonOption3.txt"); + delai(); + background('1'); + afficherMenu("AfficheMenu/Quitter.txt"); + quitter = true; + break; + } system("PAUSE>0"); system("cls"); diff --git a/mesFonctions.cpp b/mesFonctions.cpp index cb04105..f509966 100644 --- a/mesFonctions.cpp +++ b/mesFonctions.cpp @@ -87,18 +87,15 @@ void curseur(bool interrupteur) { 1 - JOUER ====================================*/ //fonction pour choisir le mot de facon random -void choisirMot(string nomFichier, int maximum) { - system("cls"); - +string choisirMot(string nomFichier, int maximum) {//Choisi un mot aléatoire et le renvoi int numeroLigne = rand() % (maximum)+1; - fstream monFlux; ouvrirFichier(monFlux, nomFichier); - string mot = goToLine(monFlux, numeroLigne); + string motRandom = goToLine(monFlux, numeroLigne); fermerFichier(monFlux); - + return motRandom; } -string goToLine(fstream& monFlux, int numeroLigne) { +string goToLine(fstream& monFlux, int numeroLigne) {//génère un nb aléatoire, et choisi une ligne associé pour un mot aléatoire. renvoi le mot choisi string mot; for (int i = 0; i < numeroLigne; i++) { getline(monFlux, mot); @@ -109,25 +106,25 @@ string goToLine(fstream& monFlux, int numeroLigne) { void afficherMenuJouer() { cout << setw(83) << "=============================================\n"; - string motPlayer; - for (int i = 0; i < 6; i++) + string motPlayer; + for (int nbTentative = 0; nbTentative < 6; nbTentative++) { do { - cout << setw(65) << "Tentative #" << i + 1 << endl; + cout << setw(65) << "Tentative #" << nbTentative + 1 << endl; cout << setw(69) << "Saisir votre mot : "; cin >> motPlayer; } while (motPlayer.length() > 3); if (dansListe(motPlayer)) { - + cout << "\na continue\n"; } else { - cout << setw(58) << "Mot n'est pas dans la liste"; - i--; + cout << setw(58) << "\nMot n'est pas dans la liste\n"; + nbTentative--; } } @@ -136,27 +133,27 @@ void afficherMenuJouer() cout << setw(66) << "Votre mot est : " << motPlayer; } + bool dansListe(string motPlayer) { fstream monFlux; ouvrirFichier(monFlux, "Mots/mot3lettres.txt"); - comparerMot(monFlux, motPlayer, 15); - -} -bool comparerMot(fstream& monFlux, string motPlayer, int numeroLigne) -{ string mot; - for (int i = 0; i < numeroLigne; i++) { + for (int i = 0; i < 15; i++) { //TODO changer le chiffre 15 par le numéro de ligne dans le ficher getline(monFlux, mot); + if (motPlayer == mot) { return true; } } - return false; + return false; + fermerFichier(monFlux); } + + /*==================================== 2 - OPTIONS ====================================*/ diff --git a/mesFonctions.h b/mesFonctions.h index af34d7d..699d8f4 100644 --- a/mesFonctions.h +++ b/mesFonctions.h @@ -29,7 +29,7 @@ int demanderBackground(); void backgroundDefault(); // Mot -void choisirMot(string nomFichier, int maximum); +string choisirMot(string nomFichier, int maximum); string goToLine(fstream& monFlux, int numeroLigne); void afficherMenuJouer();