From 37c2f33dbd2f8f861e0381958ad407e25d4def6d Mon Sep 17 00:00:00 2001 From: Aimee Reincke Date: Tue, 24 Jan 2023 12:22:23 +0100 Subject: [PATCH] refactoring: made print prompt a function + text --- src/c/rockPaperScissors.c | 7 ++++++- src/c/rockPaperScissors.h | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/c/rockPaperScissors.c b/src/c/rockPaperScissors.c index 25c0f0f..c5105cd 100644 --- a/src/c/rockPaperScissors.c +++ b/src/c/rockPaperScissors.c @@ -12,7 +12,7 @@ int playRockPaperScissors(int rounds){ int roundwinner = NOWINNER; int winner = NOTWONYET; - printf("Lets play a game\n"); + printPrompt(roundsToWin); while (winner == NOTWONYET){ playerInput = getPlayerInput(); computerInput = getComputerInput(); @@ -92,4 +92,9 @@ int wasGameWon(int roundsToWin, int playerWins, int computerWins){ winner = NOTWONYET; } return winner; +} + + +void printPrompt(int roundsToWin){ + printf("Hello NAME.\nLet us play a game, shall we? I assume you are familiar with Rock-Paper-Scissors?\nIf not, here are the rules:\nThe first one to win %d rounds wins the game. Rock beats scissors, scissors beats paper and paper beats rock.\nThey are quite simple, even you should understand. Got it?\n", roundsToWin); } \ No newline at end of file diff --git a/src/c/rockPaperScissors.h b/src/c/rockPaperScissors.h index 3c655e2..7d9c11f 100644 --- a/src/c/rockPaperScissors.h +++ b/src/c/rockPaperScissors.h @@ -28,5 +28,6 @@ int wasGameWon(int roundsToWin, int playerWins, int computerWins); bool validatePlayerInput(int playerInput); int getPlayerInput(); int playRockPaperScissors(int rounds); +void printPrompt(int roundsToWin); #endif \ No newline at end of file