Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #include <stdlib.h>
- #include <time.h>
- #include <sstream>
- using namespace std;
- void gameExplain()
- {
- string text;
- cout<<"In a game of Simon, a random number will be generated\nand shown to the player for 2 seconds."<<endl;
- cout<<"The player then must enter the number they saw, if correct\nthe computer will add another number."<<endl;
- cout<<"The game ends when the sequence hits 10 digits\nor if the user enters in an incorrect sequence."<<endl;
- cout<<"Good luck! Enter any key to begin ";
- cin>>text;
- system("cls");
- }
- void countdown()
- {
- cout<<"The game will start in\n";
- Sleep(1000);
- for(int c=5;c>0;c--)
- {
- cout<<c<<"\n";
- Sleep(1000);
- }
- }
- int simonGame()
- {
- srand(time(NULL));
- string code, numString, numGuess;
- int guess=0;
- for(int c=0;c<10;c++)
- {
- int num=rand()%9+1;
- ostringstream convert;
- convert<<num;
- numString=convert.str();
- code+=numString;
- cout<<code;
- Sleep(2000);
- system("cls");
- cout<<"Enter the sequence you saw: ";
- cin>>numGuess;
- if(numGuess==code&&c!=9)
- {
- guess++;
- cout<<"That's correct! Get ready for your next sequence in 3 seconds."<<endl;
- Sleep(2000);
- system("cls");
- Sleep(1000);
- }
- else if (numGuess!=code)
- {
- cout<<"I'm sorry, that's incorrect. The sequence was "<<code<<".\nYou got "<<guess<<" sequence";if(guess!=1)cout<<"s";cout<<" correct."<<endl;
- cout<<"Better luck next time!"<<endl;
- return 0;
- }
- }
- if(numGuess==code)
- {
- cout<<"That's correct! You got all 10 digits right! You win!"<<endl;
- return 0;
- }
- }
- int main()
- {
- char input;
- string start;
- cout<<"Game of Simon!"<<endl;
- cout<<"--------------"<<endl;
- cout<<"Do you need an explanation of the game? (y) or (n): ";
- cin>>input;
- if(input=='y'||input=='Y')gameExplain();
- else
- {
- cout<<"Enter any key to begin ";
- cin>>start;
- }
- system("cls");
- countdown();
- system("cls");
- simonGame();
- }
Advertisement
Add Comment
Please, Sign In to add comment