Advertisement
axyd

CS172 l5_Ex24

Apr 14th, 2016
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.41 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4. #include <random>
  5. #include <string>
  6. using namespace std;
  7.     void fMenu(int&, string&); //menu
  8.     void fConvert(int, string&);    //convert number to string 
  9.     void fPC(int&, string&);    //randomize
  10.     void fDetWin(string, string, string&); //decide winner
  11.  
  12.     int main(){
  13.         char repeat = 'y';
  14.         while (repeat == 'y'){
  15.             cout << "\n##Rock, Paper, Scissors##\n\n";
  16.  
  17.             int iMenu; string sMenu;
  18.             fMenu(iMenu, sMenu);
  19.  
  20.             int AInumber; string AIstring;
  21.             fPC(AInumber, AIstring);
  22.            
  23.             string winP = sMenu, winAI = AIstring, winWIN;
  24.             fDetWin(winP, winAI, winWIN);
  25.  
  26.             cout << "\nPlayer picked " << winP << " and AI Picked " << winAI << endl << winWIN;
  27.             if (winP == winAI)
  28.                 cout << "\nIt's a tie, try again\n";
  29.  
  30.             cout << "\n\nPlay again? (y|Y)?  ";
  31.             cin >> repeat;
  32.         }
  33.         return 0;
  34.     }
  35.  
  36.     void fPC(int& fPC_int, string& fPC_str){
  37.         random_device rd;
  38.         mt19937 randRoll(rd());
  39.         uniform_int_distribution<int> uni(1, 3);
  40.         fPC_int = uni(randRoll); int AIint = fPC_int;
  41.  
  42.         if (fPC_int == 1 || fPC_int == 2 || fPC_int == 3)
  43.             fConvert(fPC_int, fPC_str);
  44.     }
  45.  
  46.     void fMenu(int& fMenu_int, string& fMenu_str){
  47.         cout << "(1) Rock\n" << "(2) Paper\n" << "(3) Scissors\n";
  48.         cin >> fMenu_int;
  49.         while (fMenu_int <1 || fMenu_int >3){
  50.             cout << "\t\t/!\\Not a valid choice, try again/!\\\n";
  51.             cin >> fMenu_int;
  52.         }
  53.         fConvert(fMenu_int, fMenu_str);
  54.     }
  55.  
  56.     void fConvert(int fConvert_int, string& fConvert_str){  //Convert number to string
  57.         if (fConvert_int == 1) fConvert_str = "Rock";
  58.         else if (fConvert_int == 2) fConvert_str = "Paper";
  59.         else if (fConvert_int == 3) fConvert_str = "Scissors";
  60.     }
  61.  
  62.     void fDetWin(string fDetWin_strp, string fDetWin_strAI, string& fDetWin_winner){
  63.         string p = fDetWin_strp, ai = fDetWin_strAI;
  64.  
  65.         if (p == "Rock" && ai == "Scissors")
  66.             fDetWin_winner = "The rock smashes the scissors, Player wins";
  67.         else if (p == "Scissors" && ai == "Paper")
  68.             fDetWin_winner = "Scissors cuts paper, Player wins";
  69.         else if (p == "Paper" && ai == "Rock")
  70.             fDetWin_winner = "Paper wraps rock, Player wins";
  71.         else if (ai == "Rock" && p == "Scissors")
  72.             fDetWin_winner = "The rock smashes the scissors, Computer wins";
  73.         else if (ai == "Scissors" && p == "Paper")
  74.             fDetWin_winner = "Scissors cuts paper, Computer wins";
  75.         else if (ai == "Paper" && p == "Rock")
  76.             fDetWin_winner = "Paper wraps rock, Computer wins";
  77.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement