Implémentation total de la prise en charge en simultané des mots a 3 et 4 lettres.
This commit is contained in:
2
0
2
0
@@ -1 +1 @@
|
|||||||
Appuyez sur une touche pour continuer...
|
Appuyez sur une touche pour continuer...
|
||||||
|
|||||||
9
main.cpp
9
main.cpp
@@ -17,6 +17,9 @@ BUT : Rassemble les appels de fonction de Taxon
|
|||||||
//D<>claration des namespaces
|
//D<>claration des namespaces
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
extern int nbEssai = 6;
|
||||||
|
extern int nbLettre = 4;
|
||||||
|
|
||||||
//D<>claration du main
|
//D<>claration du main
|
||||||
int main() {
|
int main() {
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
@@ -24,11 +27,7 @@ int main() {
|
|||||||
|
|
||||||
bool quitter = false; //Quitter le jeu
|
bool quitter = false; //Quitter le jeu
|
||||||
int nbMot3lettre = 15; //Nombre de mot pr<70>sent dans le fichier
|
int nbMot3lettre = 15; //Nombre de mot pr<70>sent dans le fichier
|
||||||
int nbLettre = 4;
|
|
||||||
string motRandom; // Mot random
|
string motRandom; // Mot random
|
||||||
const int NOMBREMOT3LETTRE = 101;
|
|
||||||
const int NOMBREMOT4LETTRE = 74;
|
|
||||||
int nbEssai = 6;
|
|
||||||
|
|
||||||
while (quitter == false) {
|
while (quitter == false) {
|
||||||
curseur(false);
|
curseur(false);
|
||||||
@@ -44,7 +43,7 @@ int main() {
|
|||||||
system("cls");
|
system("cls");
|
||||||
|
|
||||||
|
|
||||||
effectuerTour(nbLettre);
|
effectuerTour();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '2':
|
case '2':
|
||||||
|
|||||||
@@ -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
|
#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;
|
const int BONNE_PLACE = 1, MAUVAIS_PLACE = 2, PAS_LA = 3;
|
||||||
extern const int NOMBREMOT3LETTRE = 101;
|
extern int nbEssai;
|
||||||
extern const int NOMBREMOT4LETTRE = 74;
|
extern int nbLettre;
|
||||||
extern int nbEssai = 6;
|
|
||||||
extern int nbLettre = 4;
|
|
||||||
|
|
||||||
/*====================================
|
/*====================================
|
||||||
MENU
|
MENU
|
||||||
@@ -92,11 +90,26 @@ void curseur(bool interrupteur) {
|
|||||||
/*====================================
|
/*====================================
|
||||||
1 - JOUER
|
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
|
//fonction pour choisir le mot de facon random
|
||||||
string choisirMot(string nomFichier, int maximum) {//Choisi un mot al<61>atoire et le renvoi
|
string choisirMot(string nomFichier) {//Choisi un mot al<61>atoire et le renvoi
|
||||||
int numeroLigne = rand() % (maximum)+1;
|
|
||||||
fstream monFlux;
|
fstream monFlux;
|
||||||
ouvrirFichier(monFlux, nomFichier);
|
ouvrirFichier(monFlux, nomFichier);
|
||||||
|
int maximum = nombreLigneFichier(monFlux);
|
||||||
|
int numeroLigne = rand() % (maximum)+1;
|
||||||
string motRandom = goToLine(monFlux, numeroLigne);
|
string motRandom = goToLine(monFlux, numeroLigne);
|
||||||
fermerFichier(monFlux);
|
fermerFichier(monFlux);
|
||||||
return motRandom;
|
return motRandom;
|
||||||
@@ -110,14 +123,14 @@ string goToLine(fstream& monFlux, int numeroLigne) {//g
|
|||||||
return mot;
|
return mot;
|
||||||
}
|
}
|
||||||
|
|
||||||
void effectuerTour(int nbLettre)
|
void effectuerTour()
|
||||||
{
|
{
|
||||||
string motRandom;
|
string motRandom;
|
||||||
if (nbLettre == 3) {
|
if (nbLettre == 3) {
|
||||||
motRandom = choisirMot("Mots/mot3lettres.txt", NOMBREMOT3LETTRE);
|
motRandom = choisirMot("Mots/mot3lettres.txt");
|
||||||
}
|
}
|
||||||
else if (nbLettre == 4) {
|
else if (nbLettre == 4) {
|
||||||
motRandom = choisirMot("Mots/mot4lettres.txt", NOMBREMOT4LETTRE);
|
motRandom = choisirMot("Mots/mot4lettres.txt");
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << setw(83) << "=============================================\n";
|
cout << setw(83) << "=============================================\n";
|
||||||
@@ -128,7 +141,7 @@ void effectuerTour(int nbLettre)
|
|||||||
{
|
{
|
||||||
string lettrePlayer;
|
string lettrePlayer;
|
||||||
do {
|
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 : ";
|
cout << setw(69) << "Saisir votre mot : ";
|
||||||
cin >> motPlayer; //TODO: mettre tolower string (boucle)
|
cin >> motPlayer; //TODO: mettre tolower string (boucle)
|
||||||
} while (motPlayer.length() != nbLettre);
|
} while (motPlayer.length() != nbLettre);
|
||||||
@@ -166,28 +179,21 @@ void effectuerTour(int nbLettre)
|
|||||||
bool dansListe(string motPlayer) {
|
bool dansListe(string motPlayer) {
|
||||||
fstream monFlux;
|
fstream monFlux;
|
||||||
string mot;
|
string mot;
|
||||||
|
int nbMots = 0;
|
||||||
if (nbLettre == 3) {
|
if (nbLettre == 3) {
|
||||||
ouvrirFichier(monFlux, "Mots/mot3lettres.txt");
|
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) {
|
else if (nbLettre == 4) {
|
||||||
ouvrirFichier(monFlux, "Mots/mot4lettres.txt");
|
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)
|
if (motPlayer == mot)
|
||||||
{
|
{
|
||||||
fermerFichier(monFlux);
|
fermerFichier(monFlux);
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fermerFichier(monFlux);
|
fermerFichier(monFlux);
|
||||||
|
|||||||
@@ -25,11 +25,13 @@ void fermerFichier(fstream& monFlux);
|
|||||||
void delai();
|
void delai();
|
||||||
void curseur(bool interrupteur);
|
void curseur(bool interrupteur);
|
||||||
|
|
||||||
|
int nombreLigneFichier(fstream& monFlux);
|
||||||
|
|
||||||
// Mot
|
// Mot
|
||||||
string choisirMot(string nomFichier, int maximum);
|
string choisirMot(string nomFichier);
|
||||||
string goToLine(fstream& monFlux, int numeroLigne);
|
string goToLine(fstream& monFlux, int numeroLigne);
|
||||||
|
|
||||||
void effectuerTour(int nbLettre);
|
void effectuerTour();
|
||||||
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);
|
||||||
|
|||||||
Reference in New Issue
Block a user