fork(1) download
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <ctime>
  5. #include <cstdlib>
  6.  
  7. using namespace std;
  8.  
  9. string melangerLettres(string mot);
  10. void menu();
  11. void moteurJeu();
  12.  
  13. int main()
  14. {
  15. string devineMot, motMystere, motMelange;
  16. int decompteur(5);
  17. system("title Jeu du mot mystere");
  18. system("color 5");
  19. moteurJeu();
  20. system("pause");
  21.  
  22. return 0;
  23. }
  24.  
  25. string melangerLettres(string mot)
  26. {
  27. string melange;
  28. int position(0);
  29.  
  30. while (mot.size() != 0)
  31. {
  32.  
  33. position = rand() % mot.size();
  34. melange += mot[position];
  35. mot.erase(position, 1);
  36. }
  37.  
  38. return melange;
  39. }
  40.  
  41. void menu()
  42. {
  43. cout << "\t\t__________________________________________" <<endl;
  44. cout << "\t\t|::::::::: Jeu du mot mystere ! :::::::::|" <<endl;
  45. cout << "\t\t__________________________________________" <<endl<<endl<<endl;
  46. }
  47.  
  48. void moteurJeu()
  49. {
  50. string motMelange, devineMot, motMystere;
  51. int decompteur(5);
  52. srand(time(0));
  53. system("cls");
  54. menu();
  55. cout << "\t\t\tSaisissez un mot : " << endl;
  56. cin >> motMystere;
  57. system("cls");
  58.  
  59. motMelange = melangerLettres(motMystere);
  60. do
  61. {
  62. menu();
  63. cout << endl << "\t\t\tQuel est ce mot ? " << motMelange << endl;
  64. cin >> devineMot;
  65. decompteur --;
  66.  
  67. if (devineMot == motMystere)
  68. {
  69. cout << "\t\t\tBravo ! Vous avez trouve le mot mystere !!!" << endl << endl << endl;
  70. }
  71. else
  72. {
  73. cout << "\t\t\tCe n'est pas le mot !" << endl;
  74. cout << "\t\t\tIl vous reste " << decompteur << " chances !" << endl<< endl<<endl <<endl;
  75. system("pause");
  76. system("cls");
  77. }
  78. }while (devineMot != motMystere && decompteur != 0);
  79. }
  80.  
Success #stdin #stdout 0.04s 5312KB
stdin
hello
heylo
heyyl
hello
stdout
		__________________________________________
		|::::::::: Jeu du mot mystere ! :::::::::|
		__________________________________________


			Saisissez un mot : 
		__________________________________________
		|::::::::: Jeu du mot mystere ! :::::::::|
		__________________________________________



			Quel est ce mot ? llheo
			Ce n'est pas le mot !
			Il vous reste 4 chances !



		__________________________________________
		|::::::::: Jeu du mot mystere ! :::::::::|
		__________________________________________



			Quel est ce mot ? llheo
			Ce n'est pas le mot !
			Il vous reste 3 chances !



		__________________________________________
		|::::::::: Jeu du mot mystere ! :::::::::|
		__________________________________________



			Quel est ce mot ? llheo
			Bravo ! Vous avez trouve le mot mystere !!!