Advertisement
paulogp

Russian Roulette

Aug 23rd, 2011
457
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. // msvc++
  2. // paulogp
  3. #include <iostream>
  4. #include <time.h>
  5. #include <Windows.h> // Sleep
  6.  
  7. using namespace std;
  8.  
  9. int randomChamber();
  10. int spinBarrel();
  11.  
  12. int randomChamber()
  13. {
  14.     // 5 bullets chamber
  15.     int the_temp = ((rand() % 5) + 1);
  16.     return the_temp;
  17. }
  18.  
  19. int spinBarrel()
  20. {
  21.     int the_current_chamber;
  22.  
  23.     // assigning the loaded variable a random number
  24.     the_current_chamber = randomChamber();
  25.  
  26.     cout << "spun to chamber " << the_current_chamber << endl;
  27.     cout << "the chambers have been spun." << endl;
  28.  
  29.     return (the_current_chamber);
  30. }
  31.  
  32. int main()
  33. {
  34.     int the_loaded_barrel, the_current_barrel;
  35.     char the_spin;
  36.  
  37.     cout << "welcome to Russian Roulette.\n";
  38.    
  39.     // load gun
  40.     // random seed
  41.     srand (time(NULL));
  42.  
  43.     // assigning the loaded variable a random number
  44.     the_loaded_barrel = randomChamber();
  45.     cout << "the revolver is loaded. spin the Barrel or quit (y, q)? ";
  46.     cin >> the_spin;
  47.  
  48.     // go to game
  49.     if ((the_spin == 'Y') || (the_spin == 'y'))
  50.     {
  51.         the_current_barrel = spinBarrel();
  52.  
  53.         cout << "shaking, you pull the trigger...\n";
  54.  
  55.         // suspense
  56.         Sleep (4000);
  57.  
  58.         if (the_loaded_barrel != the_current_barrel)
  59.             cout << "*click*.... the bullet wasn't in that chamber." << endl;
  60.         else
  61.             cout << "a loud explosion fills your ears, then... nothing.\n" << "-- You lose! --" << endl;
  62.  
  63.         // quit
  64.         Sleep (5000);
  65.     }
  66.    
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement