Guest User

Untitled

a guest
May 20th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. #include <windows.h>
  5.  
  6. using namespace std;
  7.  
  8. void animatedPrint(const string &text)
  9. {
  10.     for (int i = (int)text.size() - 1; i > 0; i--)
  11.     {
  12.         cout << &text[i];
  13.  
  14.         Sleep(20);
  15.  
  16.         string backspaces;
  17.         for (int j = i; j < (int)text.size(); j++)
  18.             backspaces += "\b";
  19.         cout << backspaces;
  20.     }
  21.  
  22.     cout << text;
  23. }
  24.  
  25. int main()
  26. {
  27.     while (true)
  28.     {
  29.         animatedPrint("Laten we galgje spelen!");
  30.         cout << "\n\n";
  31.  
  32.         animatedPrint("Voor de uitdager...");
  33.         cout << "\n\n";
  34.  
  35.         string oplossing;
  36.         animatedPrint("Geef de oplossing: ");
  37.         cin >> oplossing;
  38.  
  39.         int beurten;
  40.         do {
  41.             animatedPrint("Geef het aantal beurten: ");
  42.             cin >> beurten;
  43.         } while (beurten <= 0);
  44.  
  45.         system("cls");
  46.  
  47.         animatedPrint("Voor de speler...");
  48.         cout << "\n\n";
  49.  
  50.         string woord;
  51.         for (int i = 0; i < (int)oplossing.size(); i++)
  52.             woord += ".";
  53.  
  54.         while (true)
  55.         {
  56.             animatedPrint("Woord: " + woord);
  57.             cout << "\n";
  58.             animatedPrint("Beurten: ");
  59.             cout << beurten << "\n";
  60.  
  61.             string input;
  62.             animatedPrint("Geef een letter of de oplossing: ");
  63.             cin >> input;
  64.  
  65.             if (input.size() > 1)
  66.             {
  67.                 if (input == oplossing)
  68.                 {
  69.                     animatedPrint("Juist!");
  70.                     cout << "\n\n";
  71.                     break;
  72.                 }
  73.                 else
  74.                 {
  75.                     animatedPrint("Fout!");
  76.                     cout << "\n\n";
  77.                     beurten--;
  78.                 }
  79.             }
  80.             else
  81.             {
  82.                 bool juist = false;
  83.  
  84.                 for (int i = 0; i < (int)oplossing.size(); i++)
  85.                 {              
  86.                     if (oplossing[i] == input[0])
  87.                     {
  88.                         woord[i] = oplossing[i];
  89.                         juist = true;
  90.                     }
  91.                 }
  92.  
  93.                 if (!juist)
  94.                     beurten--;
  95.  
  96.                 if (woord == oplossing)
  97.                 {
  98.                     animatedPrint("Gewonnen!");
  99.                     cout << "\n\n";
  100.                     break;
  101.                 }
  102.             }
  103.  
  104.             if (!beurten)
  105.             {
  106.                 animatedPrint("Verloren!");
  107.                 cout << "\n\n";
  108.                 break;
  109.             }
  110.         }
  111.  
  112.         animatedPrint("Oplossing: " + oplossing);
  113.         cout << "\n\n";
  114.  
  115.         string opnieuw;
  116.  
  117.         do {
  118.             animatedPrint("Nog eens spelen (j/n)? ");
  119.             cin >> opnieuw;
  120.         } while ((opnieuw[0] != 'j') && (opnieuw[0] != 'n'));
  121.  
  122.         if (opnieuw[0] == 'n')
  123.         {
  124.             cout << "\n";
  125.             animatedPrint("Ik hoop dat je het leuk vond. Ik althans wel!");
  126.             cout << "\n\n";
  127.             break;
  128.         }
  129.  
  130.         system("cls");
  131.     }
  132. }
Add Comment
Please, Sign In to add comment