I've been asked to create a Rock, Paper, scissors game between a human player and a computer player using classes in C++.
Everything is pretty much straight forward other than that they want the human player to have a strategy and it will loop through that strategy to play the game. The user can input how long the strategy will be and then will input what those strategies will be as well after. So for example, if the user inputs 4 R P S S, that means the human strategy is to play Rock then Paper then Scissors then Scissors and then loop back to the start if asked to play more. The computer in this case will always play Rock. And there is a Referee class which will determine the winner here. The output in this case is suppose to look like 4 T L W W. T = tie , L = lose , W = win
Making the .h and .cpp file for the Computer is straight forward as it will always play Rock.
My Problem is that the StrategyCounter gets stuck on 0 and the StrategyCounter++; in the Human::getMove() doesn't increment it.
Keep in mind I can't change the parameters of the functions.
Here is the main file:
int main()
{
Referee ref;
HumanPlayer human;
ComputerPlayer computer;
for (int i=0 ; i<5; i++){
cout<< ref.refGame(human, computer)<< " ";
}
}
Referee.cpp
Referee::Referee(){
}
char Referee::refGame(HumanPlayer human,ComputerPlayer computer){
char s = human.makeMove();
if (s == 'R'){
score = 'T';}
else if (s == 'P'){
score = 'W';}
else if (s == 'S'){
score = 'L';
}
return score;
}
Human.cpp
HumanPlayer::HumanPlayer(){
int r;
cin>>r;
k = r;
cout<< k << " ";
StrategyCounter = 0;
for (int i=0; i<k; i++){
cout << "What the next move?: ";
cin>>Strategy[i];
}
}
char HumanPlayer::makeMove(){
// he should have the startegy here to get results
if (StrategyCounter > k){
StrategyCounter = 0;
}
cout<<StrategyCounter<<endl;
char HumanMove_p;
HumanMove_p = Strategy[StrategyCounter];
StrategyCounter++;
HumanMove = HumanMove_p;
return HumanMove;
}
Human.h
class HumanPlayer
{
public:
HumanPlayer();
int k;
int StrategyCounter;
char *Strategy = new char[k];
char HumanMove;
char makeMove();
};