From fe59a589261a9febec3913b62fa19f9bb6618da7 Mon Sep 17 00:00:00 2001 From: Aimee Reincke Date: Wed, 25 Jan 2023 10:31:25 +0100 Subject: [PATCH] refactoring: extracted setScore function --- src/c/rockPaperScissors.c | 9 +++++++-- src/c/rockPaperScissors.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/c/rockPaperScissors.c b/src/c/rockPaperScissors.c index 9b314e0..1da33e6 100644 --- a/src/c/rockPaperScissors.c +++ b/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); } diff --git a/src/c/rockPaperScissors.h b/src/c/rockPaperScissors.h index fd6333f..224a20d 100644 --- a/src/c/rockPaperScissors.h +++ b/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 \ No newline at end of file