Browse Source

refactoring: made print prompt a function + text

remotes/origin/SchereSteinPapier
Aimee Reincke 2 years ago
parent
commit
37c2f33dbd
  1. 7
      src/c/rockPaperScissors.c
  2. 1
      src/c/rockPaperScissors.h

7
src/c/rockPaperScissors.c

@ -12,7 +12,7 @@ int playRockPaperScissors(int rounds){
int roundwinner = NOWINNER; int roundwinner = NOWINNER;
int winner = NOTWONYET; int winner = NOTWONYET;
printf("Lets play a game\n");
printPrompt(roundsToWin);
while (winner == NOTWONYET){ while (winner == NOTWONYET){
playerInput = getPlayerInput(); playerInput = getPlayerInput();
computerInput = getComputerInput(); computerInput = getComputerInput();
@ -92,4 +92,9 @@ int wasGameWon(int roundsToWin, int playerWins, int computerWins){
winner = NOTWONYET; winner = NOTWONYET;
} }
return winner; 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);
} }

1
src/c/rockPaperScissors.h

@ -28,5 +28,6 @@ int wasGameWon(int roundsToWin, int playerWins, int computerWins);
bool validatePlayerInput(int playerInput); bool validatePlayerInput(int playerInput);
int getPlayerInput(); int getPlayerInput();
int playRockPaperScissors(int rounds); int playRockPaperScissors(int rounds);
void printPrompt(int roundsToWin);
#endif #endif
Loading…
Cancel
Save