Browse Source

improved random numbers

remotes/origin/SchereSteinPapier
Aimee Reincke 2 years ago
parent
commit
c166123a00
  1. 2
      src/c/rockPaperScissors.c
  2. 3
      src/c/rockPaperScissors.h
  3. 4
      test/c/test_rockPaperScissors.c

2
src/c/rockPaperScissors.c

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <time.h>
#include "rockPaperScissors.h"
@ -56,6 +57,7 @@ bool validatePlayerInput(int playerInput){
int getComputerInput(){
srand(rand() % 300);
int input = rand() % 3;
return input;
}

3
src/c/rockPaperScissors.h

@ -28,5 +28,8 @@ int wasGameWon(int roundsToWin, int playerWins, int computerWins);
bool validatePlayerInput(int playerInput);
int getPlayerInput();
int playRockPaperScissors(int rounds);
void printPrompt(int roundsToWin);
void printResult(int playerInput, int computerInput, int roundWinner, int playerWins, int computerWins);
void printWinner(int winner);
#endif

4
test/c/test_rockPaperScissors.c

@ -31,7 +31,7 @@ void test_rockPaperScissors_playerWinsRound(void)
{
/* arrange */
int result;
int inputPlayer = ROCK;
int inputComputer = SCISSORS;
@ -111,7 +111,7 @@ void test_rockPaperScissors_generateComputerInput(void)
result = getComputerInput();
/* assert */
TEST_ASSERT_EQUAL_INT(ROCK || PAPER || SCISSORS, result);
TEST_ASSERT_INT_WITHIN(1, 1, result);
}

Loading…
Cancel
Save