Implémentation total de la prise en charge en simultané des mots a 3 et 4 lettres.
This commit is contained in:
9
main.cpp
9
main.cpp
@@ -17,6 +17,9 @@ BUT : Rassemble les appels de fonction de Taxon
|
||||
//D<>claration des namespaces
|
||||
using namespace std;
|
||||
|
||||
extern int nbEssai = 6;
|
||||
extern int nbLettre = 4;
|
||||
|
||||
//D<>claration du main
|
||||
int main() {
|
||||
srand(time(NULL));
|
||||
@@ -24,11 +27,7 @@ int main() {
|
||||
|
||||
bool quitter = false; //Quitter le jeu
|
||||
int nbMot3lettre = 15; //Nombre de mot pr<70>sent dans le fichier
|
||||
int nbLettre = 4;
|
||||
string motRandom; // Mot random
|
||||
const int NOMBREMOT3LETTRE = 101;
|
||||
const int NOMBREMOT4LETTRE = 74;
|
||||
int nbEssai = 6;
|
||||
|
||||
while (quitter == false) {
|
||||
curseur(false);
|
||||
@@ -44,7 +43,7 @@ int main() {
|
||||
system("cls");
|
||||
|
||||
|
||||
effectuerTour(nbLettre);
|
||||
effectuerTour();
|
||||
break;
|
||||
|
||||
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
|
||||
|
||||
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);
|
||||
|
||||
@@ -25,11 +25,13 @@ void fermerFichier(fstream& monFlux);
|
||||
void delai();
|
||||
void curseur(bool interrupteur);
|
||||
|
||||
int nombreLigneFichier(fstream& monFlux);
|
||||
|
||||
// Mot
|
||||
string choisirMot(string nomFichier, int maximum);
|
||||
string choisirMot(string nomFichier);
|
||||
string goToLine(fstream& monFlux, int numeroLigne);
|
||||
|
||||
void effectuerTour(int nbLettre);
|
||||
void effectuerTour();
|
||||
bool dansListe(string motPlayer);
|
||||
bool comparerMot(fstream& monFlux, string motPlayer, int numeroLigne);
|
||||
int lettreDansMot(string motRandom, string motPlayer, int nbLettre, int i);
|
||||
|
||||
Reference in New Issue
Block a user