Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main.cpp
- #include <iostream>
- #include "dictionnaire.h"
- #include <string>
- #include <cstdlib>
- #include <time.h>
- using namespace std;
- int nombreLettre(string motUser, string motInitial)
- {
- int nombreLettreJuste(0), position(0);
- while (position < motInitial.size())
- {
- if (motUser[position] == motInitial[position])
- {
- nombreLettreJuste++;
- }
- position++;
- }
- return nombreLettreJuste;
- }
- string melange(string motAleatoire)
- {
- int position(0);
- string motMelanger;
- srand(time(NULL));
- while (motAleatoire.size() != 0)
- {
- position = rand() % motAleatoire.size();
- motMelanger += motAleatoire[position];
- motAleatoire.erase(position, 1);
- }
- return motMelanger;
- }
- int verification(string motInitial, string motMelanger)
- {
- string motUser;
- int nombreCoup(0), nombreLettreJuste(0);
- while (motUser != motInitial)
- {
- cout << "Mot a deviner: " << motMelanger << endl << "Votre proposition: ";
- cin >> motUser;
- nombreCoup++;
- system("cls");
- cout << "Derniere propositioon: " << motUser << endl << "Lettres correctes: " << nombreLettre(motUser, motInitial) << endl;
- if (motUser == "spoil")
- {
- system("cls");
- cout << "SPOIL: Mot initial: " << motInitial << endl;
- }
- }
- return nombreCoup;
- }
- void partie(string dir)
- {
- string motRandom, motMelanger;
- int nombreCoup(0);
- motRandom = motHasard(dir);
- motMelanger = melange(motRandom);
- nombreCoup = verification(motRandom, motMelanger);
- }
- void affichage()
- {
- cout << "Mot Mystere: v0.01" << endl << "";
- }
- int main()
- {
- string directory("dico.txt");
- partie(directory);
- }
- dictionnaire.cpp
- /////////
- #include "dictionnaire.h"
- #include <fstream>
- #include <string>
- #include <iostream>
- #include <cstdlib>
- #include <time.h>
- std::string motHasard(std::string dir)
- {
- int nombreLigne, ligneHasard;
- std::string motRandom;
- nombreLigne = getLigne(dir, nombreLigne);
- ligneHasard = nombreHasard(nombreLigne);
- motRandom = getRandomMot(ligneHasard, dir);
- return motRandom;
- }
- std::string getRandomMot(int random, std::string dir)
- {
- std::ifstream getMotHasard(dir.c_str());
- std::string resultat("none"), ligne("none");
- if (getMotHasard)
- {
- for (int i(0) ; i < random - 1 ; i++)
- {
- getline(getMotHasard, ligne);
- }
- resultat = ligne;
- }
- else
- {
- std::cout << "Erreur ouverture flux getMotHasard";
- }
- return resultat;
- }
- int nombreHasard(int nombreLigne)
- {
- int nombreAleatoire(1);
- srand(time(NULL));
- nombreAleatoire = rand() % nombreLigne;
- return nombreAleatoire;
- }
- ////////
- dictionnaire.h
- #ifndef DICTIONNAIRE_H_INCLUDED
- #define DICTIONNAIRE_H_INCLUDED
- #include <string>
- std::string motHasard(std::string dir);
- int getLigne(std::string dir, int nombre);
- int nombreHasard(int nombreLigne);
- std::string getRandomMot(int random, std::string dir);
- #endif // DICTIONNAIRE_H_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement