Advertisement
Guest User

KCM

a guest
Apr 26th, 2015
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.90 KB | None | 0 0
  1. // KCM @ KCM @ KCM
  2. #include <iostream>
  3. #include <vector>
  4. using namespace std;
  5. int main()
  6. {
  7.         char again='y';         //(do you want to play?)
  8.         vector<char>word;
  9.         vector<char>mystery;
  10.         vector<char>guessed;
  11.         while(again=='y'||again=='Y')
  12.         {
  13.             char letter='0';
  14.             int one=1;
  15.             int j=0;
  16.             int count=0;
  17.             int left;
  18.             int guesses=0;
  19.             int chances=6;
  20.             int disc=0;
  21.  
  22.  
  23.         cout<<"Type in any word or words, followed by '@'\n"; //sets up the word
  24.         while(letter!='@')
  25.         {
  26.                 cin>>letter;
  27.                 if(letter!='@')
  28.                 {
  29.                 word.push_back(letter);
  30.                 ++j;
  31.                 }
  32.         }
  33.  
  34.         left=j; //# of letters
  35.  
  36.         cout<<"\n\n\n\n\n\n\n\n\n\n\n\n\nletters: "<<j<<"\n\n\n\n\n\n\n"; //shows how many letters there are total
  37.  
  38.         while(left>0&&chances>0)
  39.         {
  40.                 cout<<"\n\nChances left: "<<chances<<"\n\n\n"; //prints chances left
  41.         count=0;
  42.  
  43.                 if(chances==6)
  44.                 cout<<"    ___\n   |   |\n       |\n       |\n       |\n    ___ \n   |   |\n\n\n";
  45.                 else if(chances==5)
  46.                 cout<<"    ___\n   |   |\n   O   |\n       |\n       |\n    ___ \n   |   |\n\n\n";
  47.                 else if(chances==4)
  48.                 cout<<"    ___\n   |   |\n   O   |\n   I   |\n       |\n    ___ \n   |   |\n\n\n";
  49.                 else if(chances==3)
  50.                 cout<<"    ___\n   |   |\n   O   |\n   I   |\n  /    |\n    ___ \n   |   |\n\n\n";
  51.                 else if(chances==2)
  52.                 cout<<"    ___\n   |   |\n   O   |\n   I   |\n  //   |\n    ___ \n   |   |\n\n\n";
  53.                 else if(chances==1)
  54.                 cout<<"    ___\n   |   |\n   O   |\n  |I   |\n  //   |\n    ___ \n   |   |\n\n\n";
  55.  
  56.         while(count<j) //prints dashes and correct letters
  57.         {
  58.                 mystery.push_back('_');
  59.                 cout<<mystery[count]<<" ";
  60.                 ++count;
  61.         }
  62.         count=0;
  63.  
  64.         cout<<"\n\n\nGuess a letter: "; ///guess time
  65.         cin>>letter;
  66.         while(one==2)
  67.         {
  68.                 one=1;
  69.         for(int i=0;i<guesses;++i)
  70.         {
  71.                 if(letter==guessed[i])
  72.                 {
  73.                         one=2;
  74.                         cout<<"\nYou already guessed that.\n\nGuess another letter: ";
  75.                         cin>>letter;
  76.                 }
  77.         }
  78.         }
  79.  
  80.         one=2;
  81.         for(int i=0;i<j;++i) //controls replacing blanks with letters, as well as counts how many chances there are left
  82.         {
  83.                 if(letter==word[i])
  84.                 {
  85.                         mystery[i]=word[i];
  86.                         --left;
  87.                         disc=1;
  88.                 }
  89.         }
  90.         if(disc==0)
  91.         {
  92.                 --chances;
  93.         }
  94.         disc=0;
  95.  
  96.         ++guesses;
  97.         cout<<"\n\n\n\n\n\n\nGuessed: "; //prints guessed letters
  98.         guessed.push_back(letter);
  99.         while(count<guesses)
  100.         {
  101.                 cout<<guessed[count];
  102.                 ++count;
  103.         }
  104.  
  105.         count=0;
  106.  
  107.         }
  108.  
  109.         if(chances>0)
  110.         cout<<"\n~~~~~~~~~~\nYou Win!!!\n\n'";
  111.         else if(left>0)
  112.                 cout<<"\n\n\n~~~~~~~~~~\nYou Lose!!!\n\n    ___\n   |   |\n   X   |\n  |I|  |\n  //   |\n    ___ \n   |   |\n\n\n'";
  113.         while(count<j)
  114.         {
  115.                 cout<<word[count];
  116.                 ++count;
  117.         }
  118.  
  119.         cout<<"'\n\nWould you like to play again? (Y/N): ";
  120.  
  121.         cin>>again;
  122.         while(again!='Y'&&again!='y'&&again!='N'&&again!='n')
  123.         {
  124.                 cout<<"'\nWould you like to play again? (Y/N): ";
  125.                 cin>>again;
  126.         }
  127.         cout<<"\n\n";
  128.         }
  129.  
  130.         cout<<"Thanks for playing!\n\n";
  131.  
  132.         return 0;
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement