From 8957916a23fb9ac4b6548b6942b421cc5c0dad24 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 11:44:47 +0000 Subject: [PATCH 1/4] display the game board --- src/main/c/GameTic_Tac_Toe/game.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 7d5c061..aeec7e0 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -4,3 +4,16 @@ 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"); + } +} From a2b296651064ff9c44370ae4494e2bbb0b4a5e7e Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 11:45:48 +0000 Subject: [PATCH 2/4] Verification of the winner --- src/main/c/GameTic_Tac_Toe/game.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index aeec7e0..2937166 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -17,3 +17,6 @@ void displayBoard() { if (i < 2) printf("---------\n"); } } + +// Funktion zur Überprüfung des Gewinners +char checkWinner() { From 2d7b1b0e8cda5029a6694ca40002147c4b37f86d Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 11:46:46 +0000 Subject: [PATCH 3/4] Check horizontal and vertical lines --- src/main/c/GameTic_Tac_Toe/game.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 2937166..a08e501 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -20,3 +20,8 @@ void displayBoard() { // 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]; + } From 00ee1fdb18c618c51a313b7a0faa1a1294286c34 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 11:47:58 +0000 Subject: [PATCH 4/4] Check diagonal lines --- src/main/c/GameTic_Tac_Toe/game.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index a08e501..3f1dc5a 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -25,3 +25,7 @@ char checkWinner() { 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]; +