Browse Source

refactoring: extracted setScore function

remotes/origin/SchereSteinPapier
Aimee Reincke 2 years ago
parent
commit
fe59a58926
  1. 9
      src/c/rockPaperScissors.c
  2. 1
      src/c/rockPaperScissors.h

9
src/c/rockPaperScissors.c

@ -24,17 +24,22 @@ int playRockPaperScissors(int rounds){
void runGame(int *playerWins, int *computerWins){
int computerInput, playerInput;
int roundwinner = NOWINNER;
playerInput = getPlayerInput();
computerInput = getComputerInput();
roundwinner = findWinner(playerInput, computerInput);
setScore(roundwinner, playerWins, computerWins);
printResult(playerInput, computerInput, roundwinner, *playerWins, *computerWins);
}
void setScore(int roundwinner, int *playerWins, int *computerWins){
if (roundwinner == PLAYERWINSROUND){
*playerWins += 1;
}
else if (roundwinner == COMPUTERWINSROUND){
*computerWins += 1;
}
printResult(playerInput, computerInput, roundwinner, *playerWins, *computerWins);
}

1
src/c/rockPaperScissors.h

@ -32,5 +32,6 @@ void printPrompt(int roundsToWin);
void printResult(int playerInput, int computerInput, int roundWinner, int playerWins, int computerWins);
void printWinner(int winner);
void runGame(int *playerWins, int *computerWins);
void setScore(int roundwinner, int *playerWins, int *computerWins);
#endif
Loading…
Cancel
Save