Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cstdlib>
- #include <random>
- #include <string>
- using namespace std;
- void fMenu(int&, string&); //menu
- void fConvert(int, string&); //convert number to string
- void fPC(int&, string&); //randomize
- void fDetWin(string, string, string&); //decide winner
- int main(){
- char repeat = 'y';
- while (repeat == 'y'){
- cout << "\n##Rock, Paper, Scissors##\n\n";
- int iMenu; string sMenu;
- fMenu(iMenu, sMenu);
- int AInumber; string AIstring;
- fPC(AInumber, AIstring);
- string winP = sMenu, winAI = AIstring, winWIN;
- fDetWin(winP, winAI, winWIN);
- cout << "\nPlayer picked " << winP << " and AI Picked " << winAI << endl << winWIN;
- if (winP == winAI)
- cout << "\nIt's a tie, try again\n";
- cout << "\n\nPlay again? (y|Y)? ";
- cin >> repeat;
- }
- return 0;
- }
- void fPC(int& fPC_int, string& fPC_str){
- random_device rd;
- mt19937 randRoll(rd());
- uniform_int_distribution<int> uni(1, 3);
- fPC_int = uni(randRoll); int AIint = fPC_int;
- if (fPC_int == 1 || fPC_int == 2 || fPC_int == 3)
- fConvert(fPC_int, fPC_str);
- }
- void fMenu(int& fMenu_int, string& fMenu_str){
- cout << "(1) Rock\n" << "(2) Paper\n" << "(3) Scissors\n";
- cin >> fMenu_int;
- while (fMenu_int <1 || fMenu_int >3){
- cout << "\t\t/!\\Not a valid choice, try again/!\\\n";
- cin >> fMenu_int;
- }
- fConvert(fMenu_int, fMenu_str);
- }
- void fConvert(int fConvert_int, string& fConvert_str){ //Convert number to string
- if (fConvert_int == 1) fConvert_str = "Rock";
- else if (fConvert_int == 2) fConvert_str = "Paper";
- else if (fConvert_int == 3) fConvert_str = "Scissors";
- }
- void fDetWin(string fDetWin_strp, string fDetWin_strAI, string& fDetWin_winner){
- string p = fDetWin_strp, ai = fDetWin_strAI;
- if (p == "Rock" && ai == "Scissors")
- fDetWin_winner = "The rock smashes the scissors, Player wins";
- else if (p == "Scissors" && ai == "Paper")
- fDetWin_winner = "Scissors cuts paper, Player wins";
- else if (p == "Paper" && ai == "Rock")
- fDetWin_winner = "Paper wraps rock, Player wins";
- else if (ai == "Rock" && p == "Scissors")
- fDetWin_winner = "The rock smashes the scissors, Computer wins";
- else if (ai == "Scissors" && p == "Paper")
- fDetWin_winner = "Scissors cuts paper, Computer wins";
- else if (ai == "Paper" && p == "Rock")
- fDetWin_winner = "Paper wraps rock, Computer wins";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement