corirger lettre
This commit is contained in:
@@ -23,6 +23,7 @@ using namespace std::chrono_literals;
|
||||
|
||||
#include <limits> //Sources : https://www.tutorialspoint.com/cpp_standard_library/limits.htm et https://stackoverflow.com/questions/2158943/split-string-into-array-of-chars
|
||||
|
||||
const int BONNE_PLACE = 1, MAUVAIS_PLACE = 2, PAS_LA = 3;
|
||||
|
||||
/*====================================
|
||||
MENU
|
||||
@@ -106,6 +107,8 @@ string goToLine(fstream& monFlux, int numeroLigne) {//g
|
||||
|
||||
void effectuerTour(int nbLettre)
|
||||
{
|
||||
fstream monFlux;
|
||||
string nomFichier;
|
||||
HANDLE hconsole = GetStdHandle(STD_OUTPUT_HANDLE);//pour la couleur
|
||||
|
||||
string motRandom = choisirMot("Mots/mot3lettres.txt", 15);
|
||||
@@ -128,24 +131,35 @@ void effectuerTour(int nbLettre)
|
||||
|
||||
for (int i = 0; i < nbLettre; i++) {
|
||||
|
||||
if (lettreDansMot(motRandom, motPlayer, nbLettre) == 1) {
|
||||
|
||||
SetConsoleTextAttribute(hconsole, 2);//mettre la lettre en vert
|
||||
cout << motPlayer[i];
|
||||
SetConsoleTextAttribute(hconsole, 15);//remettre le texte en blanc
|
||||
if (lettreDansMot(motRandom, motPlayer, nbLettre, i) == BONNE_PLACE) {
|
||||
string lettrePlayer;
|
||||
lettrePlayer = motPlayer[i];
|
||||
lettrePlayer.insert(0, "Alphabet/Normal/");
|
||||
lettrePlayer.insert(17, ".txt");
|
||||
nomFichier = lettrePlayer;
|
||||
ouvrirFichier(monFlux, nomFichier);
|
||||
printLettre(monFlux, 1);
|
||||
fermerFichier(monFlux);
|
||||
}
|
||||
else if (lettreDansMot(motRandom, motPlayer, nbLettre) == 2) {
|
||||
|
||||
SetConsoleTextAttribute(hconsole, 6);//mettre la lettre en jaune
|
||||
cout << motPlayer[i];
|
||||
SetConsoleTextAttribute(hconsole, 15);//remettre le texte en blanc
|
||||
|
||||
else if (lettreDansMot(motRandom, motPlayer, nbLettre, i) == MAUVAIS_PLACE) {
|
||||
string lettrePlayer;
|
||||
lettrePlayer = motPlayer[i];
|
||||
lettrePlayer.insert(0, "Alphabet/Normal/");
|
||||
lettrePlayer.insert(17, ".txt");
|
||||
nomFichier = lettrePlayer;
|
||||
ouvrirFichier(monFlux, nomFichier);
|
||||
printLettre(monFlux, 2);
|
||||
fermerFichier(monFlux);
|
||||
}
|
||||
else {
|
||||
|
||||
SetConsoleTextAttribute(hconsole, 8);//mettre la lettre en gris
|
||||
cout << motPlayer[i];
|
||||
SetConsoleTextAttribute(hconsole, 15);//remettre le texte en blanc
|
||||
string lettrePlayer;
|
||||
lettrePlayer = motPlayer[i];
|
||||
lettrePlayer.insert(0, "Alphabet/Normal/");
|
||||
lettrePlayer.insert(17, ".txt");
|
||||
nomFichier = lettrePlayer;
|
||||
ouvrirFichier(monFlux, nomFichier);
|
||||
printLettre(monFlux, 3);
|
||||
fermerFichier(monFlux);
|
||||
}
|
||||
}
|
||||
cout << endl;
|
||||
@@ -179,20 +193,18 @@ bool dansListe(string motPlayer) {
|
||||
|
||||
}
|
||||
|
||||
int lettreDansMot(string motRandom, string motPlayer, int nbLettre) {
|
||||
int lettreDansMot(string motRandom, string motPlayer, int nbLettre, int i) {
|
||||
|
||||
for (int i = 0; i < nbLettre; i++) {
|
||||
for (int k = 0; k < nbLettre; k++) {
|
||||
|
||||
if (motRandom[i] == motPlayer[k] && i == k) {
|
||||
return 1;
|
||||
if (motRandom[k] == motPlayer[i] && i == k) {
|
||||
return BONNE_PLACE;
|
||||
}
|
||||
else if ((motRandom[i] == motPlayer[k]) && i != k) {
|
||||
return 2;
|
||||
else if ((motRandom[k] == motPlayer[i]) && i != k) {
|
||||
return MAUVAIS_PLACE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 3;
|
||||
return PAS_LA;
|
||||
}
|
||||
|
||||
|
||||
@@ -260,7 +272,7 @@ void printLettre(fstream& monFlux, int positionLettre) {
|
||||
}
|
||||
else if (positionLettre == 3 /*Lettre non pr<70>sente*/)
|
||||
{
|
||||
couleurLettre = 00;
|
||||
couleurLettre = 8;
|
||||
}
|
||||
else /*Pas une lettre*/
|
||||
{
|
||||
|
||||
@@ -35,4 +35,5 @@ string goToLine(fstream& monFlux, int numeroLigne);
|
||||
void effectuerTour(int nbLettre);
|
||||
bool dansListe(string motPlayer);
|
||||
bool comparerMot(fstream& monFlux, string motPlayer, int numeroLigne);
|
||||
int lettreDansMot(string motRandom, string motPlayer, int nbLettre);
|
||||
int lettreDansMot(string motRandom, string motPlayer, int nbLettre, int i);
|
||||
void printLettre(fstream& monFlux, int positionLettre);
|
||||
Reference in New Issue
Block a user