Implémentation total de la prise en charge en simultané des mots a 3 et 4 lettres.
This commit is contained in:
@@ -24,10 +24,8 @@ 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;
|
||||
extern const int NOMBREMOT3LETTRE = 101;
|
||||
extern const int NOMBREMOT4LETTRE = 74;
|
||||
extern int nbEssai = 6;
|
||||
extern int nbLettre = 4;
|
||||
extern int nbEssai;
|
||||
extern int nbLettre;
|
||||
|
||||
/*====================================
|
||||
MENU
|
||||
@@ -92,11 +90,26 @@ void curseur(bool interrupteur) {
|
||||
/*====================================
|
||||
1 - JOUER
|
||||
====================================*/
|
||||
//Fonction pour connaitre le nombre de ligne d'un fichier
|
||||
int nombreLigneFichier(fstream& monFlux) {
|
||||
string str;
|
||||
int nbLigne = 0;
|
||||
|
||||
while (!monFlux.eof()) {
|
||||
getline(monFlux, str);
|
||||
nbLigne++;
|
||||
}
|
||||
|
||||
monFlux.seekg(ios::beg);
|
||||
|
||||
return nbLigne;
|
||||
}
|
||||
//fonction pour choisir le mot de facon random
|
||||
string choisirMot(string nomFichier, int maximum) {//Choisi un mot al<61>atoire et le renvoi
|
||||
int numeroLigne = rand() % (maximum)+1;
|
||||
string choisirMot(string nomFichier) {//Choisi un mot al<61>atoire et le renvoi
|
||||
fstream monFlux;
|
||||
ouvrirFichier(monFlux, nomFichier);
|
||||
int maximum = nombreLigneFichier(monFlux);
|
||||
int numeroLigne = rand() % (maximum)+1;
|
||||
string motRandom = goToLine(monFlux, numeroLigne);
|
||||
fermerFichier(monFlux);
|
||||
return motRandom;
|
||||
@@ -110,14 +123,14 @@ string goToLine(fstream& monFlux, int numeroLigne) {//g
|
||||
return mot;
|
||||
}
|
||||
|
||||
void effectuerTour(int nbLettre)
|
||||
void effectuerTour()
|
||||
{
|
||||
string motRandom;
|
||||
if (nbLettre == 3) {
|
||||
motRandom = choisirMot("Mots/mot3lettres.txt", NOMBREMOT3LETTRE);
|
||||
motRandom = choisirMot("Mots/mot3lettres.txt");
|
||||
}
|
||||
else if (nbLettre == 4) {
|
||||
motRandom = choisirMot("Mots/mot4lettres.txt", NOMBREMOT4LETTRE);
|
||||
motRandom = choisirMot("Mots/mot4lettres.txt");
|
||||
}
|
||||
|
||||
cout << setw(83) << "=============================================\n";
|
||||
@@ -128,7 +141,7 @@ void effectuerTour(int nbLettre)
|
||||
{
|
||||
string lettrePlayer;
|
||||
do {
|
||||
cout << setw(65) << "Tentative #" << nbTentative + 1 << endl;
|
||||
cout << setw(69) << "Tentative des mots de " << nbLettre << " #" << nbTentative + 1 << endl;
|
||||
cout << setw(69) << "Saisir votre mot : ";
|
||||
cin >> motPlayer; //TODO: mettre tolower string (boucle)
|
||||
} while (motPlayer.length() != nbLettre);
|
||||
@@ -166,28 +179,21 @@ void effectuerTour(int nbLettre)
|
||||
bool dansListe(string motPlayer) {
|
||||
fstream monFlux;
|
||||
string mot;
|
||||
int nbMots = 0;
|
||||
if (nbLettre == 3) {
|
||||
ouvrirFichier(monFlux, "Mots/mot3lettres.txt");
|
||||
for (int i = 0; i < NOMBREMOT3LETTRE; i++) {
|
||||
getline(monFlux, mot);
|
||||
|
||||
if (motPlayer == mot)
|
||||
{
|
||||
fermerFichier(monFlux);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (nbLettre == 4) {
|
||||
ouvrirFichier(monFlux, "Mots/mot4lettres.txt");
|
||||
for (int i = 0; i < NOMBREMOT4LETTRE; i++) {
|
||||
getline(monFlux, mot);
|
||||
}
|
||||
nbMots = nombreLigneFichier(monFlux);
|
||||
for (int i = 0; i < nbMots; i++) {
|
||||
getline(monFlux, mot); //TODO: Verification d'erreur du getline (Exemple si le fichier est trops petit)
|
||||
|
||||
if (motPlayer == mot)
|
||||
{
|
||||
fermerFichier(monFlux);
|
||||
return true;
|
||||
}
|
||||
if (motPlayer == mot)
|
||||
{
|
||||
fermerFichier(monFlux);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
fermerFichier(monFlux);
|
||||
|
||||
Reference in New Issue
Block a user