Browse Source

added play function

remotes/origin/ticTacToe
Aimee Reincke 2 years ago
parent
commit
47f60a0253
  1. 25
      src/c/ticTacToe.c
  2. 1
      src/c/ticTacToe.h

25
src/c/ticTacToe.c

@ -20,6 +20,7 @@ void printField(char field[3][3]){
}
printf("\n");
}
printf("/n");
}
void initField(char field[3][3]) {
@ -864,3 +865,27 @@ void fillAlmostFull(char field[3][3], bool* pt) {
}
}
}
int play() {
printPrompt();
int counter = 0;
char field[3][3];
initField(field);
int winner = NOWINNERYET;
while (winner == NOWINNERYET) {
if (counter % 2 == 0) {
printField(field);
getPlayerInput(field);
winner = wasGameWon(field);
}
else if (counter % 2 == 1) {
printField(field);
getComputerInput(field);
winner = wasGameWon(field);
}
counter += 1;
}
printField(field);
printf("%d", winner);
return winner;
}

1
src/c/ticTacToe.h

@ -17,5 +17,6 @@ bool validatePlayerInput(int row, int col);
int wasGameWon(char field[3][3]);
void getComputerInput(char field[3][3]);
void fillAlmostFull(char field[3][3], bool *pt);
int play();
#endif
Loading…
Cancel
Save