1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <ctime>
using namespace std;
void pause(double dur); //enables pausing
int identifyH(float x); //supposed to identify if the user input rock paper or scissors based upon number selection
int identifyC(float y); //supposed to identify the computer's selection
int main(int argc, char *argv[])
{
srand(time(0)); //enables the computer to pick a random number
int yon, human, computer; //yon lets the user decide if they want to play (yes or no)
//human is the user's selection
//computer is the computer's selection
float x=human, y=computer; //unsure if needed or not, I tried using it for the functions since they kept on not being recognized
//prompts user if they want to play
cout<<"Lets play rock, paper, scissors!"<<endl;
cout<<"Do you want to play? (Enter 1 for yes, or 0 for no): ";
cin>>yon;
//as long as the user says yes(1) it starts a game of rock paper scissors
while(yon == 1)
{
cout<<"Okay! Choose 1 for Rock, 2 for Paper, or 3 for Scissors, then press [ENTER]."<<endl;
pause(2);
cout<<"Get ready to play!"<<endl;
pause(0.5);
cout<<"1..."<<endl;
pause(0.5);
cout<<"2..."<<endl;
pause(0.5);
cout<<"3..."<<endl;
pause(0.5);
cout<<"Shoot!: ";
cin>>human; //user input
computer=rand()%3+1; //computer's random selection from 1 to 3
//if the user and computer pick the same number
if(human==computer) cout<<"Huh, seems neither of us wins... I mean, since "<<identifyH(human)<<" vs "<<identifyC(computer)<<" is like you punching yourself in the face! Pretty funny, but nothing happens. ;)"<<endl;
//if the computer has the winning number
else if((human==1 && computer==2) || (human==2 && computer==3) || (human==3 && computer==1))
{
cout<<"Ha, ha! Looks like I win! "<<identifyC(computer)<<" beats "<<identifyH(human)<<" :P"<<endl<<"Better luck next time!"<<endl;
}
//if the user has the winning number
else if((human==1 && computer==3) || (human==2 && computer==1) || (human==3 && computer==2))
{
cout<<"Well played, you sneaky devil! "<<identifyH(human)<<" beats "<<identifyC(computer)<<"!"<<endl<<"I'll beat you next time for sure!"<<endl;
}
// if the user selects a number other than 1, 2, or 3
else
{
cout<<"Well, this wasn't supposed to happen! But, I'm pretty sure one of us is cheating. "<<identifyH(human)<<" vs "<<identifyC(computer)<<" doesn't seem like a fair match."<<endl;
}
//prompts user for input if they want to play again, 1 for yes, and anything else really for no.
cout<<"Do you want to play again? (Enter 1 for yes or 0 for no): ";
cin>>yon;
}
//Signals the end of the program
cout<<"Goodbye!"<<endl;
cout<<"Press the [ENTER] key to continue: ";
cin.get();
return(0);
}
//pause function
void pause(double dur)
{
double temp = time(NULL) + dur;
while(temp > time(NULL));
}
//function to identify user's choice
int identifyH(float x)
{
if(human==1) x='rock';
else if(human==2) x='paper';
else if(human==3) x='scissors';
else x='dynamite';
return(x);
}
//function to identify computer's choice
int identifyC(float y)
{
if(computer==1) y='rock';
else if(computer==2) y='paper';
else if(computer==3) y='scissors';
else y='explosions';
return(y);
}
|