| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 
 | #include <iostream>
#include <ctime>
#include <cstdlib>
#include <string>
#include <future>
#include <thread>
#include <chrono>
#include <unistd.h>
 
static std::string getAnswer()
{
    std::string answer;
    std::cin >> answer;
    return answer;
}
 
std::string melangerlettres(std::string mot)
{
    std::string melange;
    int position(0);
 
    while (mot.size() != 0)
    {
        position = rand() % mot.size();
        melange += mot[position];
        mot.erase(position, 1);
    }
    return melange;
}
 
int main()
{
    std::string motMystere, motMelange, motUtilisateur, reponseRejouer;
    srand(time(0));
 
    std::chrono::seconds timeout(5);
 
    do
    {
        std::system("clear");
 
        std::cout << "mot mystere: " << std::endl;
        std::cin >> motMystere;
 
        std::system("clear");
 
        int nombreCoups = motMystere.size();
 
        motMelange = melangerlettres(motMystere);
 
        do
        {
            motUtilisateur = "perdu";
 
            std::cout << "nombre restant d'essais : " << nombreCoups << std::endl;
            std::cout << "\nQuel est ce mot : " << motMelange << std::endl;
 
            std::future<std::string> future = std::async(getAnswer);
 
            if (future.wait_for(timeout) == std::future_status::ready)
            {
                motUtilisateur = future.get();
            }
 
            std::cout << "heheheheheh" << std::endl;
            //std::system("clear");
            nombreCoups -= 1;
 
            if (nombreCoups < 1)
            {
                std::cout << "COUPS DEPASSES." << std::endl;
                motUtilisateur = motMystere;
            }
            else
            {
                if (motUtilisateur != motMystere)
                {
                    std::cout << "NON RECOMMENCE." << std::endl;
                }
                else
                {
                    std::cout << "BRAVO." << std::endl;
                }
            }
        } while (motUtilisateur != motMystere);
 
        std::cout << "\nVoulez-vous rejouer ? (o/n)" << std::endl;
        std::cin >> reponseRejouer;
 
    } while (reponseRejouer == "o" || reponseRejouer == "O");
 
    return 0;
} | 
Partager