From fea4ba17045318a1aca7c7549b7b06674e151619 Mon Sep 17 00:00:00 2001 From: Aimee Reincke Date: Mon, 23 Jan 2023 10:53:06 +0100 Subject: [PATCH] get player input --- src/c/rockPaperScissors.c | 14 +++++++++++++- src/c/rockPaperScissors.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/c/rockPaperScissors.c b/src/c/rockPaperScissors.c index 7a98a97..fa87c41 100644 --- a/src/c/rockPaperScissors.c +++ b/src/c/rockPaperScissors.c @@ -28,7 +28,7 @@ int findWinner(int inputPlayer, int inputComputer){ } } -int wasGameWon(roundsToWin, playerWins, computerWins){ +int wasGameWon(int roundsToWin, int playerWins, int computerWins){ int winner; if (playerWins == roundsToWin){ winner = PLAYERWINSGAME; @@ -51,4 +51,16 @@ bool validatePlayerInput(int playerInput){ inputValid = false; } return inputValid; +} + +int getPlayerInput(){ + bool inputValid = false; + int inputPlayer; + while(!inputValid){ + printf("Enter your choice:\n1 for Rock\n2 for Paper\n3 for Scissors\n"); + scanf("%d", &inputPlayer); + inputPlayer -= 1; + inputValid = validatePlayerInput(inputPlayer); + } + return inputPlayer; } \ No newline at end of file diff --git a/src/c/rockPaperScissors.h b/src/c/rockPaperScissors.h index d6df3ec..e935a05 100644 --- a/src/c/rockPaperScissors.h +++ b/src/c/rockPaperScissors.h @@ -26,5 +26,6 @@ int findWinner(int inputPlayer, int inputComputer); int getComputerInput(); int wasGameWon(int roundsToWin, int playerWins, int computerWins); bool validatePlayerInput(int playerInput); +int getPlayerInput(); #endif \ No newline at end of file