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
|
#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
|
MENU
|
||||||
@@ -106,6 +107,8 @@ 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
|
HANDLE hconsole = GetStdHandle(STD_OUTPUT_HANDLE);//pour la couleur
|
||||||
|
|
||||||
string motRandom = choisirMot("Mots/mot3lettres.txt", 15);
|
string motRandom = choisirMot("Mots/mot3lettres.txt", 15);
|
||||||
@@ -128,24 +131,35 @@ void effectuerTour(int nbLettre)
|
|||||||
|
|
||||||
for (int i = 0; i < nbLettre; i++) {
|
for (int i = 0; i < nbLettre; i++) {
|
||||||
|
|
||||||
if (lettreDansMot(motRandom, motPlayer, nbLettre) == 1) {
|
if (lettreDansMot(motRandom, motPlayer, nbLettre, i) == BONNE_PLACE) {
|
||||||
|
string lettrePlayer;
|
||||||
SetConsoleTextAttribute(hconsole, 2);//mettre la lettre en vert
|
lettrePlayer = motPlayer[i];
|
||||||
cout << motPlayer[i];
|
lettrePlayer.insert(0, "Alphabet/Normal/");
|
||||||
SetConsoleTextAttribute(hconsole, 15);//remettre le texte en blanc
|
lettrePlayer.insert(17, ".txt");
|
||||||
|
nomFichier = lettrePlayer;
|
||||||
|
ouvrirFichier(monFlux, nomFichier);
|
||||||
|
printLettre(monFlux, 1);
|
||||||
|
fermerFichier(monFlux);
|
||||||
}
|
}
|
||||||
else if (lettreDansMot(motRandom, motPlayer, nbLettre) == 2) {
|
else if (lettreDansMot(motRandom, motPlayer, nbLettre, i) == MAUVAIS_PLACE) {
|
||||||
|
string lettrePlayer;
|
||||||
SetConsoleTextAttribute(hconsole, 6);//mettre la lettre en jaune
|
lettrePlayer = motPlayer[i];
|
||||||
cout << motPlayer[i];
|
lettrePlayer.insert(0, "Alphabet/Normal/");
|
||||||
SetConsoleTextAttribute(hconsole, 15);//remettre le texte en blanc
|
lettrePlayer.insert(17, ".txt");
|
||||||
|
nomFichier = lettrePlayer;
|
||||||
|
ouvrirFichier(monFlux, nomFichier);
|
||||||
|
printLettre(monFlux, 2);
|
||||||
|
fermerFichier(monFlux);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
string lettrePlayer;
|
||||||
SetConsoleTextAttribute(hconsole, 8);//mettre la lettre en gris
|
lettrePlayer = motPlayer[i];
|
||||||
cout << motPlayer[i];
|
lettrePlayer.insert(0, "Alphabet/Normal/");
|
||||||
SetConsoleTextAttribute(hconsole, 15);//remettre le texte en blanc
|
lettrePlayer.insert(17, ".txt");
|
||||||
|
nomFichier = lettrePlayer;
|
||||||
|
ouvrirFichier(monFlux, nomFichier);
|
||||||
|
printLettre(monFlux, 3);
|
||||||
|
fermerFichier(monFlux);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cout << endl;
|
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++) {
|
||||||
for (int k = 0; k < nbLettre; k++) {
|
|
||||||
|
|
||||||
if (motRandom[i] == motPlayer[k] && i == k) {
|
if (motRandom[k] == motPlayer[i] && i == k) {
|
||||||
return 1;
|
return BONNE_PLACE;
|
||||||
}
|
}
|
||||||
else if ((motRandom[i] == motPlayer[k]) && i != k) {
|
else if ((motRandom[k] == motPlayer[i]) && i != k) {
|
||||||
return 2;
|
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*/)
|
else if (positionLettre == 3 /*Lettre non pr<70>sente*/)
|
||||||
{
|
{
|
||||||
couleurLettre = 00;
|
couleurLettre = 8;
|
||||||
}
|
}
|
||||||
else /*Pas une lettre*/
|
else /*Pas une lettre*/
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -35,4 +35,5 @@ string goToLine(fstream& monFlux, int numeroLigne);
|
|||||||
void effectuerTour(int nbLettre);
|
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 lettreDansMot(string motRandom, string motPlayer, int nbLettre, int i);
|
||||||
|
void printLettre(fstream& monFlux, int positionLettre);
|
||||||
Reference in New Issue
Block a user