Question

It's writing a simple rock paper scissors game strictly following the instructions. INSTRUCTIONS: If the user...

It's writing a simple rock paper scissors game strictly following the instructions.

INSTRUCTIONS:
If the user selects 'p':

1. First the program should call a function named getComputerChoice to get the computer's choice in the game. The getComputerChoice function should generate a random number between 1 and 3. If the random number is 1 the computer has chosen Rock, if the random number is 2 the user has chosen Paper, and if the random number is 3 the computer has chosen Scissors. (Hint: return an int from this function and make the function have no arguments). This function is REQUIRED to be a value returning function (do NOT make a void function).



2. Next the program should call a function named getPlayerChoice to get the user's (player's) choice in the game. Have the user's choice be represented by a number just like the computer's was. The getPlayerChoice function should display a menu similar to the one below and then get a 1, 2, or 3 as the user's choice for Rock, Paper or Scissors. Do not allow the user to enter an invalid choice - they must enter 1, 2, or 3 (use integers for the menu on this instead of chars). (Hint: return an int from this function and make the function have no arguments). This function is REQUIRED to be a value returning function (do NOT make a void function).
Rock, Paper or Scissors?

1) Rock

2) Paper

3) Scissors

Please enter your choice:



3. Next the program should display what the user chose and what the computer chose. You will need to convert both the user's and the computer's integer choices of 1, 2, or 3 to the corresponding strings: Rock, Paper, or Scissors. The display should be similar to the following (in the example below the user chose 3 for Scissors and the computer chose 2 for Paper)
You chose: Scissors

The computer chose: Paper



4. Next the program should call a function named isTie (Hint: have the function return a bool and take two arguments) to see if the game was a tie. This function is REQUIRED to be a value returning function and must take TWO arguments (do NOT make a void function). The game is a tie if both the computer and user made the same choice. If the game was a tie display the appropriate message. An example of a tie is shown below with the appropriate message on the third line.

You choose: Scissors

The computer chose: Scissors

It's a TIE!



5. If the game was NOT a tie, the program should next determine if the player (user) has won the game. You should use a function called isPlayerWinnerto do this, the function should take two arguments (the player choice and the computer choice and return true if the player is a winner and false if the player is not a winner). This function is REQUIRED to be a value returning function (do NOT make a void function) The function is required to take two arguments.

After calling the function, based on the result of it, if the player has won the program should display a message similar to the one below telling the user they won. In the example below the user's winning choice is Rock and the computer's losing choice is Scissors. (Remember the rules for winning and losing are at the top of the page)

You choose: Rock

The computer chose: Scissors

You WIN!



6. If the game was NOT a tie and the user (player) did NOT win this means the computer won and the program should display a message saying the user has lost. In the example below the computer's winning choice is Paper (the user's losing choice is Rock). Do not make this complicated, if it was not a tie and the player did not win the computer won.

You choose: Rock

The computer chose: Paper

Sorry you LOSE.



If the user selects q: Quit the program

If the user selects anything other than p or q: Display an error message.

The program should keep re-displaying the menu and let the user play as many games against the computer as they would like.

------------------------------------------------------

The point of this assignment is to divide the program to two cpp files(called play.cpp and playTest.cpp) and one header file(called play.h).

Also, play.cpp should include

#include "play.h" #include <ctime>

using namespace std; string convert(int choice) // moved to a implementation file { string s = ""; switch (choice) { case 1: s = "Rock"; break; case 2: s = "Paper"; break; case 3: s = "Scissors"; break; } return s; }

--------------------------------------------------------------

and testPlay.cpp should include

#include <iostream> #include "play.h" #include <ctime> using namespace std; int main() { char select; int player, computer; //srand(time(NULL)): srand(13);

-----------------------------------------------------------------

and play.h should include

#include <iostream> #include <string> #include <stdlib.h> std::string convert(int); // moved to a header file

---------------------------------------------------------------

It is due by today so it's urgent!!!!!!!!!!!!!!!!!!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ Program:

File: play.h

#ifndef PLAY_H_INCLUDED
#define PLAY_H_INCLUDED

//Function prototypes
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;

string convert(int); // moved to a header file
int getComputerChoice();
int getPlayerChoice();
bool isTie(int,int);
bool isPlayerWinner(int,int);

#endif // PLAY_H_INCLUDED

___________________________________________________________________________________________________________________

File: play.cpp

#include "play.h"
#include <ctime>

using namespace std;

//Convert function
string convert(int choice) // moved to a implementation file
{
string s = "";
switch (choice)
{
case 1: s = "Rock"; break;
case 2: s = "Paper"; break;
case 3: s = "Scissors"; break;
}
return s;
}

//Getting computer choice
int getComputerChoice()
{
return ((rand()%3) + 1);
}

//Getting user input
int getPlayerChoice()
{
int ip;
//Loop till user enters valid input
do
{
//Reading input from user
cout << "\n\nEnter your choice: 1 - Rock \t 2 - Paper \t 3 - Scissors : ";
cin >> ip;

}while(ip < 1 || ip > 3);

//Returning input
return ip;
}

//Check for tie
bool isTie(int player, int computer)
{
//Comparing selections
if(player == computer)
return true;
return false;
}

//Function that checks whether player is winner or not
bool isPlayerWinner(int player1, int player2)
{
//Rock wins over Scissors
if( (player1 == 1 && player2 == 3) || (player1 == 3 && player2 == 1) )
{
if(player1 == 1)
return true;
else
return false;
}
//Scissors win over Paper
else if( (player1 == 2 && player2 == 3) || (player1 == 3 && player2 == 2) )
{
if(player1 == 3)
return true;
else
return false;
}
//Paper wins over Rock
else
{
if(player1 == 2)
return true;
else
return false;
}
return false;
}

