c++ classes you are going to implement a simple Rock, Paper, Scissors game in C+
ID: 3863929 • Letter: C
Question
c++ classes
you are going to implement a simple Rock, Paper, Scissors game in C++. Two players compete and, independently, choose one of Rock, Paper, or Scissors. They then simultaneously declare their choices. The winner of the game is determined by comparing the choices of the players. Rock beats Scissors, Scissors beats Paper, Paper beats Rock. Your task is to produce a set of classes that will allow a human player, typing instructions from the keyboard, to interact with a computer player. An independent referee class will decide whether the human or computer wins the game. In your design, there should at least exist a human player class, a computer player class and a referee class. You probably want to use a game controller class as well but the details are left up to you.Explanation / Answer
#include <iostream>
using namespace std;
class humanClass{
public:
char* moves;
int totalMoves;
int noOfMove;
humanClass(){
cout << "Enter your input: ";
cin >> totalMoves;
moves = new char[totalMoves];
for( int i = 0; i < totalMoves; i++ ){
cin >> moves[i];
}
noOfMove = 0;
}
char move(){
if( noOfMove >= totalMoves ){
cout << "Error" << endl;
return '-';
}
char returnV = moves[noOfMove];
noOfMove = noOfMove + 1;
return returnV;
}
};
class computerClass{
public:
char move(){
return 'R';
}
};
class refereeClass{
public:
void competition( humanClass H, computerClass C ){
int totalMoves = H.totalMoves;
for(int i = 0; i < totalMoves; i++){
char winner = 'T';
char humanMove = H.move();
char compMove = C.move();
if( humanMove=='R'){
if(compMove=='S'){
winner='W'; }
if(compMove=='P'){
winner='L';
}
}
if( humanMove=='S'){
if(compMove=='R'){
winner='L'; }
if(compMove=='P'){
winner='W';
}
}
if( humanMove=='P'){
if(compMove=='S'){
winner='L'; }
if(compMove=='R'){
winner='W';
}
}
cout << winner << " ";
}
cout << endl;
}
};
int main(){
humanClass H;
computerClass C;
refereeClass R;
R.competition( H, C );
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.