Browse Source

play function

remotes/origin/SchereSteinPapier
Aimee Reincke 2 years ago
parent
commit
01d870252f
  1. 24
      src/c/rockPaperScissors.c
  2. 1
      src/c/rockPaperScissors.h
  3. 7
      test/c/test_rockPaperScissors.c

24
src/c/rockPaperScissors.c

@ -63,4 +63,28 @@ int getPlayerInput(){
inputValid = validatePlayerInput(inputPlayer);
}
return inputPlayer;
}
int play(int rounds){
int playerWins = 0, computerWins = 0;
int roundsToWin = (rounds/2)+1;
int computerInput, playerInput;
int roundwinner = NOWINNER;
int winner = NOTWONYET;
printf("Lets play a game\n");
while (winner == NOTWONYET){
playerInput = getPlayerInput();
computerInput = getComputerInput();
roundwinner = findWinner(playerInput, computerInput);
if (roundwinner == PLAYERWINSROUND){
playerWins += 1;
}
else if (roundwinner == COMPUTERWINSROUND){
computerWins += 1;
}
winner = wasGameWon(roundsToWin, playerWins, computerWins);
printf("Something happened\n");
}
printf("Someone won\n");
}

1
src/c/rockPaperScissors.h

@ -27,5 +27,6 @@ int getComputerInput();
int wasGameWon(int roundsToWin, int playerWins, int computerWins);
bool validatePlayerInput(int playerInput);
int getPlayerInput();
int play(int rounds);
#endif

7
test/c/test_rockPaperScissors.c

@ -214,9 +214,4 @@ void test_rockPaperScissors_invalidPlayerInput(void)
TEST_ASSERT_EQUAL_INT(false, result);
}
#endif // TEST
/*Testcases:
rockPaperScissors_outputResult
rockPaperScissors_invalidInput
*/
#endif // TEST
Loading…
Cancel
Save