_________________________________________________________________________________________________________________________

File: main.cpp

#include <iostream>
#include <ctime>
#include "play.h"

using namespace std;

int main()
{
char select;
int player, computer;
//srand(time(NULL)):
srand(13);

//Loop till user want to quit
while(true)
{
cout << "\n Select your choice: p-play q-quit : ";
cin >> select;

//Selection
switch(select)
{
case 'p':
case 'P':
//Playing game
computer = getComputerChoice();
player = getPlayerChoice();

//Printing selections
cout << "\nYou choose: " << convert(player);
cout << "\nThe computer chose: " << convert(computer);

//Checking result
if(isTie(player, computer))
{
cout << "\nIt's a TIE!\n";
}
else if(isPlayerWinner(player, computer))
{
cout << "\nYou WIN!\n";
}
else
{
cout << "\nSorry you LOSE.\n";
}

break;

case 'q':
case 'Q':
cout << "\nThanks for playing the game...\n";
return 0;

default:
cout << "\n Invalid Choice... \n";
break;
}
}

return 0;
}

__________________________________________________________________________________________________________________________

Sample Run:

C:\TC\RockPaperScissor_Game_cpp\bin\Debug\RockPaperScissor_Game_cpp.exe Select your choice: P-play q-quit : P Enter your choi

Add a comment
Know the answer?
Add Answer to:
It's writing a simple rock paper scissors game strictly following the instructions. INSTRUCTIONS: If the user...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • You are asked to implement scissors-rock-paper game where the players are a computer and a user....

    You are asked to implement scissors-rock-paper game where the players are a computer and a user. The player that wins 3 hands successively is the winner of the game. Your program should prompt the user with a message at the beginning of each hand to enter one of scissors, rock or paper. If the user's entry is not valid, i.e. entry is neither scissors, rock, nor paper, your program throws a message to the user to enter a valid entry...

  • In python language Write a program that lets the user play the game of Rock, Paper,...

    In python language Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: 1. When the program begins, a random number in the range of 1 and 3 is generated. 1 = Computer has chosen Rock 2 = Computer has chosen Paper 3 = Computer has chosen Scissors (Dont display the computer's choice yet) 2. The user enters his or her choice of “Rock”, “Paper", “Scissors" at...

  • C++ Part 2: Rock Paper Scissors Game Write a program that lets the user play this...

    C++ Part 2: Rock Paper Scissors Game Write a program that lets the user play this game against the computer. The program should work as follows: When the program begins, a random number between 1 and 3 is generated. If the number is 1, the computer has chosen rock. If the number is 2, the computer has chosen paper. If the number is 3, the computer has chosen scissors. Don't display the computer's choice yet. Use a menu to display...

  • In this problem, you’ll play a simple rock, paper, scissors game. First, you’ll ask the user...

    In this problem, you’ll play a simple rock, paper, scissors game. First, you’ll ask the user to pick rock, paper, or scissors. Then, you’ll have the computer randomly choose one of the options. After that, print out the winner! You should keep playing the game until the user hits enter. Note: You’ll need to implement a method called String getWinner(String user, String computer). Luckily, you just wrote that in an earlier program! Here is a sample run of the program....

  • IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors...

    IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. Don’t display the computer’s choice yet....

  • (Java) Write a program that lets the user play the game of Rock, Paper, Scissors against...

    (Java) Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. Don’t display the computer’s choice yet. The...

  • Write a C# program that allows one user to play Rock-Paper-Scissors with computer. The user will...

    Write a C# program that allows one user to play Rock-Paper-Scissors with computer. The user will pick a move (Rock Paper Scissors) from 3 radio buttons and click the play button to play the game. The application will use random number generator to pick a move for the computer. Then, the application display the computer's move and also display whether you won or lost the game, or the game is tie if both moves are the same. The application must...

  • java pls Rock Paper Scissors Lizard Spock Rock Paper Scissors Lizard Spock is a variation of...

    java pls Rock Paper Scissors Lizard Spock Rock Paper Scissors Lizard Spock is a variation of the common game Rock Paper Scissors that is often used to pass time (or sometimes to make decisions.) The rules of the game are outlined below: • • Scissors cuts Paper Paper covers Rock Rock crushes Lizard Lizard poisons Spock Spock smashes Scissors Scissors decapitates Lizard Lizard eats Paper Paper disproves Spock Spock vaporizes Rock Rock crushes Scissors Write a program that simulates the...

  • C++ You are asked to implement scissors-rock-paper game where the players are a computer and a...

    C++ You are asked to implement scissors-rock-paper game where the players are a computer and a user. The player that wins 3 hands successively is the winner of the game. Your program should prompt the user with a message at the beginning of each hand to enter one of scissors, rock or paper. If the user’s entry is not valid, i.e. entry is neither scissors, rock, nor paper, your program throws a message to the user to enter a valid...

  • In JAVA Chapter 5Assignment(Rock, Paper, Scissors)–20pointsYour goal is towrite a program that lets the user play...

    In JAVA Chapter 5Assignment(Rock, Paper, Scissors)–20pointsYour goal is towrite a program that lets the user play the game of Rock, Paper, Scissors against the computer.Your program should have the following: •Make the name of the project RockPaperScissors•Write a method that generates a random number in the range of 1 through 3. The randomly generated number will determine if the computer chooses rock, paper, or scissors. If the number is 1, then the computer has chosen rock. If the number is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT