Browse Source

get player input

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

14
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;
}

1
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
Loading…
Cancel
Save