|
|
|
|
|
|
|
case R: return ROCK; // No break needed after
case P: return PAPER; // return statement
case S: return SCISSORS;
}
}
//******************************************************************
void ProcessPlays( /* in */ int gameNumber, // Game number
/* in */ PlayType playForA, // A's play
/* in */ PlayType playForB, // B's play
/* inout */ int& winsForA, // A's wins
/* inout */ int& winsForB ) //B's wins
// Determines whether there is a winning play or a tie. If there
// is a winner, the number of wins of the winning player is
// incremented. In all cases, a message is written
// Precondition:
// All parameters are assigned
// Postcondition:
// IF Player A won
// winsForA == winsForA@entry + 1
// ELSE IF Player B won
// winsForB == winsForB@entry + 1
// && A message, including gameNumber, has been written specifying
// either a tie or a winner
{
if (playForA == playForB)
cout < Game number < gameNumber < is a tie.
<endl;
else if (playForA == PAPER && playForB == ROCK ||
playForA == SCISSORS && playForB == PAPER ||
playForA == ROCK && playForB == SCISSORS)
RecordAWin(A, gameNumber, winsForA); // Player A wins
else
RecordAWin(B, gameNumber, winsForB); // Player B wins}
}
//******************************************************************
void RecordAWin( /* in */ char player, // Winning player
/* in */ int gameNumber, // Game number
/* inout */ int& numOfWins ) // Win count
// Outputs a message telling which player has won the current game
// and updates that player's total
|
|
|
|
|
|