Simplification du système de couleur des lettres (tous est dans une fonction)

This commit is contained in:
2025-12-05 17:57:26 -05:00
parent 9dede478c0
commit eb24e9279d
3 changed files with 24 additions and 26 deletions

2
0
View File

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

View File

@@ -110,9 +110,6 @@ string goToLine(fstream& monFlux, int numeroLigne) {//g
void effectuerTour(int nbLettre) void effectuerTour(int nbLettre)
{ {
fstream monFlux;
string nomFichier;
HANDLE hconsole = GetStdHandle(STD_OUTPUT_HANDLE);//pour la couleur
string motRandom = choisirMot("Mots/mot3lettres.txt", NOMBREMOT3LETTRE); string motRandom = choisirMot("Mots/mot3lettres.txt", NOMBREMOT3LETTRE);
@@ -122,6 +119,7 @@ void effectuerTour(int nbLettre)
for (int nbTentative = 0; nbTentative < nbEssai; nbTentative++) for (int nbTentative = 0; nbTentative < nbEssai; nbTentative++)
{ {
string lettrePlayer;
do { do {
cout << setw(65) << "Tentative #" << nbTentative + 1 << endl; cout << setw(65) << "Tentative #" << nbTentative + 1 << endl;
cout << setw(69) << "Saisir votre mot : "; cout << setw(69) << "Saisir votre mot : ";
@@ -135,34 +133,16 @@ void effectuerTour(int nbLettre)
for (int i = 0; i < nbLettre; i++) { for (int i = 0; i < nbLettre; i++) {
if (lettreDansMot(motRandom, motPlayer, nbLettre, i) == BONNE_PLACE) { if (lettreDansMot(motRandom, motPlayer, nbLettre, i) == BONNE_PLACE) {
string lettrePlayer;
lettrePlayer = motPlayer[i]; lettrePlayer = motPlayer[i];
lettrePlayer.insert(0, "Alphabet/"); afficherMotPlayer(lettrePlayer, BONNE_PLACE);
lettrePlayer.append(".txt");
nomFichier = lettrePlayer;
ouvrirFichier(monFlux, nomFichier);
printLettre(monFlux, 1);
fermerFichier(monFlux);
} }
else if (lettreDansMot(motRandom, motPlayer, nbLettre, i) == MAUVAIS_PLACE) { else if (lettreDansMot(motRandom, motPlayer, nbLettre, i) == MAUVAIS_PLACE) {
string lettrePlayer;
lettrePlayer = motPlayer[i]; lettrePlayer = motPlayer[i];
lettrePlayer.insert(0, "Alphabet/"); afficherMotPlayer(lettrePlayer, MAUVAIS_PLACE);
lettrePlayer.append(".txt");
nomFichier = lettrePlayer;
ouvrirFichier(monFlux, nomFichier);
printLettre(monFlux, 2);
fermerFichier(monFlux);
} }
else { else {
string lettrePlayer;
lettrePlayer = motPlayer[i]; lettrePlayer = motPlayer[i];
lettrePlayer.insert(0, "Alphabet/"); afficherMotPlayer(lettrePlayer, PAS_LA);
lettrePlayer.append(".txt");
nomFichier = lettrePlayer;
ouvrirFichier(monFlux, nomFichier);
printLettre(monFlux, 3);
fermerFichier(monFlux);
} }
} }
cout << endl; cout << endl;
@@ -228,7 +208,24 @@ void choixNbEssai() {
/*==================================== /*====================================
Affichage couleur des lettres Affichage couleur des lettres
====================================*/ ====================================*/
void printLettre(fstream& monFlux, int positionLettre) { void afficherMotPlayer(string lettrePlayer, int positionLettre)
{
fstream monFlux;
string nomFichier;
HANDLE hconsole = GetStdHandle(STD_OUTPUT_HANDLE);//pour la couleur
lettrePlayer.insert(0, "Alphabet/");
lettrePlayer.append(".txt");
nomFichier = lettrePlayer;
ouvrirFichier(monFlux, nomFichier);
printLettre(monFlux, positionLettre);
fermerFichier(monFlux);
}
void printLettre(fstream& monFlux, int positionLettre)
{
int couleurLettre; int couleurLettre;
if (positionLettre == 1 /*Lettre bien plac<61>*/) if (positionLettre == 1 /*Lettre bien plac<61>*/)
{ {

View File

@@ -33,6 +33,7 @@ void effectuerTour(int nbLettre);
bool dansListe(string motPlayer); bool dansListe(string motPlayer);
bool comparerMot(fstream& monFlux, string motPlayer, int numeroLigne); bool comparerMot(fstream& monFlux, string motPlayer, int numeroLigne);
int lettreDansMot(string motRandom, string motPlayer, int nbLettre, int i); int lettreDansMot(string motRandom, string motPlayer, int nbLettre, int i);
void afficherMotPlayer(string lettrePlayer, int positionLettre);
void printLettre(fstream& monFlux, int positionLettre); void printLettre(fstream& monFlux, int positionLettre);
/*==================================== /*====================================