The program should meet the following requirements: 1.) The game starts with a m
ID: 663997 • Letter: T
Question
The program should meet the following requirements: 1.) The game starts with a menu. The user is presented with the opportunity to review the rules of the game, or to actually play the game. (It?s up to you if you want to display a menu separately, or integrate the display instructions option within the Rock, Paper, Scissors choice (see 3.a. below). 2.) If the user requests to see the rules, the program displays the rules of the game. 3.) If the user requests to actually play the game: a. The user enters his or her choice of rock paper or scissors at the keyboard. The user should be able to type out his/her choice and press enter. b. The computer randomly picks its choice. (HINT: use the random number generator to generate a number between 0 and 2. Use the random number to represent rock, paper, or scissors.) c. The program then reveals the computer?s choice, displays the user?s choice, and declares a winner (or tie). The winner s determined according to the following rules: . If one player chooses rock and the other player chooses scissors, then the rock wins. (Rock crushes scissors.) . If one player chooses paper and the other chooses rock, then paper wins. (Paper covers rock.) . If one player chooses scissors and the other player chooses paper, then scissors wins. (Scissors cuts paper). . If both players make the same choice, then the game is tie. In order for this program to receive full credit: . The user MUST be able to type in his/her choice: ROCK, PAPER, SCISSORS. . At minimum, the following functions must be used (you can choose to add others, depending on the way you implement the program):Explanation / Answer
#include<iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
// A computer program to play a series of rock-paper-scissors matches
//against the user, with the computer using a random number
//generator to pick its move
//Each match is worth one point, and continues until either the player
//or the computer has won two games
//The tournament consists of three matches: whoever wins the most
//matches wins the tournament
// For the sake of maintainability, use constants to store
//the number of matches in a tournament and
//the number of game wins needed to win a match
//const int MatchWinsNeeded=2;
//const int GameWinsNeeded=2;
int getuserchoice();
int quitORplay();
int playGame(int computermove,int usermove);
int whoWins(int result);
int playMatch(int usergames,int computergames);
//bool playTournament();
//void displayResults(int playerWins, int computerWins);
//FUNCTION TO GET USER'S CHOICE
int getuserchoice()
{
int userchoice;
cout<<"0--------------------rock"<<endl;
cout<<"1--------------------paper"<<endl;
cout<<"2--------------------scissors"<<endl;
cout<<"enter your choice"<<endl;
cin>>userchoice; //reading user's choice
return userchoice;
}
//FUNCTION TO PLAY A GAME
int playGame(int computermove,int usermove)
{
if(computermove==0)
{
cout<<"COMPUTER CHOSES ROCK"<<endl;
if(usermove==0)
{
cout<<"USER ALSO CHOSES ROCK"<<endl;
cout<<"WE BOTH ARE SAME"<<endl;
cout<<"IT IS A DRAW"<<endl;
return 0;
}
else if(usermove==1)
{
cout<<"USER CHOSES PAPER"<<endl;
cout<<"PAPER COVERS THE ROCK"<<endl;
cout<<"USER HAS WON THIS GAME"<<endl;
return 1;
}
else if(usermove==2)
{
cout<<"USER CHOSES SCISSORS"<<endl;
cout<<"ROCK BLUNTS THE SCISSORS"<<endl;
cout<<"COMPUTER HAS WON THIS GAME"<<endl;
return -1;
}
}
if(computermove==1)
{
cout<<"COMPUTER CHOSES PAPER"<<endl;
if(usermove==0)
{
cout<<"USER CHOSES ROCK"<<endl;
cout<<"PAPER COVERS THE ROCK"<<endl;
cout<<"COMPUTER HAS WON THIS GAME"<<endl;
return -1;
}
else if(usermove==1)
{
cout<<"WE BOTH ARE SAME"<<endl;
cout<<"IT IS A DRAW"<<endl;
return 0;
}
else if(usermove==2)
{
cout<<"USER CHOSES SCISSORS"<<endl;
cout<<"SCISSOR CUTS THE PAPER"<<endl;
cout<<"USER HAS WON THIS GAME"<<endl;
return 1;
}
}
if(computermove==2)
{
cout<<"COMPUTER CHOSES SCISSORS"<<endl;
if(usermove==0)
{
cout<<"USER CHOSES ROCK"<<endl;
cout<<"ROCK BLUNTS THE SCISSORS"<<endl;
cout<<"USER HAS WON THIS GAME"<<endl;
return 1;
}
else if(usermove==1)
{
cout<<"USER CHOSES PAPER"<<endl;
cout<<"SCISSORS CUT THE PAPER"<<endl;
cout<<"COMPUTER HAS WON THIS GAME"<<endl;
return -1;
}
else if(usermove==2)
{
cout<<"USER ALSO CHOSES SCISSORS"<<endl;
cout<<"WE BOTH ARE SAME"<<endl;
cout<<"IT IS A DRAW"<<endl;
return 0;
}
}
}
int whoWins(int result)
{
if(result==1)
{
return 1;
}
else if(result==-1)
{
return -1;
}
else
{
return 0;
}
}
//FUNCTION TO PLAY A MATCH
int playMatch(int usergames,int computergames)
{
if(usergames==2)
{
return 1;
}
else if(computergames==2)
{
return -1;
}
}
//FUNCTION FOR PLAYING GAME AGAIN OR TO QUIT FROM THE GAME
int quitORplay()
{
int choice,keepplaying;
cout<<"DO U WANNA QUIT OR PLAY AGAIN"<<endl;
cout<<"press 1 to quit"<<endl;
cout<<"press 0 to play agin"<<endl;
cout<<"Enter Ur Choice"<<endl;
cin>>choice;
if(choice==1)
{
keepplaying=true;
return keepplaying;
}
else
{
return 0;
}
}
int main()
{
bool keepplaying=false;
int result;
int UserComputerGames=0;
int UserComputerMatches=0;
int usermatches=0,computermatches=0,usergames=0,computergames=0;
while(!keepplaying)
{
int computermove,usermove;
computermove=rand()%3; //picking computer's move
usermove=getuserchoice();
result=playGame(computermove,usermove);
UserComputerGames=whoWins(result);
if(UserComputerGames==1)
{
usergames++;
cout<<"User has won "<<usergames<<" games"<<endl;
}
else if(UserComputerGames==-1)
{
computergames++;
cout<<"Computer has won "<<computergames<<" games"<<endl;
}
else
{
cout<<"no one won the game"<<endl;
}
if((usergames==2)||(computergames==2))
{
usergames=0;
computergames=0;
UserComputerMatches=playMatch(usergames,computergames);
}
if(UserComputerMatches==1)
{
usermatches++;
cout<<"User has won "<<usermatches<<" matches"<<endl;
}
else if(UserComputerMatches==-1)
{
computermatches++;
cout<<"Computer has won "<<computermatches<<" matches"<<endl;
}
keepplaying=quitORplay();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.