Advertisement
-LIR-

Memory Game

Jul 17th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <time.h>
  5. #include <windows.h>
  6.  
  7. using namespace std;
  8.  
  9. int n = 25, level = 1, random = 0, guess = 0, guess_prev = 0;
  10. int grid[26], memory[26];
  11. bool ops = false;
  12.  
  13. void Afisare()
  14. {
  15.     cout << "--------------------------------------------------------------------\n";
  16.     cout << "                             Memory Game                            \n";
  17.     cout << "--------------------------------------------------------------------\n";
  18.     cout << "                                Rules                               \n";
  19.     cout << "--------------------------------------------------------------------\n";
  20.     cout << " You can already see that there's a grid of numbers. When the level \n";
  21.     cout << " begins some numbers will blink in a particular order which you'll  \n";
  22.     cout << " have to reproduce.\n";
  23.     cout << "--------------------------------------------------------------------\n";
  24.  
  25.     cout << " Level: " << level << "\n ";
  26.     for( int i=1 ; i<=n ; i++ )
  27.     {
  28.         if( i == random )
  29.             cout << (char) 178 << "  ";
  30.         else
  31.         {
  32.             if( i < 10 )
  33.                 cout << i << "  ";
  34.             else
  35.                 cout << i << " ";
  36.         }
  37.  
  38.         if( i%5 == 0 )
  39.             cout << "\n ";
  40.     }
  41. }
  42.  
  43. void GenerateNumber()
  44. {
  45.     srand(time(NULL));
  46.     for( int i=1 ; i<=level ; i++ )
  47.     {
  48.         guess_prev = guess;
  49.         do
  50.         {
  51.             random = rand()%n + 1;
  52.         }
  53.         while( guess != guess_prev );
  54.     }
  55. }
  56.  
  57. int main()
  58. {
  59.  
  60.     while(1)
  61.     {
  62.         for( int i=1 ; i<=level ; i++ )
  63.         {
  64.             GenerateNumber();
  65.             memory[i] = random;
  66.             Afisare();
  67.             Sleep(2000);
  68.             system("cls");
  69.         }
  70.         random = 0;
  71.         Afisare();
  72.         for( int i=1 ; i<=level ; i++ )
  73.         {
  74.             if( i>1 )
  75.                 cout << " Enter your guess(number pls): ";
  76.             else
  77.                 cout <<  "Enter your guess(number pls): ";
  78.             cin >> guess;
  79.             if( guess != memory[i] )
  80.             {
  81.                 system("cls");
  82.                 cout << "Ops :( You lost! ";
  83.                 ops = true;
  84.                 break;
  85.             }
  86.             Sleep(500);
  87.         }
  88.         if( ops || level == 10 )
  89.             break;
  90.         system("cls");
  91.         cout <<" Congrats! You have beaten level " << level;
  92.         Sleep(1000);
  93.         system("cls");
  94.         level++;
  95.     }
  96.     Sleep(10000);
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement