#include <iostream>
#include <string>
#include <fstream>
#include <ctime>
#include <cstdlib>

using namespace std;

string melangerLettres(string mot);
void menu();
void moteurJeu();

int main()
{
    string devineMot, motMystere, motMelange;
    int decompteur(5);
    system("title Jeu du mot mystere");
    system("color 5");
    moteurJeu();
    system("pause");

    return main();
}

string melangerLettres(string mot)
{
    string melange;
    int position(0);

    while (mot.size() != 0)
    {

        position = rand() % mot.size();
        melange += mot[position];
        mot.erase(position, 1);
    }

    return melange;
}

void menu()
{
    cout << "\t\t__________________________________________" <<endl;
    cout << "\t\t|::::::::: Jeu du mot mystere ! :::::::::|" <<endl;
    cout << "\t\t__________________________________________" <<endl<<endl<<endl;
}

void moteurJeu()
{
    string motMelange, devineMot, motMystere;
    int decompteur(5);
    srand(time(0));
    system("cls");
    menu();
    cout << "\t\t\tSaisissez un mot : " << endl;
    cin >> motMystere;
    system("cls");

    motMelange = melangerLettres(motMystere);
    do
        {
        menu();
        cout << endl << "\t\t\tQuel est ce mot ? " << motMelange << endl;
        cin >> devineMot;
        decompteur --;

        if (devineMot == motMystere)
        {
            cout << "\t\t\tBravo ! Vous avez trouve le mot mystere !!!" << endl << endl << endl;
        }
        else
        {
            cout << "\t\t\tCe n'est pas le mot !" << endl;
            cout << "\t\t\tIl vous reste " << decompteur << " chances !" << endl<< endl<<endl <<endl;
            system("pause");
            system("cls");
        }
        }while (devineMot != motMystere && decompteur != 0);
}
