Browse Source

Merge branch 'Ariana' into 'main'

Ariana

See merge request pmuw_projekt/pmuw_projekt_notebinder!17
remotes/origin/fdai7775-main-patch-54732
fdai7775 11 months ago
parent
commit
78ffd44390
  1. 25
      src/main/c/GameTic_Tac_Toe/game.c

25
src/main/c/GameTic_Tac_Toe/game.c

@ -4,3 +4,28 @@ char board[3][3] = {{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'}};
char currentPlayer = 'X';
// Funktionen zur Anzeige des Spielbretts
void displayBoard() {
printf("Tic-Tac-Toe\n");
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
printf("%c", board[i][j]);
if (j < 2) printf(" | ");
}
printf("\n");
if (i < 2) printf("---------\n");
}
}
// Funktion zur Überprüfung des Gewinners
char checkWinner() {
// Überprüfe horizontale und vertikale Linien
for (int i = 0; i < 3; i++) {
if (board[i][0] == board[i][1] && board[i][1] == board[i][2]) return board[i][0];
if (board[0][i] == board[1][i] && board[1][i] == board[2][i]) return board[0][i];
}
// Überprüfe diagonale Linien
if (board[0][0] == board[1][1] && board[1][1] == board[2][2]) return board[0][0];
if (board[0][2] == board[1][1] && board[1][1] == board[2][0]) return board[0][2];
Loading…
Cancel
Save