KeeganT

Ass55

Oct 6th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5. #include <sstream>
  6.  
  7. using namespace std;
  8.  
  9. void gameExplain()
  10. {
  11.     string text;
  12.     cout<<"In a game of Simon, a random number will be generated\nand shown to the player for 2 seconds."<<endl;
  13.     cout<<"The player then must enter the number they saw, if correct\nthe computer will add another number."<<endl;
  14.     cout<<"The game ends when the sequence hits 10 digits\nor if the user enters in an incorrect sequence."<<endl;
  15.     cout<<"Good luck! Enter any key to begin ";
  16.     cin>>text;
  17.     system("cls");
  18. }
  19.  
  20. void countdown()
  21. {
  22.     cout<<"The game will start in\n";
  23.     Sleep(1000);
  24.     for(int c=5;c>0;c--)
  25.     {
  26.     cout<<c<<"\n";
  27.     Sleep(1000);
  28.     }
  29. }
  30.  
  31. int simonGame()
  32. {
  33.     srand(time(NULL));
  34.     string code, numString, numGuess;
  35.     int guess=0;
  36.     for(int c=0;c<10;c++)
  37.     {
  38.         int num=rand()%9+1;
  39.         ostringstream convert;
  40.         convert<<num;
  41.         numString=convert.str();
  42.         code+=numString;
  43.         cout<<code;
  44.         Sleep(2000);
  45.         system("cls");
  46.         cout<<"Enter the sequence you saw: ";
  47.         cin>>numGuess;
  48.         if(numGuess==code&&c!=9)
  49.         {
  50.             guess++;
  51.             cout<<"That's correct! Get ready for your next sequence in 3 seconds."<<endl;
  52.             Sleep(2000);
  53.             system("cls");
  54.             Sleep(1000);
  55.         }
  56.         else if (numGuess!=code)
  57.         {
  58.             cout<<"I'm sorry, that's incorrect. The sequence was "<<code<<".\nYou got "<<guess<<" sequence";if(guess!=1)cout<<"s";cout<<" correct."<<endl;
  59.             cout<<"Better luck next time!"<<endl;
  60.             return 0;
  61.         }
  62.     }
  63.     if(numGuess==code)
  64.     {
  65.         cout<<"That's correct! You got all 10 digits right! You win!"<<endl;
  66.         return 0;
  67.     }
  68. }
  69.  
  70. int main()
  71. {
  72.     char input;
  73.     string start;
  74.     cout<<"Game of Simon!"<<endl;
  75.     cout<<"--------------"<<endl;
  76.     cout<<"Do you need an explanation of the game? (y) or (n): ";
  77.     cin>>input;
  78.     if(input=='y'||input=='Y')gameExplain();
  79.     else
  80.     {
  81.         cout<<"Enter any key to begin ";
  82.         cin>>start;
  83.     }
  84.     system("cls");
  85.     countdown();
  86.     system("cls");
  87.     simonGame();
  88. }
Advertisement
Add Comment
Please, Sign In to add comment