Browse Source

refactoring: findWinner duplications removed

remotes/origin/SchereSteinPapier
Aimee Reincke 2 years ago
parent
commit
03e14ca157
  1. 33
      src/c/rockPaperScissors.c
  2. 15
      src/c/rockPaperScissors.h

33
src/c/rockPaperScissors.c

@ -6,31 +6,20 @@
char findWinner(int inputPlayer, int inputComputer){
if (inputPlayer == inputComputer){
return 'n';
return NOWINNER;
}
else if (inputPlayer == ROCK && inputComputer == SCISSORS) {
return PLAYERWINSROUND;
}
else if (inputPlayer == ROCK){
if (inputComputer == SCISSORS){
return 'p';
}
else if (inputComputer == PAPER){
return 'c';
}
else if (inputPlayer == PAPER && inputComputer == ROCK) {
return PLAYERWINSROUND;
}
else if (inputPlayer == PAPER){
if (inputComputer == ROCK){
return 'p';
}
else if (inputComputer == SCISSORS){
return 'c';
}
else if (inputPlayer == SCISSORS && inputComputer == PAPER) {
return PLAYERWINSROUND;
}
else if (inputPlayer == SCISSORS){
if (inputComputer == PAPER){
return 'p';
}
else if (inputComputer == ROCK){
return 'c';
}
else {
return COMPUTERWINSROUND;
}
}

15
src/c/rockPaperScissors.h

@ -2,11 +2,18 @@
#define ROCKPAPERSCISSORS_H
enum inputOptions{
ROCK = 1,
PAPER = 2,
SCISSORS = 3
};
ROCK,
PAPER,
SCISSORS
};
enum roundWinner{
PLAYERWINSROUND = 'p',
COMPUTERWINSROUND = 'c',
NOWINNER = 'n'
};
char findWinner(int inputPlayer, int inputComputer);
#endif
Loading…
Cancel
Save