From 2b6525889c54d29e4af02e363dbb269769326310 Mon Sep 17 00:00:00 2001 From: fdai8032 Date: Tue, 9 Jan 2024 10:09:40 +0000 Subject: [PATCH 001/164] Add new directory --- src/test/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/test/.gitkeep diff --git a/src/test/.gitkeep b/src/test/.gitkeep new file mode 100644 index 0000000..e69de29 From 5410efd702f006db61964d8915add1cd63958ac9 Mon Sep 17 00:00:00 2001 From: fdai8032 Date: Tue, 9 Jan 2024 10:09:58 +0000 Subject: [PATCH 002/164] Add new directory --- src/test/c/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/test/c/.gitkeep diff --git a/src/test/c/.gitkeep b/src/test/c/.gitkeep new file mode 100644 index 0000000..e69de29 From 8153810d1213169a69e26c062c17838f8cbf9d94 Mon Sep 17 00:00:00 2001 From: fdai8032 Date: Tue, 9 Jan 2024 10:10:11 +0000 Subject: [PATCH 003/164] Delete .gitkeep --- src/test/c/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/test/c/.gitkeep diff --git a/src/test/c/.gitkeep b/src/test/c/.gitkeep deleted file mode 100644 index e69de29..0000000 From de49deaad0cbc93c3f25c6fc15793f3fddf5215a Mon Sep 17 00:00:00 2001 From: fdai8032 Date: Tue, 9 Jan 2024 10:10:29 +0000 Subject: [PATCH 004/164] Add new directory --- src/test/c/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/test/c/.gitkeep diff --git a/src/test/c/.gitkeep b/src/test/c/.gitkeep new file mode 100644 index 0000000..e69de29 From 436c1555bd87dbe3919df3aa38116c38c773fa7c Mon Sep 17 00:00:00 2001 From: fdai8032 Date: Tue, 9 Jan 2024 10:10:58 +0000 Subject: [PATCH 005/164] Delete .gitkeep --- src/test/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/test/.gitkeep diff --git a/src/test/.gitkeep b/src/test/.gitkeep deleted file mode 100644 index e69de29..0000000 From 0d26209ce929ed5a53d581e5ece22e3909f8051c Mon Sep 17 00:00:00 2001 From: fdai8032 Date: Wed, 17 Jan 2024 18:39:56 +0000 Subject: [PATCH 006/164] Delete .gitkeep --- src/test/c/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 src/test/c/.gitkeep diff --git a/src/test/c/.gitkeep b/src/test/c/.gitkeep deleted file mode 100644 index e69de29..0000000 From a6b6a633c6b7b72d3d071a5fd88c3866f76fc2c0 Mon Sep 17 00:00:00 2001 From: fdai7729 Date: Tue, 23 Jan 2024 15:23:39 +0000 Subject: [PATCH 007/164] Update team.md --- team.md | 1 + 1 file changed, 1 insertion(+) diff --git a/team.md b/team.md index bdce5f5..9054457 100644 --- a/team.md +++ b/team.md @@ -2,3 +2,4 @@ - Julia Selig, fdai8040 - Ariana Ginju, fdai7775 - Saba Fazlali, fdai7875 +- Nina Gärtner, fdai7729 From b9cc942a3b82de120c548bb980f1cb4abd5f01fe Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Wed, 24 Jan 2024 12:36:32 +0000 Subject: [PATCH 008/164] Add new directory --- src/main/c/GameTic_Tac_Toe/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/c/GameTic_Tac_Toe/.gitkeep diff --git a/src/main/c/GameTic_Tac_Toe/.gitkeep b/src/main/c/GameTic_Tac_Toe/.gitkeep new file mode 100644 index 0000000..e69de29 From 239329dcb0d1f96212add1daf769dda5ac7f1fe6 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Wed, 24 Jan 2024 12:44:46 +0000 Subject: [PATCH 009/164] Add new file --- src/main/c/GameTic_Tac_Toe/temp | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/main/c/GameTic_Tac_Toe/temp diff --git a/src/main/c/GameTic_Tac_Toe/temp b/src/main/c/GameTic_Tac_Toe/temp new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/main/c/GameTic_Tac_Toe/temp @@ -0,0 +1 @@ + From ebfdb2133a457dcc45f56d980572263c0ca30a12 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Wed, 24 Jan 2024 12:45:27 +0000 Subject: [PATCH 010/164] Add new file --- src/main/c/GameTic_Tac_Toe/temp | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/main/c/GameTic_Tac_Toe/temp diff --git a/src/main/c/GameTic_Tac_Toe/temp b/src/main/c/GameTic_Tac_Toe/temp new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/main/c/GameTic_Tac_Toe/temp @@ -0,0 +1 @@ + From 376d864b3a65658c1f6c50b5e182cbb9d365cf7a Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Wed, 24 Jan 2024 13:04:28 +0000 Subject: [PATCH 011/164] Delete temp --- src/main/c/GameTic_Tac_Toe/temp | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/main/c/GameTic_Tac_Toe/temp diff --git a/src/main/c/GameTic_Tac_Toe/temp b/src/main/c/GameTic_Tac_Toe/temp deleted file mode 100644 index 8b13789..0000000 --- a/src/main/c/GameTic_Tac_Toe/temp +++ /dev/null @@ -1 +0,0 @@ - From b50761f3182096294c5a2ad328b0e5d25ac548fd Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Wed, 24 Jan 2024 14:21:33 +0100 Subject: [PATCH 012/164] added global board --- src/main/c/GameTic_Tac_Toe/game.c | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/c/GameTic_Tac_Toe/game.c diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c new file mode 100644 index 0000000..7d5c061 --- /dev/null +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -0,0 +1,6 @@ +#include + +char board[3][3] = {{'1', '2', '3'}, + {'4', '5', '6'}, + {'7', '8', '9'}}; +char currentPlayer = 'X'; From 8957916a23fb9ac4b6548b6942b421cc5c0dad24 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 11:44:47 +0000 Subject: [PATCH 013/164] 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 014/164] 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 015/164] 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 016/164] 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]; + From 22ce5b5fc45d3de430691a3439044bfb96a2d4f7 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 11:52:41 +0000 Subject: [PATCH 017/164] No 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 3f1dc5a..a91ba51 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -29,3 +29,6 @@ char checkWinner() { 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]; + // Kein Gewinner + return ' '; +} From f770bfd5d647d60b268f0a267b006343b50c2aaa Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 11:58:28 +0000 Subject: [PATCH 018/164] Verification function --- src/main/c/GameTic_Tac_Toe/game.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index a91ba51..6432f7f 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -32,3 +32,15 @@ char checkWinner() { // Kein Gewinner return ' '; } + +// Funktion zur Überprüfung, ob das Spiel unentschieden ist +int isBoardFull() { + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (board[i][j] != 'X' && board[i][j] != 'O') { + return 0; + } + } + } + return 1; +} From d75ff5cdbf9d229e47f300ecee996e83ec902ae4 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 11:59:42 +0000 Subject: [PATCH 019/164] Function: A player's turn --- src/main/c/GameTic_Tac_Toe/game.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 6432f7f..089012b 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -44,3 +44,11 @@ int isBoardFull() { } return 1; } + + +// Funktion zum Zug eines Spielers +void makeMove() { + int choice; + printf("Spieler %c, wähle eine Zahl (1-9): ", currentPlayer); + scanf("%d", &choice); + From 95c97636763ff420483d77a59bf813e4fac5b54d Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 12:00:33 +0000 Subject: [PATCH 020/164] Convert the number --- 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 089012b..48035ae 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -52,3 +52,7 @@ void makeMove() { printf("Spieler %c, wähle eine Zahl (1-9): ", currentPlayer); scanf("%d", &choice); +// Konvertiere die Zahl in Zeilen- und Spaltenindex + int row = (choice - 1) / 3; + int col = (choice - 1) % 3; + From c0df50c14754154612ecd07674579ea5abdeb251 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 12:01:52 +0000 Subject: [PATCH 021/164] Check whether the selected field is valid --- 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 48035ae..f0ddb37 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -56,3 +56,7 @@ void makeMove() { int row = (choice - 1) / 3; int col = (choice - 1) % 3; + // Überprüfe, ob das gewählte Feld gültig ist + if (choice >= 1 && choice <= 9 && board[row][col] != 'X' && board[row][col] != 'O') { + + From 68f804befc16b175915ddd7c4aa066c3b5667d32 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 12:02:18 +0000 Subject: [PATCH 022/164] Update game.c --- src/main/c/GameTic_Tac_Toe/game.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index f0ddb37..5129548 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -58,5 +58,6 @@ void makeMove() { // Überprüfe, ob das gewählte Feld gültig ist if (choice >= 1 && choice <= 9 && board[row][col] != 'X' && board[row][col] != 'O') { - + board[row][col] = currentPlayer; + } else { From 57ff8f28ae42deb751d92346429a7eb54dee673d Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 12:03:21 +0000 Subject: [PATCH 023/164] Invalid move --- src/main/c/GameTic_Tac_Toe/game.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 5129548..51f5c7c 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -60,4 +60,7 @@ void makeMove() { if (choice >= 1 && choice <= 9 && board[row][col] != 'X' && board[row][col] != 'O') { board[row][col] = currentPlayer; } else { - + printf("Ungültiger Zug! Bitte wähle erneut.\n"); + makeMove(); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird + } +} From e99a489aa351de1759d2f54cc771860fb8a7e88b Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 12:04:05 +0000 Subject: [PATCH 024/164] Update main --- 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 51f5c7c..85a08a2 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -64,3 +64,8 @@ void makeMove() { makeMove(); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird } } + +int main() { + while (1) { + displayBoard(); + makeMove(); From 097e26462eaec31300dc48366252ef1f57ebbd12 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 12:05:23 +0000 Subject: [PATCH 025/164] check winner --- src/main/c/GameTic_Tac_Toe/game.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 85a08a2..215af00 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -69,3 +69,10 @@ int main() { while (1) { displayBoard(); makeMove(); + + char winner = checkWinner(); + if (winner == 'X' || winner == 'O') { + displayBoard(); + printf("Spieler %c gewinnt!\n", winner); + break; + } From c4c5255c32e69b0b45164e5fe6098ead52f76bcb Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 12:20:45 +0000 Subject: [PATCH 026/164] possibility: draw --- src/main/c/GameTic_Tac_Toe/game.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 215af00..0f0d6f8 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -76,3 +76,9 @@ int main() { printf("Spieler %c gewinnt!\n", winner); break; } + + if (isBoardFull()) { + displayBoard(); + printf("Unentschieden!\n"); + break; + } From 44325c521fed24d036f30b85d670ff9f5af962e8 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 12:22:57 +0000 Subject: [PATCH 027/164] Change player --- src/main/c/GameTic_Tac_Toe/game.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 0f0d6f8..b20f125 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -82,3 +82,10 @@ int main() { printf("Unentschieden!\n"); break; } + + // Wechsle den Spieler + currentPlayer = (currentPlayer == 'X') ? 'O' : 'X'; + } + + return 0; +} From eb9a2755fe911b7b7760353dc20384acbea304d5 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 16:57:40 +0000 Subject: [PATCH 028/164] refactoring: lear condition for an invalid move --- src/main/c/GameTic_Tac_Toe/game.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index b20f125..11d2a79 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -57,11 +57,11 @@ void makeMove() { int col = (choice - 1) % 3; // Überprüfe, ob das gewählte Feld gültig ist - if (choice >= 1 && choice <= 9 && board[row][col] != 'X' && board[row][col] != 'O') { - board[row][col] = currentPlayer; - } else { - printf("Ungültiger Zug! Bitte wähle erneut.\n"); + if (choice < 1 || choice > 9 || board[row][col] == 'X' || board[row][col] == 'O') { + printf("Ungültiger Zug! Bitte wähle erneut.\n"); makeMove(); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird + } else { + board[row][col] = currentPlayer; } } From 5567f10afcad179c0a7def3929b264a963b207a5 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 17:05:35 +0000 Subject: [PATCH 029/164] refactoring: using else and if --- src/main/c/GameTic_Tac_Toe/game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 11d2a79..278b1e5 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -27,7 +27,7 @@ char checkWinner() { } // Ü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]; + else if (board[0][2] == board[1][1] && board[1][1] == board[2][0]) return board[0][2]; // Kein Gewinner return ' '; From 4af8ceda5d461297fa85ba5c0bf158a4874f1090 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 17:15:30 +0000 Subject: [PATCH 030/164] refactoring: using an auxiliary feature for win conditions --- src/main/c/GameTic_Tac_Toe/game.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 278b1e5..0765c17 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -17,13 +17,19 @@ void displayBoard() { if (i < 2) printf("---------\n"); } } - +char checkLine(char a, char b, char c) { + if (a == b && b == c) return a; + return ' '; +} // 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]; + for (int i = 0; i < 3; i++) { + char horizontalWinner = checkLine(board[i][0], board[i][1], board[i][2]); + char verticalWinner = checkLine(board[0][i], board[1][i], board[2][i]); + + if (horizontalWinner != ' ') return horizontalWinner; + if (verticalWinner != ' ') return verticalWinner; } // Überprüfe diagonale Linien if (board[0][0] == board[1][1] && board[1][1] == board[2][2]) return board[0][0]; From ad6d3bbdcfe3e7aad435dee8e30e4bcfb7ff818a Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 17:18:52 +0000 Subject: [PATCH 031/164] refactoring: using an auxiliary function for diagonal lines --- src/main/c/GameTic_Tac_Toe/game.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 0765c17..215f890 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -32,8 +32,11 @@ char checkWinner() { if (verticalWinner != ' ') return verticalWinner; } // Überprüfe diagonale Linien - if (board[0][0] == board[1][1] && board[1][1] == board[2][2]) return board[0][0]; - else if (board[0][2] == board[1][1] && board[1][1] == board[2][0]) return board[0][2]; + char diagonal1Winner = checkLine(board[0][0], board[1][1], board[2][2]); + char diagonal2Winner = checkLine(board[0][2], board[1][1], board[2][0]); + + if (diagonal1Winner != ' ') return diagonal1Winner; + if (diagonal2Winner != ' ') return diagonal2Winner; // Kein Gewinner return ' '; From a6c12ae026290794ac6649cdae8e9da72d85f285 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 17:43:49 +0000 Subject: [PATCH 032/164] refactoring: logic functions for player exchange --- 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 215f890..a3f3ae2 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -56,6 +56,10 @@ int isBoardFull() { // Funktion zum Zug eines Spielers +char switchPlayer(char currentPlayer) { + return (currentPlayer == 'X') ? 'O' : 'X'; +} + void makeMove() { int choice; printf("Spieler %c, wähle eine Zahl (1-9): ", currentPlayer); @@ -71,6 +75,7 @@ void makeMove() { makeMove(); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird } else { board[row][col] = currentPlayer; + currentPlayer = switchPlayer(currentPlayer); } } From 6e55a92f3ee10ff8330579b75aec2beff2e2b58d Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 17:53:55 +0000 Subject: [PATCH 033/164] refactoring: separation of the game loop into functions --- src/main/c/GameTic_Tac_Toe/game.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index a3f3ae2..f193efa 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -79,7 +79,7 @@ void makeMove() { } } -int main() { +void playGame() { while (1) { displayBoard(); makeMove(); @@ -95,11 +95,10 @@ int main() { displayBoard(); printf("Unentschieden!\n"); break; - } - - // Wechsle den Spieler - currentPlayer = (currentPlayer == 'X') ? 'O' : 'X'; + } } - +} +int main(){ + playGame(); return 0; } From 36d75c111cbcc1a583de5762d5d8ef4b44f708c1 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 17:56:28 +0000 Subject: [PATCH 034/164] refactoring: using const --- src/main/c/GameTic_Tac_Toe/game.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index f193efa..f20e298 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -43,9 +43,11 @@ char checkWinner() { } // Funktion zur Überprüfung, ob das Spiel unentschieden ist +const int BOARD_SIZE = 3; + int isBoardFull() { - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { + for (int i = 0; i < BOARD_SIZE; i++) { + for (int j = 0; j < BOARD_SIZE; j++) { if (board[i][j] != 'X' && board[i][j] != 'O') { return 0; } From 6c7fc28dc481897bcb97ca729968930eb764239c Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 18:04:27 +0000 Subject: [PATCH 035/164] refactoring: Clear condition in makeMove --- src/main/c/GameTic_Tac_Toe/game.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index f20e298..ece4bb7 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -62,22 +62,28 @@ char switchPlayer(char currentPlayer) { return (currentPlayer == 'X') ? 'O' : 'X'; } +int isValidMove(int choice) { + int row = (choice - 1) / BOARD_SIZE; + int col = (choice - 1) % BOARD_SIZE; + + return (choice >= 1 && choice <= BOARD_SIZE * BOARD_SIZE && board[row][col] != 'X' && board[row][col] != 'O'); +} + void makeMove() { int choice; - printf("Spieler %c, wähle eine Zahl (1-9): ", currentPlayer); + printf("Spieler %c, waehle eine Zahl (1-9): ", currentPlayer); scanf("%d", &choice); // Konvertiere die Zahl in Zeilen- und Spaltenindex - int row = (choice - 1) / 3; - int col = (choice - 1) % 3; - - // Überprüfe, ob das gewählte Feld gültig ist - if (choice < 1 || choice > 9 || board[row][col] == 'X' || board[row][col] == 'O') { - printf("Ungültiger Zug! Bitte wähle erneut.\n"); - makeMove(); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird - } else { - board[row][col] = currentPlayer; - currentPlayer = switchPlayer(currentPlayer); +if (isValidMove(choice)) { + int row = (choice - 1) / / BOARD_SIZE; + int col = (choice - 1) % % BOARD_SIZE; + board[row][col] = currentPlayer; + currentPlayer = switchPlayer(currentPlayer); + +} else { + printf("Ungueltiger Zug! Bitte waehle erneut.\n"); + makeMove(); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird } } From 18a2eeaa64286be27a672a14db8e5d93166e5d17 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 18:07:39 +0000 Subject: [PATCH 036/164] Update: corrected errors --- src/main/c/GameTic_Tac_Toe/game.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index ece4bb7..e56e55f 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -76,8 +76,8 @@ void makeMove() { // Konvertiere die Zahl in Zeilen- und Spaltenindex if (isValidMove(choice)) { - int row = (choice - 1) / / BOARD_SIZE; - int col = (choice - 1) % % BOARD_SIZE; + int row = (choice - 1) / BOARD_SIZE; + int col = (choice - 1) % BOARD_SIZE; board[row][col] = currentPlayer; currentPlayer = switchPlayer(currentPlayer); From 1abf73507ee06529b853a80e64fbae52006217dc Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 18:14:59 +0000 Subject: [PATCH 038/164] refactoring: Using const for game symbol constants --- src/main/c/GameTic_Tac_Toe/game.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index e56e55f..ec98aec 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -4,7 +4,8 @@ char board[3][3] = {{'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}}; char currentPlayer = 'X'; - +const char PLAYER_X = 'X'; +const char PLAYER_O = 'O'; // Funktionen zur Anzeige des Spielbretts void displayBoard() { printf("Tic-Tac-Toe\n"); From 98533bbc98c2651716fbe3ed42f4f902a0cfb337 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 18:16:46 +0000 Subject: [PATCH 039/164] refactoring: Removing the currentPlayer global variable --- src/main/c/GameTic_Tac_Toe/game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index ec98aec..8615cb8 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -60,7 +60,7 @@ int isBoardFull() { // Funktion zum Zug eines Spielers char switchPlayer(char currentPlayer) { - return (currentPlayer == 'X') ? 'O' : 'X'; + return (currentPlayer == PLAYER_X) ? PLAYER_O : PLAYER_X; } int isValidMove(int choice) { From 6a843132cff3f0493108d4e31870d35d49c0f615 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 18:20:35 +0000 Subject: [PATCH 040/164] refactoring: Using a loop --- src/main/c/GameTic_Tac_Toe/game.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 8615cb8..177acc8 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -6,16 +6,22 @@ char board[3][3] = {{'1', '2', '3'}, char currentPlayer = 'X'; const char PLAYER_X = 'X'; const char PLAYER_O = 'O'; + // 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++) { + for (int i = 0; i < BOARD_SIZE; i++) { + for (int j = 0; j < BOARD_SIZE; j++) { printf("%c", board[i][j]); - if (j < 2) printf(" | "); - } + if (j < BOARD_SIZE - 1) printf(" | "); + } printf("\n"); - if (i < 2) printf("---------\n"); + if (i < BOARD_SIZE - 1) { + for (int k = 0; k < BOARD_SIZE * 4 - 1; k++) { + printf("-"); + } + printf("\n"); + } } } char checkLine(char a, char b, char c) { From 6956db884ccb4754d4f78c00e834035ca2244b8d Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 18:35:42 +0000 Subject: [PATCH 041/164] refactoring: char replaced with enum --- src/main/c/GameTic_Tac_Toe/game.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 177acc8..ea95618 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -24,14 +24,16 @@ void displayBoard() { } } } + char checkLine(char a, char b, char c) { if (a == b && b == c) return a; return ' '; } + // Funktion zur Überprüfung des Gewinners char checkWinner() { // Überprüfe horizontale und vertikale Linien - for (int i = 0; i < 3; i++) { + for (int i = 0; i < BOARD_SIZE; i++) { char horizontalWinner = checkLine(board[i][0], board[i][1], board[i][2]); char verticalWinner = checkLine(board[0][i], board[1][i], board[2][i]); @@ -65,7 +67,7 @@ int isBoardFull() { // Funktion zum Zug eines Spielers -char switchPlayer(char currentPlayer) { +enum switchPlayer(enum currentPlayer) { return (currentPlayer == PLAYER_X) ? PLAYER_O : PLAYER_X; } From 2ce9e44041607a5540c09bd2e23d749023f89b9b Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 18:44:21 +0000 Subject: [PATCH 042/164] refactoring: replacing larger parts --- src/main/c/GameTic_Tac_Toe/game.c | 35 ++++++++++++++++--------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index ea95618..3b7f017 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -80,14 +80,14 @@ int isValidMove(int choice) { void makeMove() { int choice; - printf("Spieler %c, waehle eine Zahl (1-9): ", currentPlayer); + printf("Spieler %c, waehle eine Zahl (1-9): ", currentPlayer == PLAYER_X) ? 'X' : 'O'); scanf("%d", &choice); // Konvertiere die Zahl in Zeilen- und Spaltenindex if (isValidMove(choice)) { int row = (choice - 1) / BOARD_SIZE; int col = (choice - 1) % BOARD_SIZE; - board[row][col] = currentPlayer; + board[row][col] = currentPlayer == PLAYER_X) ? 'X' : 'O'; currentPlayer = switchPlayer(currentPlayer); } else { @@ -96,25 +96,26 @@ if (isValidMove(choice)) { } } +int isGameOver() { + char winner = checkWinner(); + return (winner == PLAYER_X || winner == PLAYER_O || isBoardFull()); +} + +void printGameResult(char winner) { + if (winner == PLAYER_X || winner == PLAYER_O) { + printf("Spieler %c gewinnt!\n", (winner == PLAYER_X) ? 'X' : 'O'); + } else { + printf("Unentschieden!\n"); + } +} + void playGame() { - while (1) { + while (!isGameOver()) { displayBoard(); makeMove(); - - char winner = checkWinner(); - if (winner == 'X' || winner == 'O') { - displayBoard(); - printf("Spieler %c gewinnt!\n", winner); - break; - } - - if (isBoardFull()) { - displayBoard(); - printf("Unentschieden!\n"); - break; - } } -} + + //Fehlt etwas, änderung folgt; int main(){ playGame(); return 0; From 673de7e2e293f3540618bd7bdec3b39ec5fd28c6 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 18:45:51 +0000 Subject: [PATCH 043/164] refactoring: added missing part --- src/main/c/GameTic_Tac_Toe/game.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 3b7f017..f72b814 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -115,7 +115,11 @@ void playGame() { makeMove(); } - //Fehlt etwas, änderung folgt; + displayBoard(); + char winner = checkWinner(); + printGameResult(winner); +} + int main(){ playGame(); return 0; From b12449338944ee154d3da893562a62fd897012e8 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Tue, 30 Jan 2024 19:14:53 +0000 Subject: [PATCH 044/164] refactoring: correct the errors --- src/main/c/GameTic_Tac_Toe/game.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index f72b814..443fe8d 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -1,5 +1,6 @@ #include +const int BOARD_SIZE = 3; char board[3][3] = {{'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}}; @@ -52,8 +53,6 @@ char checkWinner() { } // Funktion zur Überprüfung, ob das Spiel unentschieden ist -const int BOARD_SIZE = 3; - int isBoardFull() { for (int i = 0; i < BOARD_SIZE; i++) { for (int j = 0; j < BOARD_SIZE; j++) { @@ -67,7 +66,7 @@ int isBoardFull() { // Funktion zum Zug eines Spielers -enum switchPlayer(enum currentPlayer) { +char switchPlayer(char currentPlayer) { return (currentPlayer == PLAYER_X) ? PLAYER_O : PLAYER_X; } @@ -80,14 +79,14 @@ int isValidMove(int choice) { void makeMove() { int choice; - printf("Spieler %c, waehle eine Zahl (1-9): ", currentPlayer == PLAYER_X) ? 'X' : 'O'); + printf("Spieler %c, waehle eine Zahl (1-9): ", (currentPlayer == PLAYER_X) ? 'X' : 'O'); scanf("%d", &choice); // Konvertiere die Zahl in Zeilen- und Spaltenindex if (isValidMove(choice)) { int row = (choice - 1) / BOARD_SIZE; int col = (choice - 1) % BOARD_SIZE; - board[row][col] = currentPlayer == PLAYER_X) ? 'X' : 'O'; + board[row][col] = (currentPlayer == PLAYER_X) ? 'X' : 'O'; currentPlayer = switchPlayer(currentPlayer); } else { From 1ac053a2dca41b1b2e44ef8c012ab77c8c29311a Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 12:19:57 +0000 Subject: [PATCH 045/164] Erstelle eine neues Verzeichnis --- src/main/c/Pong/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/c/Pong/.gitkeep diff --git a/src/main/c/Pong/.gitkeep b/src/main/c/Pong/.gitkeep new file mode 100644 index 0000000..e69de29 From 0c2593924dddf30a0603fb7c451850ac045f1e00 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 12:21:06 +0000 Subject: [PATCH 046/164] Add new file --- src/main/c/Pong/game.c | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/main/c/Pong/game.c diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/main/c/Pong/game.c @@ -0,0 +1 @@ + From 66b03b0a20621e2660b7f2c9077a7023d8ce5da4 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Wed, 31 Jan 2024 12:23:59 +0000 Subject: [PATCH 047/164] Add new directory --- test/tests_tictactoe.game/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/tests_tictactoe.game/.gitkeep diff --git a/test/tests_tictactoe.game/.gitkeep b/test/tests_tictactoe.game/.gitkeep new file mode 100644 index 0000000..e69de29 From 5e74794e40fd23875ccb0ff5b9056fd47fe2c236 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Wed, 31 Jan 2024 12:27:00 +0000 Subject: [PATCH 048/164] Delete .gitkeep --- test/tests_tictactoe.game/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test/tests_tictactoe.game/.gitkeep diff --git a/test/tests_tictactoe.game/.gitkeep b/test/tests_tictactoe.game/.gitkeep deleted file mode 100644 index e69de29..0000000 From d6dd92dc1e6a83cac81770d4236ab31892ad02b1 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Wed, 31 Jan 2024 12:28:08 +0000 Subject: [PATCH 049/164] Add new file --- test/test_tictactoe.c | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/test_tictactoe.c diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/test/test_tictactoe.c @@ -0,0 +1 @@ + From 556ecbe863183e310fe004c143da33133a1cf60d Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Wed, 31 Jan 2024 12:32:21 +0000 Subject: [PATCH 050/164] Update game.c --- src/main/c/GameTic_Tac_Toe/game.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 443fe8d..62b99bc 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -64,7 +64,6 @@ int isBoardFull() { return 1; } - // Funktion zum Zug eines Spielers char switchPlayer(char currentPlayer) { return (currentPlayer == PLAYER_X) ? PLAYER_O : PLAYER_X; From 8b88c2fbc974b4564ca0977ee294a7979f941a2b Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Wed, 24 Jan 2024 12:36:32 +0000 Subject: [PATCH 052/164] Add new directory Author: Ariana Ginju --- src/main/c/GameTic_Tac_Toe/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/main/c/GameTic_Tac_Toe/.gitkeep diff --git a/src/main/c/GameTic_Tac_Toe/.gitkeep b/src/main/c/GameTic_Tac_Toe/.gitkeep new file mode 100644 index 0000000..e69de29 From 2c08c49fdf287f7dcb61a0f36b8d25a2472da8a7 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Wed, 24 Jan 2024 12:45:27 +0000 Subject: [PATCH 053/164] Add new file --- src/main/c/GameTic_Tac_Toe/temp | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/main/c/GameTic_Tac_Toe/temp diff --git a/src/main/c/GameTic_Tac_Toe/temp b/src/main/c/GameTic_Tac_Toe/temp new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/main/c/GameTic_Tac_Toe/temp @@ -0,0 +1 @@ + From eca9fef7a13af1ef19f0765d5feeebc03878c48b Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Wed, 24 Jan 2024 13:04:28 +0000 Subject: [PATCH 054/164] Delete temp --- src/main/c/GameTic_Tac_Toe/temp | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/main/c/GameTic_Tac_Toe/temp diff --git a/src/main/c/GameTic_Tac_Toe/temp b/src/main/c/GameTic_Tac_Toe/temp deleted file mode 100644 index 8b13789..0000000 --- a/src/main/c/GameTic_Tac_Toe/temp +++ /dev/null @@ -1 +0,0 @@ - From a8c427c5b2c361bb6739f9188bfc24184eb4802d Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Wed, 24 Jan 2024 14:21:33 +0100 Subject: [PATCH 055/164] added global board --- src/main/c/GameTic_Tac_Toe/game.c | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/c/GameTic_Tac_Toe/game.c diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c new file mode 100644 index 0000000..7d5c061 --- /dev/null +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -0,0 +1,6 @@ +#include + +char board[3][3] = {{'1', '2', '3'}, + {'4', '5', '6'}, + {'7', '8', '9'}}; +char currentPlayer = 'X'; From 794f052fa746757d14dba5d6de325061cb229aca Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 11:44:47 +0000 Subject: [PATCH 056/164] 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 7999eb79fe7155da4fc5b3b8d94f54fdd2d395c4 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 11:45:48 +0000 Subject: [PATCH 057/164] 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 a9fb21881e83ecb0337d2e60b5ff9bca5bb78e33 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 11:46:46 +0000 Subject: [PATCH 058/164] 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 30f7147c18b85d24caa91288a8d7e6cd7f45f4d5 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 11:47:58 +0000 Subject: [PATCH 059/164] 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]; + From 970382ae3c968897fb7925f33e52b2f3ca643152 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 11:52:41 +0000 Subject: [PATCH 060/164] No 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 3f1dc5a..a91ba51 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -29,3 +29,6 @@ char checkWinner() { 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]; + // Kein Gewinner + return ' '; +} From 7f8de3f06bb9fa26aca2ef129c4b6041b24dc4f1 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 11:58:28 +0000 Subject: [PATCH 061/164] Verification function --- src/main/c/GameTic_Tac_Toe/game.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index a91ba51..6432f7f 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -32,3 +32,15 @@ char checkWinner() { // Kein Gewinner return ' '; } + +// Funktion zur Überprüfung, ob das Spiel unentschieden ist +int isBoardFull() { + for (int i = 0; i < 3; i++) { + for (int j = 0; j < 3; j++) { + if (board[i][j] != 'X' && board[i][j] != 'O') { + return 0; + } + } + } + return 1; +} From 1ec3169a5b6edffa9c36a7a30e3d2df7a3943381 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 11:59:42 +0000 Subject: [PATCH 062/164] Function: A player's turn --- src/main/c/GameTic_Tac_Toe/game.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 6432f7f..089012b 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -44,3 +44,11 @@ int isBoardFull() { } return 1; } + + +// Funktion zum Zug eines Spielers +void makeMove() { + int choice; + printf("Spieler %c, wähle eine Zahl (1-9): ", currentPlayer); + scanf("%d", &choice); + From 22d08f9a4b27e6ed72339a872ad860226106cd85 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 12:00:33 +0000 Subject: [PATCH 063/164] Convert the number --- 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 089012b..48035ae 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -52,3 +52,7 @@ void makeMove() { printf("Spieler %c, wähle eine Zahl (1-9): ", currentPlayer); scanf("%d", &choice); +// Konvertiere die Zahl in Zeilen- und Spaltenindex + int row = (choice - 1) / 3; + int col = (choice - 1) % 3; + From f1b61336a5a5beb5d08874fb901e9657932f9b1e Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 12:01:52 +0000 Subject: [PATCH 064/164] Check whether the selected field is valid --- 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 48035ae..f0ddb37 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -56,3 +56,7 @@ void makeMove() { int row = (choice - 1) / 3; int col = (choice - 1) % 3; + // Überprüfe, ob das gewählte Feld gültig ist + if (choice >= 1 && choice <= 9 && board[row][col] != 'X' && board[row][col] != 'O') { + + From 9ef4f2f96690b5e7cdf6af931d9ffcbac1abaec5 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 12:02:18 +0000 Subject: [PATCH 065/164] Update game.c --- src/main/c/GameTic_Tac_Toe/game.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index f0ddb37..5129548 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -58,5 +58,6 @@ void makeMove() { // Überprüfe, ob das gewählte Feld gültig ist if (choice >= 1 && choice <= 9 && board[row][col] != 'X' && board[row][col] != 'O') { - + board[row][col] = currentPlayer; + } else { From d47cb68db8380e185c9556709a41c366ccd0a30d Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 12:03:21 +0000 Subject: [PATCH 066/164] Invalid move --- src/main/c/GameTic_Tac_Toe/game.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 5129548..51f5c7c 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -60,4 +60,7 @@ void makeMove() { if (choice >= 1 && choice <= 9 && board[row][col] != 'X' && board[row][col] != 'O') { board[row][col] = currentPlayer; } else { - + printf("Ungültiger Zug! Bitte wähle erneut.\n"); + makeMove(); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird + } +} From 87f5a6c5d8267494d57cd5302e9e5517ef909f61 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 12:04:05 +0000 Subject: [PATCH 067/164] Update main --- 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 51f5c7c..85a08a2 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -64,3 +64,8 @@ void makeMove() { makeMove(); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird } } + +int main() { + while (1) { + displayBoard(); + makeMove(); From bd7b0a63c647e259a8fb7ab9255d3a7d289996a8 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 12:05:23 +0000 Subject: [PATCH 068/164] check winner --- src/main/c/GameTic_Tac_Toe/game.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 85a08a2..215af00 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -69,3 +69,10 @@ int main() { while (1) { displayBoard(); makeMove(); + + char winner = checkWinner(); + if (winner == 'X' || winner == 'O') { + displayBoard(); + printf("Spieler %c gewinnt!\n", winner); + break; + } From b02a1f7f6cf0cc7727c125ff136099760d521075 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 12:20:45 +0000 Subject: [PATCH 069/164] possibility: draw --- src/main/c/GameTic_Tac_Toe/game.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 215af00..0f0d6f8 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -76,3 +76,9 @@ int main() { printf("Spieler %c gewinnt!\n", winner); break; } + + if (isBoardFull()) { + displayBoard(); + printf("Unentschieden!\n"); + break; + } From 421db299f35517a88096b718f0af89ab65693137 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 12:22:57 +0000 Subject: [PATCH 070/164] Change player --- src/main/c/GameTic_Tac_Toe/game.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 0f0d6f8..b20f125 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -82,3 +82,10 @@ int main() { printf("Unentschieden!\n"); break; } + + // Wechsle den Spieler + currentPlayer = (currentPlayer == 'X') ? 'O' : 'X'; + } + + return 0; +} From 04b9365a8ac416738f3555c3f6eb17ea18a4ae2f Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 16:57:40 +0000 Subject: [PATCH 071/164] refactoring: lear condition for an invalid move --- src/main/c/GameTic_Tac_Toe/game.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index b20f125..11d2a79 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -57,11 +57,11 @@ void makeMove() { int col = (choice - 1) % 3; // Überprüfe, ob das gewählte Feld gültig ist - if (choice >= 1 && choice <= 9 && board[row][col] != 'X' && board[row][col] != 'O') { - board[row][col] = currentPlayer; - } else { - printf("Ungültiger Zug! Bitte wähle erneut.\n"); + if (choice < 1 || choice > 9 || board[row][col] == 'X' || board[row][col] == 'O') { + printf("Ungültiger Zug! Bitte wähle erneut.\n"); makeMove(); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird + } else { + board[row][col] = currentPlayer; } } From a0ecdb63f1cbbe0fc19f296d86830176e43793b3 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 17:05:35 +0000 Subject: [PATCH 072/164] refactoring: using else and if --- src/main/c/GameTic_Tac_Toe/game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 11d2a79..278b1e5 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -27,7 +27,7 @@ char checkWinner() { } // Ü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]; + else if (board[0][2] == board[1][1] && board[1][1] == board[2][0]) return board[0][2]; // Kein Gewinner return ' '; From 990b115c96fed40a214baed9d0fe6d5dc5c63ec9 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 17:15:30 +0000 Subject: [PATCH 073/164] refactoring: using an auxiliary feature for win conditions --- src/main/c/GameTic_Tac_Toe/game.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 278b1e5..0765c17 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -17,13 +17,19 @@ void displayBoard() { if (i < 2) printf("---------\n"); } } - +char checkLine(char a, char b, char c) { + if (a == b && b == c) return a; + return ' '; +} // 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]; + for (int i = 0; i < 3; i++) { + char horizontalWinner = checkLine(board[i][0], board[i][1], board[i][2]); + char verticalWinner = checkLine(board[0][i], board[1][i], board[2][i]); + + if (horizontalWinner != ' ') return horizontalWinner; + if (verticalWinner != ' ') return verticalWinner; } // Überprüfe diagonale Linien if (board[0][0] == board[1][1] && board[1][1] == board[2][2]) return board[0][0]; From fec03368ca2cd1c5a0c2648c81f7709e179c9dd6 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 17:18:52 +0000 Subject: [PATCH 074/164] refactoring: using an auxiliary function for diagonal lines --- src/main/c/GameTic_Tac_Toe/game.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 0765c17..215f890 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -32,8 +32,11 @@ char checkWinner() { if (verticalWinner != ' ') return verticalWinner; } // Überprüfe diagonale Linien - if (board[0][0] == board[1][1] && board[1][1] == board[2][2]) return board[0][0]; - else if (board[0][2] == board[1][1] && board[1][1] == board[2][0]) return board[0][2]; + char diagonal1Winner = checkLine(board[0][0], board[1][1], board[2][2]); + char diagonal2Winner = checkLine(board[0][2], board[1][1], board[2][0]); + + if (diagonal1Winner != ' ') return diagonal1Winner; + if (diagonal2Winner != ' ') return diagonal2Winner; // Kein Gewinner return ' '; From 483f2b54800761f661f66ec9e4f931386e707620 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 17:43:49 +0000 Subject: [PATCH 075/164] refactoring: logic functions for player exchange Author: Ariana Ginju --- 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 215f890..a3f3ae2 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -56,6 +56,10 @@ int isBoardFull() { // Funktion zum Zug eines Spielers +char switchPlayer(char currentPlayer) { + return (currentPlayer == 'X') ? 'O' : 'X'; +} + void makeMove() { int choice; printf("Spieler %c, wähle eine Zahl (1-9): ", currentPlayer); @@ -71,6 +75,7 @@ void makeMove() { makeMove(); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird } else { board[row][col] = currentPlayer; + currentPlayer = switchPlayer(currentPlayer); } } From 29759098ad1f386a32dc74eb2b89f87d99ff4196 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 17:53:55 +0000 Subject: [PATCH 076/164] refactoring: separation of the game loop into functions Author: Ariana Ginju --- src/main/c/GameTic_Tac_Toe/game.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index a3f3ae2..f193efa 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -79,7 +79,7 @@ void makeMove() { } } -int main() { +void playGame() { while (1) { displayBoard(); makeMove(); @@ -95,11 +95,10 @@ int main() { displayBoard(); printf("Unentschieden!\n"); break; - } - - // Wechsle den Spieler - currentPlayer = (currentPlayer == 'X') ? 'O' : 'X'; + } } - +} +int main(){ + playGame(); return 0; } From 0d188261b2ad94bb5efa2a48e553496662ef42b1 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 17:56:28 +0000 Subject: [PATCH 077/164] refactoring: using const --- src/main/c/GameTic_Tac_Toe/game.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index f193efa..f20e298 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -43,9 +43,11 @@ char checkWinner() { } // Funktion zur Überprüfung, ob das Spiel unentschieden ist +const int BOARD_SIZE = 3; + int isBoardFull() { - for (int i = 0; i < 3; i++) { - for (int j = 0; j < 3; j++) { + for (int i = 0; i < BOARD_SIZE; i++) { + for (int j = 0; j < BOARD_SIZE; j++) { if (board[i][j] != 'X' && board[i][j] != 'O') { return 0; } From f0480af37136c2200c5e0486ef55e54a1336f045 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 18:04:27 +0000 Subject: [PATCH 078/164] refactoring: Clear condition in makeMove --- src/main/c/GameTic_Tac_Toe/game.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index f20e298..ece4bb7 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -62,22 +62,28 @@ char switchPlayer(char currentPlayer) { return (currentPlayer == 'X') ? 'O' : 'X'; } +int isValidMove(int choice) { + int row = (choice - 1) / BOARD_SIZE; + int col = (choice - 1) % BOARD_SIZE; + + return (choice >= 1 && choice <= BOARD_SIZE * BOARD_SIZE && board[row][col] != 'X' && board[row][col] != 'O'); +} + void makeMove() { int choice; - printf("Spieler %c, wähle eine Zahl (1-9): ", currentPlayer); + printf("Spieler %c, waehle eine Zahl (1-9): ", currentPlayer); scanf("%d", &choice); // Konvertiere die Zahl in Zeilen- und Spaltenindex - int row = (choice - 1) / 3; - int col = (choice - 1) % 3; - - // Überprüfe, ob das gewählte Feld gültig ist - if (choice < 1 || choice > 9 || board[row][col] == 'X' || board[row][col] == 'O') { - printf("Ungültiger Zug! Bitte wähle erneut.\n"); - makeMove(); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird - } else { - board[row][col] = currentPlayer; - currentPlayer = switchPlayer(currentPlayer); +if (isValidMove(choice)) { + int row = (choice - 1) / / BOARD_SIZE; + int col = (choice - 1) % % BOARD_SIZE; + board[row][col] = currentPlayer; + currentPlayer = switchPlayer(currentPlayer); + +} else { + printf("Ungueltiger Zug! Bitte waehle erneut.\n"); + makeMove(); // Rekursiver Aufruf, bis ein gültiger Zug gemacht wird } } From 0221526e8e45ec1686d295f40d8660626af09bac Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 18:07:39 +0000 Subject: [PATCH 079/164] Update: corrected errors --- src/main/c/GameTic_Tac_Toe/game.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index ece4bb7..e56e55f 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -76,8 +76,8 @@ void makeMove() { // Konvertiere die Zahl in Zeilen- und Spaltenindex if (isValidMove(choice)) { - int row = (choice - 1) / / BOARD_SIZE; - int col = (choice - 1) % % BOARD_SIZE; + int row = (choice - 1) / BOARD_SIZE; + int col = (choice - 1) % BOARD_SIZE; board[row][col] = currentPlayer; currentPlayer = switchPlayer(currentPlayer); From b690c7e673ae766b2cdc4f5f639fae28436f7e53 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 18:14:59 +0000 Subject: [PATCH 080/164] refactoring: Using const for game symbol constants --- src/main/c/GameTic_Tac_Toe/game.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index e56e55f..ec98aec 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -4,7 +4,8 @@ char board[3][3] = {{'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}}; char currentPlayer = 'X'; - +const char PLAYER_X = 'X'; +const char PLAYER_O = 'O'; // Funktionen zur Anzeige des Spielbretts void displayBoard() { printf("Tic-Tac-Toe\n"); From 0721be55c82ee5cbbfe631cf08501bd091df9d6b Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 18:16:46 +0000 Subject: [PATCH 081/164] refactoring: Removing the currentPlayer global variable --- src/main/c/GameTic_Tac_Toe/game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index ec98aec..8615cb8 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -60,7 +60,7 @@ int isBoardFull() { // Funktion zum Zug eines Spielers char switchPlayer(char currentPlayer) { - return (currentPlayer == 'X') ? 'O' : 'X'; + return (currentPlayer == PLAYER_X) ? PLAYER_O : PLAYER_X; } int isValidMove(int choice) { From dff9fd6ec9fdcd792ff6f2628a11a7e213fcd57a Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 18:20:35 +0000 Subject: [PATCH 082/164] refactoring: Using a loop --- src/main/c/GameTic_Tac_Toe/game.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 8615cb8..177acc8 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -6,16 +6,22 @@ char board[3][3] = {{'1', '2', '3'}, char currentPlayer = 'X'; const char PLAYER_X = 'X'; const char PLAYER_O = 'O'; + // 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++) { + for (int i = 0; i < BOARD_SIZE; i++) { + for (int j = 0; j < BOARD_SIZE; j++) { printf("%c", board[i][j]); - if (j < 2) printf(" | "); - } + if (j < BOARD_SIZE - 1) printf(" | "); + } printf("\n"); - if (i < 2) printf("---------\n"); + if (i < BOARD_SIZE - 1) { + for (int k = 0; k < BOARD_SIZE * 4 - 1; k++) { + printf("-"); + } + printf("\n"); + } } } char checkLine(char a, char b, char c) { From 6d1d96c4d9732867d1f69a2ebca2af38fe51cd3c Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 18:35:42 +0000 Subject: [PATCH 083/164] refactoring: char replaced with enum --- src/main/c/GameTic_Tac_Toe/game.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 177acc8..ea95618 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -24,14 +24,16 @@ void displayBoard() { } } } + char checkLine(char a, char b, char c) { if (a == b && b == c) return a; return ' '; } + // Funktion zur Überprüfung des Gewinners char checkWinner() { // Überprüfe horizontale und vertikale Linien - for (int i = 0; i < 3; i++) { + for (int i = 0; i < BOARD_SIZE; i++) { char horizontalWinner = checkLine(board[i][0], board[i][1], board[i][2]); char verticalWinner = checkLine(board[0][i], board[1][i], board[2][i]); @@ -65,7 +67,7 @@ int isBoardFull() { // Funktion zum Zug eines Spielers -char switchPlayer(char currentPlayer) { +enum switchPlayer(enum currentPlayer) { return (currentPlayer == PLAYER_X) ? PLAYER_O : PLAYER_X; } From 51aff089d80018462a17f45565432ff16bf07f76 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 18:44:21 +0000 Subject: [PATCH 084/164] refactoring: replacing larger parts --- src/main/c/GameTic_Tac_Toe/game.c | 35 ++++++++++++++++--------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index ea95618..3b7f017 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -80,14 +80,14 @@ int isValidMove(int choice) { void makeMove() { int choice; - printf("Spieler %c, waehle eine Zahl (1-9): ", currentPlayer); + printf("Spieler %c, waehle eine Zahl (1-9): ", currentPlayer == PLAYER_X) ? 'X' : 'O'); scanf("%d", &choice); // Konvertiere die Zahl in Zeilen- und Spaltenindex if (isValidMove(choice)) { int row = (choice - 1) / BOARD_SIZE; int col = (choice - 1) % BOARD_SIZE; - board[row][col] = currentPlayer; + board[row][col] = currentPlayer == PLAYER_X) ? 'X' : 'O'; currentPlayer = switchPlayer(currentPlayer); } else { @@ -96,25 +96,26 @@ if (isValidMove(choice)) { } } +int isGameOver() { + char winner = checkWinner(); + return (winner == PLAYER_X || winner == PLAYER_O || isBoardFull()); +} + +void printGameResult(char winner) { + if (winner == PLAYER_X || winner == PLAYER_O) { + printf("Spieler %c gewinnt!\n", (winner == PLAYER_X) ? 'X' : 'O'); + } else { + printf("Unentschieden!\n"); + } +} + void playGame() { - while (1) { + while (!isGameOver()) { displayBoard(); makeMove(); - - char winner = checkWinner(); - if (winner == 'X' || winner == 'O') { - displayBoard(); - printf("Spieler %c gewinnt!\n", winner); - break; - } - - if (isBoardFull()) { - displayBoard(); - printf("Unentschieden!\n"); - break; - } } -} + + //Fehlt etwas, änderung folgt; int main(){ playGame(); return 0; From 3989ecb68131b39183b56acdd5f9ba06e24f0cef Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 18:45:51 +0000 Subject: [PATCH 085/164] refactoring: added missing part --- src/main/c/GameTic_Tac_Toe/game.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index 3b7f017..f72b814 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -115,7 +115,11 @@ void playGame() { makeMove(); } - //Fehlt etwas, änderung folgt; + displayBoard(); + char winner = checkWinner(); + printGameResult(winner); +} + int main(){ playGame(); return 0; From 4cdef01b3a4c00d51b701701ed1780c878177253 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Tue, 30 Jan 2024 19:14:53 +0000 Subject: [PATCH 086/164] refactoring: correct the errors --- src/main/c/GameTic_Tac_Toe/game.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/game.c index f72b814..443fe8d 100644 --- a/src/main/c/GameTic_Tac_Toe/game.c +++ b/src/main/c/GameTic_Tac_Toe/game.c @@ -1,5 +1,6 @@ #include +const int BOARD_SIZE = 3; char board[3][3] = {{'1', '2', '3'}, {'4', '5', '6'}, {'7', '8', '9'}}; @@ -52,8 +53,6 @@ char checkWinner() { } // Funktion zur Überprüfung, ob das Spiel unentschieden ist -const int BOARD_SIZE = 3; - int isBoardFull() { for (int i = 0; i < BOARD_SIZE; i++) { for (int j = 0; j < BOARD_SIZE; j++) { @@ -67,7 +66,7 @@ int isBoardFull() { // Funktion zum Zug eines Spielers -enum switchPlayer(enum currentPlayer) { +char switchPlayer(char currentPlayer) { return (currentPlayer == PLAYER_X) ? PLAYER_O : PLAYER_X; } @@ -80,14 +79,14 @@ int isValidMove(int choice) { void makeMove() { int choice; - printf("Spieler %c, waehle eine Zahl (1-9): ", currentPlayer == PLAYER_X) ? 'X' : 'O'); + printf("Spieler %c, waehle eine Zahl (1-9): ", (currentPlayer == PLAYER_X) ? 'X' : 'O'); scanf("%d", &choice); // Konvertiere die Zahl in Zeilen- und Spaltenindex if (isValidMove(choice)) { int row = (choice - 1) / BOARD_SIZE; int col = (choice - 1) % BOARD_SIZE; - board[row][col] = currentPlayer == PLAYER_X) ? 'X' : 'O'; + board[row][col] = (currentPlayer == PLAYER_X) ? 'X' : 'O'; currentPlayer = switchPlayer(currentPlayer); } else { From 20e5561526c78d54b721eef846afba80e411298e Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Wed, 31 Jan 2024 12:23:59 +0000 Subject: [PATCH 087/164] Add new directory --- test/tests_tictactoe.game/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/tests_tictactoe.game/.gitkeep diff --git a/test/tests_tictactoe.game/.gitkeep b/test/tests_tictactoe.game/.gitkeep new file mode 100644 index 0000000..e69de29 From a1de4d4bb84dbd5a60038e1bbf0948729656be0c Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Wed, 31 Jan 2024 12:27:00 +0000 Subject: [PATCH 088/164] Delete .gitkeep --- test/tests_tictactoe.game/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test/tests_tictactoe.game/.gitkeep diff --git a/test/tests_tictactoe.game/.gitkeep b/test/tests_tictactoe.game/.gitkeep deleted file mode 100644 index e69de29..0000000 From f756c806111db52ec747236f56681fff766dec18 Mon Sep 17 00:00:00 2001 From: Ariana Ginju Date: Wed, 31 Jan 2024 12:28:08 +0000 Subject: [PATCH 089/164] Add new file --- test/test_tictactoe.c | 1 + 1 file changed, 1 insertion(+) create mode 100644 test/test_tictactoe.c diff --git a/test/test_tictactoe.c b/test/test_tictactoe.c new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/test/test_tictactoe.c @@ -0,0 +1 @@ + From c3865b164d9defa4a3517efa1462beb07ad2f939 Mon Sep 17 00:00:00 2001 From: Julia Selig Date: Wed, 31 Jan 2024 13:09:11 +0000 Subject: [PATCH 090/164] Erstellen Spielfeld --- src/main/c/Pong/game.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index 8b13789..b2969e0 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -1 +1,25 @@ +#include +#define WIDTH 40 //Breite Spielfeld +#define HEIGHT 20 //Höhe Spielfeld + +void drawField() { + for (int i = 0; i <= HEIGHT; i++){ + for (int j = 0; j <= WIDTH; j++){ + if (i == 0 || i == HEIGHT){ + printf("-"); + } else if ("i == 0 || j == WIDTH") { + printf("|"); + } else { + printf(" "); + } + } + printf("\n"); + } +} + +int main(){ + drawField(); + + return 0; +} From 753dd2211c81e1989d33795aebe3ba6cbd3a4434 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 13:32:36 +0000 Subject: [PATCH 091/164] =?UTF-8?q?Hinzuf=C3=BCgen=20Schl=C3=A4gel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Pong/game.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index b2969e0..f97a3f0 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -2,14 +2,20 @@ #define WIDTH 40 //Breite Spielfeld #define HEIGHT 20 //Höhe Spielfeld +#define PADDLE_LENGTH 4 +#define PADDLE '#' -void drawField() { +void drawField(int paddle1PositionY, int paddle2PositionY) { for (int i = 0; i <= HEIGHT; i++){ for (int j = 0; j <= WIDTH; j++){ if (i == 0 || i == HEIGHT){ printf("-"); - } else if ("i == 0 || j == WIDTH") { + } else if ("j == 0 || j == WIDTH") && (i < paddle1PositionY || i >= paddle1PositionY + PADDLE_LENGTH) && (i < paddle2PositionY || i >= paddle2PositionY + PADDLE_LENGTH)) { printf("|"); + } else if (i >= paddle1PositionY && i < paddle1PositionY + PADDLE_LENGTH && j == WIDTH) { + printf("%c", PADDLE); + }else if (i >= paddle2PositionY && i < paddle2PositionY + PADDLE_LENGTH && j == 0) { + printf("%c", PADDLE); } else { printf(" "); } @@ -19,7 +25,27 @@ void drawField() { } int main(){ - drawField(); + int paddle1PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; + int paddle2PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; + while (1) { + if (kbhit()){ + char input = getch(); + if (input == 'w' && paddle1PositionY > 1) + { + paddle1PositionY--; + } else if (input == 's' && paddle1PositionY < HEIGHT - PADDLE_LENGTH - 1) { + paddle1PositionY++; + } + } + +// Hier Steuerung für Schläger 2 noch reinschreiben + + draw Field(paddle1PositionY, paddle2PositionY); + + } + return 0; } + + From 2e38b367d885f0805a843b99b1b5b62f927dabfc Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 13:53:00 +0000 Subject: [PATCH 092/164] =?UTF-8?q?Hinzuf=C3=BCgen=20Schl=C3=A4gel=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Pong/game.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index f97a3f0..69d6a31 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -24,6 +24,7 @@ void drawField(int paddle1PositionY, int paddle2PositionY) { } } + int main(){ int paddle1PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; int paddle2PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; @@ -39,7 +40,15 @@ int main(){ } } -// Hier Steuerung für Schläger 2 noch reinschreiben +//Steuerung für Schläger 2 + if (kbhit()){ + char input = getch(); + if (input == 'i' && paddle2PositionY > 1) { + paddle2PositionY--; + } else if (input == 'k' && paddle2PositionY < HEIGHT - PADDLE_LENGTH - 1){ + paddle2PositionY++; + } + } draw Field(paddle1PositionY, paddle2PositionY); From 1e473e2d0bb1f4e2e60257dd06d122889ff7ec61 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 13:59:23 +0000 Subject: [PATCH 093/164] =?UTF-8?q?Hinzuf=C3=BCgen=20Tastatureingabe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Pong/game.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index 69d6a31..e8b68d6 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -1,4 +1,5 @@ #include +#include #define WIDTH 40 //Breite Spielfeld #define HEIGHT 20 //Höhe Spielfeld @@ -24,6 +25,36 @@ void drawField(int paddle1PositionY, int paddle2PositionY) { } } +int kbhit(void){ + struct termios oldt, newt; + int ch, oldf; + + tcgetattr(STDIN_FILENO, &oldt); + newt = oldt; + newt.c_lflag &= ~(ICANON | ECHO); + tcsetattr(STDIN_FILENO, TCSANOW, &newt); + oldf = fcntl(STDIN_FILENO, F_GETFL, 0); + fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK); + + ch = getchar(); + + tcsetattr(STDIN_FILENO, TCSANOW, &oldt); + fcntl(STDIN_FILENO, F_SETFL, oldf); + + if (ch != EOF) { + ungetc(ch, stdin); + return 1; +} +return 0; +} + +int getch(void) { + int ch; + + while ((ch = getchar()) == '\n'); + + return ch; +} int main(){ int paddle1PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; From 30b212b1cff3dfaa6bbf2a31b1dc354f5c63acf5 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 14:54:05 +0000 Subject: [PATCH 094/164] =?UTF-8?q?Bildschirm=20l=C3=B6schen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Pong/game.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index e8b68d6..6453f7a 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -1,12 +1,20 @@ #include #include +#include #define WIDTH 40 //Breite Spielfeld #define HEIGHT 20 //Höhe Spielfeld #define PADDLE_LENGTH 4 #define PADDLE '#' +// Bildschirm löschen nach Veränderung Position +void clearScreen() { + system("clear"); +} + void drawField(int paddle1PositionY, int paddle2PositionY) { + clearScreen(); + for (int i = 0; i <= HEIGHT; i++){ for (int j = 0; j <= WIDTH; j++){ if (i == 0 || i == HEIGHT){ @@ -15,7 +23,7 @@ void drawField(int paddle1PositionY, int paddle2PositionY) { printf("|"); } else if (i >= paddle1PositionY && i < paddle1PositionY + PADDLE_LENGTH && j == WIDTH) { printf("%c", PADDLE); - }else if (i >= paddle2PositionY && i < paddle2PositionY + PADDLE_LENGTH && j == 0) { + } else if (i >= paddle2PositionY && i < paddle2PositionY + PADDLE_LENGTH && j == 0) { printf("%c", PADDLE); } else { printf(" "); @@ -61,6 +69,7 @@ int main(){ int paddle2PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; while (1) { + //Steuerung für Schläger 1 if (kbhit()){ char input = getch(); if (input == 'w' && paddle1PositionY > 1) From 1636b53e131649af149ba398d43d5b1795e4d832 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 14:55:36 +0000 Subject: [PATCH 095/164] Verlangsamen Schleife --- src/main/c/Pong/game.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index 6453f7a..11a11b4 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -1,6 +1,7 @@ #include #include #include +#include #define WIDTH 40 //Breite Spielfeld #define HEIGHT 20 //Höhe Spielfeld @@ -92,6 +93,8 @@ int main(){ draw Field(paddle1PositionY, paddle2PositionY); + usleep(100000); //Verlangsamen Schleife/Spiel + } } return 0; From 6d51598c4ea5babe36686c5f3ce1981a15deed8c Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 15:10:01 +0000 Subject: [PATCH 096/164] Implementierung Ball --- src/main/c/Pong/game.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index 11a11b4..c6067ed 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -7,13 +7,22 @@ #define HEIGHT 20 //Höhe Spielfeld #define PADDLE_LENGTH 4 #define PADDLE '#' +#define BALL 'O' + +//Ballstruktur +typedef struct { + int x; + int y; + int speedX; + int speedY; +} Ball; // Bildschirm löschen nach Veränderung Position void clearScreen() { system("clear"); } -void drawField(int paddle1PositionY, int paddle2PositionY) { +void drawField(int paddle1PositionY, int paddle2PositionY, Ball ball) { clearScreen(); for (int i = 0; i <= HEIGHT; i++){ From d1a3a890c1daad92c1685786f3e56b07b3ea5d4d Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 15:13:19 +0000 Subject: [PATCH 097/164] Startposition&Geschwindigkeit des Balles --- src/main/c/Pong/game.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index c6067ed..f0f382e 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -35,6 +35,8 @@ void drawField(int paddle1PositionY, int paddle2PositionY, Ball ball) { printf("%c", PADDLE); } else if (i >= paddle2PositionY && i < paddle2PositionY + PADDLE_LENGTH && j == 0) { printf("%c", PADDLE); + } else if (i == ball.y && j == ball.x) { + printf("%c", BALL); } else { printf(" "); } @@ -77,6 +79,7 @@ int getch(void) { int main(){ int paddle1PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; int paddle2PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; + Ball ball = {WIDTH / 2, HEIGHT / 2, 1, 1}; //Startposition&Geschwindigkeit Ball while (1) { //Steuerung für Schläger 1 From e88f7ff2e6d1f7d42428f18763751b40ca3b13cf Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 15:14:28 +0000 Subject: [PATCH 098/164] Bewegung Ball --- src/main/c/Pong/game.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index f0f382e..4030b11 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -102,6 +102,10 @@ int main(){ paddle2PositionY++; } } + + //Bewegung Ball + ball.x += ball.speedX; + ball.y += ball.speedY; draw Field(paddle1PositionY, paddle2PositionY); From 2b8a70f000ed8139501f1ed38e13f697ef031be2 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 15:17:33 +0000 Subject: [PATCH 099/164] =?UTF-8?q?Ball=20Kollision=20mit=20Schl=C3=A4gern?= =?UTF-8?q?=20und=20W=C3=A4nden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Pong/game.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index 4030b11..90f45f3 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -107,12 +107,22 @@ int main(){ ball.x += ball.speedX; ball.y += ball.speedY; + //Kollision Ball (mit Schlägern und Wänden) + if (ball.y <= 0 || ball.y >= HEIGHT - 1){ + ball.speedY = -ball.speedY; + } + if (ball.x == 1 && (ball.y >= paddle2PositionY && ball.y < paddle2PositionY + PADDLE_LENGTH)){ + ball.speedX = -ball.speedX; + } + if (ball.x == WIDTH - 1 && (ball.y >= paddle1PositionY && ball.y < paddle1PositionY + PADDLE_LENGTH)){ + ball.speedX = -ball.speedX; + } + draw Field(paddle1PositionY, paddle2PositionY); usleep(100000); //Verlangsamen Schleife/Spiel } - } - + return 0; } From 16041ce71143a5a0d555aeb277b4c2e84be5cf9b Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 15:24:18 +0000 Subject: [PATCH 100/164] Spielstand --- src/main/c/Pong/game.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index 90f45f3..ce46d29 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -22,7 +22,7 @@ void clearScreen() { system("clear"); } -void drawField(int paddle1PositionY, int paddle2PositionY, Ball ball) { +void drawField(int paddle1PositionY, int paddle2PositionY, Ball ball, int score1, int score2) { clearScreen(); for (int i = 0; i <= HEIGHT; i++){ @@ -43,6 +43,9 @@ void drawField(int paddle1PositionY, int paddle2PositionY, Ball ball) { } printf("\n"); } + + printf("Spieler 1: %d\tSpieler 2: %d\n", score1, score2); + } int kbhit(void){ @@ -64,7 +67,7 @@ int kbhit(void){ if (ch != EOF) { ungetc(ch, stdin); return 1; -} + } return 0; } @@ -118,6 +121,20 @@ int main(){ ball.speedX = -ball.speedX; } + // Punkte zählen + if (ball.x <= 0){ + score1++; + ball.x = WIDTH / 2; + ball.y = HEIGHT / 2; + ball.speedX = -ball.speedX; + } + if (ball.x >= WIDTH - 1){ + score2++; + ball.x = WIDTH / 2; + ball.y = HEIGHT / 2; + ball.speedX = -ball.speedX; + } + draw Field(paddle1PositionY, paddle2PositionY); usleep(100000); //Verlangsamen Schleife/Spiel From 20ea5a7cbc65f36d7f9db23622d93ddc629ecb54 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 15:32:46 +0000 Subject: [PATCH 101/164] Spielstand (vergessen zu implementieren variable) --- src/main/c/Pong/game.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index ce46d29..3bb88ad 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -83,6 +83,8 @@ int main(){ int paddle1PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; int paddle2PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; Ball ball = {WIDTH / 2, HEIGHT / 2, 1, 1}; //Startposition&Geschwindigkeit Ball + int score1 = 0; + int score2 = 0; while (1) { //Steuerung für Schläger 1 From eadc41ecfb1554d6dae53cc4ad57e5da65ce62b9 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 15:46:23 +0000 Subject: [PATCH 102/164] Spiel beenden wenn Punktestand erreicht --- src/main/c/Pong/game.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index 3bb88ad..71b56a2 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -85,6 +85,7 @@ int main(){ Ball ball = {WIDTH / 2, HEIGHT / 2, 1, 1}; //Startposition&Geschwindigkeit Ball int score1 = 0; int score2 = 0; + int maxScore = 5; while (1) { //Steuerung für Schläger 1 @@ -137,7 +138,13 @@ int main(){ ball.speedX = -ball.speedX; } - draw Field(paddle1PositionY, paddle2PositionY); + draw Field(paddle1PositionY, paddle2PositionY,score1, score2); + + // Spielende überprüfen + if (score1 == maxScore || score2 == maxScore) { + printf("Spiel beendet!\n"); + break; + } usleep(100000); //Verlangsamen Schleife/Spiel } From 587dc8334f80412594ad99aa4599b6a31a2f2c95 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 15:51:37 +0000 Subject: [PATCH 103/164] Ball anzeigen (vergessen) --- src/main/c/Pong/game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index 71b56a2..eee78dc 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -138,7 +138,7 @@ int main(){ ball.speedX = -ball.speedX; } - draw Field(paddle1PositionY, paddle2PositionY,score1, score2); + draw Field(paddle1PositionY, paddle2PositionY, ball, score1, score2); // Spielende überprüfen if (score1 == maxScore || score2 == maxScore) { From 0cf720020d01f720e2363e379b09e94357954306 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 15:56:06 +0000 Subject: [PATCH 104/164] Anzeigen Gewinner --- src/main/c/Pong/game.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index eee78dc..96daa74 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -143,6 +143,11 @@ int main(){ // Spielende überprüfen if (score1 == maxScore || score2 == maxScore) { printf("Spiel beendet!\n"); + if (score1 == maxScore) { + printf("Spieler 1 gewinnt!\n"); + } else { + printf("Spieler 2 gewinnt!\n"); + } break; } From 13a15d1fc6b9b409003ab0b1c68b23a8ad5d277a Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 16:18:11 +0000 Subject: [PATCH 105/164] Spiel Pausieren --- src/main/c/Pong/game.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index 96daa74..877ea22 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -45,6 +45,7 @@ void drawField(int paddle1PositionY, int paddle2PositionY, Ball ball, int score1 } printf("Spieler 1: %d\tSpieler 2: %d\n", score1, score2); + printf("Drücken Sie 'p', um das Spiel zu pausieren.\n"); } @@ -86,28 +87,38 @@ int main(){ int score1 = 0; int score2 = 0; int maxScore = 5; + int isPaused = 0; while (1) { //Steuerung für Schläger 1 if (kbhit()){ char input = getch(); - if (input == 'w' && paddle1PositionY > 1) + if (input == 'w' && paddle1PositionY > 1 && !isPaused) { paddle1PositionY--; - } else if (input == 's' && paddle1PositionY < HEIGHT - PADDLE_LENGTH - 1) { + } else if (input == 's' && paddle1PositionY < HEIGHT - PADDLE_LENGTH - 1 && !isPaused) { paddle1PositionY++; + } else if (input == 'p') { + isPaused = !isPaused; } } //Steuerung für Schläger 2 if (kbhit()){ char input = getch(); - if (input == 'i' && paddle2PositionY > 1) { + if (input == 'i' && paddle2PositionY > 1 && !isPaused) { paddle2PositionY--; - } else if (input == 'k' && paddle2PositionY < HEIGHT - PADDLE_LENGTH - 1){ + } else if (input == 'k' && paddle2PositionY < HEIGHT - PADDLE_LENGTH - 1 && !isPaused){ paddle2PositionY++; + } else if (input == 'p') { + isPaused = !isPaused; } } + + //Wenn Pauseiert + if (isPaused) { + continue; + } //Bewegung Ball ball.x += ball.speedX; From cbf0e4a79b73f622515a622ae9b7fad74f4f9d32 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 16:27:49 +0000 Subject: [PATCH 106/164] refactoring:_optimierungpausierung --- src/main/c/Pong/game.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index 877ea22..4d72e10 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -91,12 +91,12 @@ int main(){ while (1) { //Steuerung für Schläger 1 - if (kbhit()){ + if (!isPaused && kbhit()){ char input = getch(); - if (input == 'w' && paddle1PositionY > 1 && !isPaused) + if (input == 'w' && paddle1PositionY > 1) { paddle1PositionY--; - } else if (input == 's' && paddle1PositionY < HEIGHT - PADDLE_LENGTH - 1 && !isPaused) { + } else if (input == 's' && paddle1PositionY < HEIGHT - PADDLE_LENGTH - 1) { paddle1PositionY++; } else if (input == 'p') { isPaused = !isPaused; @@ -104,11 +104,11 @@ int main(){ } //Steuerung für Schläger 2 - if (kbhit()){ + if (!isPaused && kbhit()){ char input = getch(); - if (input == 'i' && paddle2PositionY > 1 && !isPaused) { + if (input == 'i' && paddle2PositionY > 1){ paddle2PositionY--; - } else if (input == 'k' && paddle2PositionY < HEIGHT - PADDLE_LENGTH - 1 && !isPaused){ + } else if (input == 'k' && paddle2PositionY < HEIGHT - PADDLE_LENGTH - 1){ paddle2PositionY++; } else if (input == 'p') { isPaused = !isPaused; @@ -117,6 +117,7 @@ int main(){ //Wenn Pauseiert if (isPaused) { + drawField(paddle1PositionY, paddle2PositionY, ball, score1, score2, 1); continue; } From 285a26a686575e263fd687ff059935b82b449453 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 16:36:45 +0000 Subject: [PATCH 107/164] Vergessen Int isPaused --- src/main/c/Pong/game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index 4d72e10..5e9636e 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -22,7 +22,7 @@ void clearScreen() { system("clear"); } -void drawField(int paddle1PositionY, int paddle2PositionY, Ball ball, int score1, int score2) { +void drawField(int paddle1PositionY, int paddle2PositionY, Ball ball, int score1, int score2, int isPaused) { clearScreen(); for (int i = 0; i <= HEIGHT; i++){ From fdaacc75eebe3cfa36a73b7fe6d24589ea244840 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 16:39:39 +0000 Subject: [PATCH 108/164] Aktualisiert Spielpause --- src/main/c/Pong/game.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index 5e9636e..75fdbc6 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -45,8 +45,11 @@ void drawField(int paddle1PositionY, int paddle2PositionY, Ball ball, int score1 } printf("Spieler 1: %d\tSpieler 2: %d\n", score1, score2); - printf("Drücken Sie 'p', um das Spiel zu pausieren.\n"); - + if (isPaused) { + printf("Spiel pausiert. Drücken Sie 'p', um fortzufahren.\n"); + } else { + printf("Drücken Sie 'p', um das Spiel zu pausieren.\n"); + } } int kbhit(void){ From 1ce01e7bb349af9b407115fb0faf31b1c2b94794 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 16:42:54 +0000 Subject: [PATCH 109/164] refactoring:_aktualisieren_ballposition_nun_an_zentraler_Stelle --- src/main/c/Pong/game.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index 75fdbc6..c74f466 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -83,6 +83,13 @@ int getch(void) { return ch; } +//Aktualisierung Ballposition +void updateBallPosition(Ball *ball) { + ball->x += ball->speedX; + ball->y += ball->speedY; +} + + int main(){ int paddle1PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; int paddle2PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; From c2ce23c9fd2bcaceb3ba749850652ee4b974c02d Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 16:46:17 +0000 Subject: [PATCH 110/164] refactoring:_verbesserung_kollision --- src/main/c/Pong/game.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index c74f466..b2ca2e0 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -89,6 +89,20 @@ void updateBallPosition(Ball *ball) { ball->y += ball->speedY; } +//Verbesserung Kollision mit Schlägern&Wänden +int checkCollision(Ball ball, int paddle1PositionY, int paddle2PositionY) { + // Kollision mit Schlägern und Wänden + if (ball.y <= 0 || ball.y >= HEIGHT - 1){ + ball.speedY = -ball.speedY; + } + if (ball.x == 1 && (ball.y >= paddle2PositionY && ball.y < paddle2PositionY + PADDLE_LENGTH)){ + ball.speedX = -ball.speedX; + } + + if (ball.x == WIDTH - 1 && (ball.y >= paddle1PositionY && ball.y < paddle1PositionY + PADDLE_LENGTH)){ + ball.speedX = -ball.speedX; + } + int main(){ int paddle1PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; From 8720b8fba938cf70335143b4ca95ba61edf341e8 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 16:47:31 +0000 Subject: [PATCH 111/164] =?UTF-8?q?refactoring:=5Fbesser=5Fpunkte=5Fz?= =?UTF-8?q?=C3=A4hlen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Pong/game.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index b2ca2e0..c1d554f 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -103,6 +103,17 @@ int checkCollision(Ball ball, int paddle1PositionY, int paddle2PositionY) { ball.speedX = -ball.speedX; } + //Punkte zählen + if (ball.x <= 0){ + return 1; // Spieler 2 gewinnt Punkt + } + + if (ball.x >= WIDTH - 1){ + return 2; // Spieler 1 gewinnt Punkt + } + + return 0; // kein Punkt +} int main(){ int paddle1PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; From b5518b41cdc8ba21e93da1e74d3b6ee2c3421727 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 16:49:42 +0000 Subject: [PATCH 112/164] =?UTF-8?q?refactoring:=5Fverbesserung=5Fpunktez?= =?UTF-8?q?=C3=A4hlen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Pong/game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index c1d554f..6e3bc64 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -124,7 +124,7 @@ int main(){ int maxScore = 5; int isPaused = 0; - while (1) { + while (score1 < maxScore && score2 < maxScore) { //Steuerung für Schläger 1 if (!isPaused && kbhit()){ char input = getch(); From 99f33da69ec53c9b8a04ff6dbc7fd9bd71ce8192 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 16:59:24 +0000 Subject: [PATCH 113/164] refactoring:_verbesserung_aktualisierung_spielstand_und_ballposition --- src/main/c/Pong/game.c | 47 ++++++++++++++---------------------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index 6e3bc64..4f6008e 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -157,50 +157,33 @@ int main(){ } //Bewegung Ball - ball.x += ball.speedX; - ball.y += ball.speedY; + updateBallPosition(&ball); + int result = checkCollision(ball, paddle1PositionY, paddle2PositionY); - //Kollision Ball (mit Schlägern und Wänden) - if (ball.y <= 0 || ball.y >= HEIGHT - 1){ - ball.speedY = -ball.speedY; - } - if (ball.x == 1 && (ball.y >= paddle2PositionY && ball.y < paddle2PositionY + PADDLE_LENGTH)){ - ball.speedX = -ball.speedX; - } - if (ball.x == WIDTH - 1 && (ball.y >= paddle1PositionY && ball.y < paddle1PositionY + PADDLE_LENGTH)){ - ball.speedX = -ball.speedX; - } - - // Punkte zählen - if (ball.x <= 0){ - score1++; + //Aktualisiert Spielstand und Ballposition + if (result == 1) { + score2++; ball.x = WIDTH / 2; ball.y = HEIGHT / 2; ball.speedX = -ball.speedX; - } - if (ball.x >= WIDTH - 1){ - score2++; + } else if (result == 2) { + score1++; ball.x = WIDTH / 2; ball.y = HEIGHT / 2; ball.speedX = -ball.speedX; } - draw Field(paddle1PositionY, paddle2PositionY, ball, score1, score2); - - // Spielende überprüfen - if (score1 == maxScore || score2 == maxScore) { - printf("Spiel beendet!\n"); - if (score1 == maxScore) { - printf("Spieler 1 gewinnt!\n"); - } else { - printf("Spieler 2 gewinnt!\n"); - } - break; - } - + drawField(paddle1PositionY, paddle2PositionY, ball, score1, score2, 0); usleep(100000); //Verlangsamen Schleife/Spiel } + clearScreen(); + if (score1 == maxScore) { + printf("Spieler 1 gewinnt!\n"); + } else { + printf("Spieler 2 gewinnt!\n"); + } + return 0; } From 9d072197a96f32b73dc6e9c05c80256455b21d53 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 17:10:03 +0000 Subject: [PATCH 114/164] =?UTF-8?q?Zur=C3=BCcksetzen=20Spielstand?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Pong/game.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index 4f6008e..835c600 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -115,6 +115,12 @@ int checkCollision(Ball ball, int paddle1PositionY, int paddle2PositionY) { return 0; // kein Punkt } +//Reset +void resetScore(int *score1, int *score2) { + *score1 = 0; + *score2 = 0; +} + int main(){ int paddle1PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; int paddle2PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; @@ -173,6 +179,8 @@ int main(){ ball.speedX = -ball.speedX; } + resetScore(&score1, &score2); //Zurücksetzen Spielstand + drawField(paddle1PositionY, paddle2PositionY, ball, score1, score2, 0); usleep(100000); //Verlangsamen Schleife/Spiel } From 6c33a64a5d37897cf9a50935cd5835226cd00b73 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 21:00:19 +0000 Subject: [PATCH 115/164] Stoppen des Spiels --- src/main/c/Pong/game.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index 835c600..b50acba 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -50,6 +50,7 @@ void drawField(int paddle1PositionY, int paddle2PositionY, Ball ball, int score1 } else { printf("Drücken Sie 'p', um das Spiel zu pausieren.\n"); } + printf("Drücken Sie 'q', um das Spiel zu beenden.\n"); } int kbhit(void){ @@ -141,8 +142,12 @@ int main(){ paddle1PositionY++; } else if (input == 'p') { isPaused = !isPaused; - } + } else if (input == 'q') { + clearScreen(); + printf("Spiel beendet.\n"); + return 0; } + } //Steuerung für Schläger 2 if (!isPaused && kbhit()){ @@ -153,6 +158,10 @@ int main(){ paddle2PositionY++; } else if (input == 'p') { isPaused = !isPaused; + } else if (input == 'q') { + clearScreen(); + printf("Spiel beendet.\n"); + return 0; } } From a0e35087acf85c99ca175cb37dd8e4aee6b1640d Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 21:30:30 +0000 Subject: [PATCH 116/164] Korrigiert --- src/main/c/Pong/game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index b50acba..fa204fb 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -29,7 +29,7 @@ void drawField(int paddle1PositionY, int paddle2PositionY, Ball ball, int score1 for (int j = 0; j <= WIDTH; j++){ if (i == 0 || i == HEIGHT){ printf("-"); - } else if ("j == 0 || j == WIDTH") && (i < paddle1PositionY || i >= paddle1PositionY + PADDLE_LENGTH) && (i < paddle2PositionY || i >= paddle2PositionY + PADDLE_LENGTH)) { + } else if ((j == 0 || j == WIDTH) && (i < paddle1PositionY || i >= paddle1PositionY + PADDLE_LENGTH) && (i < paddle2PositionY || i >= paddle2PositionY + PADDLE_LENGTH)) { printf("|"); } else if (i >= paddle1PositionY && i < paddle1PositionY + PADDLE_LENGTH && j == WIDTH) { printf("%c", PADDLE); From 4863cb3a7a88652a3599502a6d2123d690e9cb76 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 21:33:23 +0000 Subject: [PATCH 117/164] Ball rot machen --- src/main/c/Pong/game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index fa204fb..999b1cd 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -7,7 +7,7 @@ #define HEIGHT 20 //Höhe Spielfeld #define PADDLE_LENGTH 4 #define PADDLE '#' -#define BALL 'O' +#define BALL "\033[1;31mO\033[0m" //Ballstruktur typedef struct { From 7f5ffe15da32d9d559ea16439d87e1c88a7937b7 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Thu, 1 Feb 2024 09:52:36 +0000 Subject: [PATCH 118/164] =?UTF-8?q?Schl=C3=A4gel=20rot=20machen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Pong/game.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/game.c index 999b1cd..f399fc2 100644 --- a/src/main/c/Pong/game.c +++ b/src/main/c/Pong/game.c @@ -6,7 +6,7 @@ #define WIDTH 40 //Breite Spielfeld #define HEIGHT 20 //Höhe Spielfeld #define PADDLE_LENGTH 4 -#define PADDLE '#' +#define PADDLE "\033[1;31m#\033[0m" #define BALL "\033[1;31mO\033[0m" //Ballstruktur From fc3efd1fec3871fba2a9a39ef41c5a0aa1314cb1 Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 10:12:17 +0000 Subject: [PATCH 119/164] Add new file tictactoe.h --- src/main/c/GameTic_Tac_Toe/tictactoe.h | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/main/c/GameTic_Tac_Toe/tictactoe.h diff --git a/src/main/c/GameTic_Tac_Toe/tictactoe.h b/src/main/c/GameTic_Tac_Toe/tictactoe.h new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/main/c/GameTic_Tac_Toe/tictactoe.h @@ -0,0 +1 @@ + From 83ca5781232e1dfd702390a1dda2e51ac1ec3a2e Mon Sep 17 00:00:00 2001 From: fdai7775 Date: Fri, 2 Feb 2024 10:14:46 +0000 Subject: [PATCH 120/164] Update name game.c --- src/main/c/GameTic_Tac_Toe/{game.c => tictactoe.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/main/c/GameTic_Tac_Toe/{game.c => tictactoe.c} (100%) diff --git a/src/main/c/GameTic_Tac_Toe/game.c b/src/main/c/GameTic_Tac_Toe/tictactoe.c similarity index 100% rename from src/main/c/GameTic_Tac_Toe/game.c rename to src/main/c/GameTic_Tac_Toe/tictactoe.c From b16143b39f4d20d6fe2ec0d7bef14521501ebf2d Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Fri, 2 Feb 2024 11:05:03 +0000 Subject: [PATCH 121/164] Add new file --- src/main/c/Pong/pong.h | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/main/c/Pong/pong.h diff --git a/src/main/c/Pong/pong.h b/src/main/c/Pong/pong.h new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/main/c/Pong/pong.h @@ -0,0 +1 @@ + From 942a7c59c1b577b7ff90835ffe306e455b6f7345 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Fri, 2 Feb 2024 11:05:33 +0000 Subject: [PATCH 122/164] Aktualisieren src/main/c/Pong/pong.c --- src/main/c/Pong/{game.c => pong.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/main/c/Pong/{game.c => pong.c} (100%) diff --git a/src/main/c/Pong/game.c b/src/main/c/Pong/pong.c similarity index 100% rename from src/main/c/Pong/game.c rename to src/main/c/Pong/pong.c From 03ed4fc6540659647e6993e837e473b59e70ddb7 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Fri, 2 Feb 2024 11:16:27 +0000 Subject: [PATCH 123/164] test resertScore --- src/main/c/Pong/pong.c | 2 +- src/main/c/Pong/pong.h | 8 ++++++++ src/main/c/main.c | 7 ++++--- src/main/c/main.h | 2 +- test/test_pong.c | 27 +++++++++++++++++++++++++++ test/test_template.c | 2 +- 6 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 test/test_pong.c diff --git a/src/main/c/Pong/pong.c b/src/main/c/Pong/pong.c index f399fc2..44cfbc5 100644 --- a/src/main/c/Pong/pong.c +++ b/src/main/c/Pong/pong.c @@ -122,7 +122,7 @@ void resetScore(int *score1, int *score2) { *score2 = 0; } -int main(){ +int pong(){ int paddle1PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; int paddle2PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; Ball ball = {WIDTH / 2, HEIGHT / 2, 1, 1}; //Startposition&Geschwindigkeit Ball diff --git a/src/main/c/Pong/pong.h b/src/main/c/Pong/pong.h index 8b13789..4e6cfdd 100644 --- a/src/main/c/Pong/pong.h +++ b/src/main/c/Pong/pong.h @@ -1 +1,9 @@ +#ifndef PONG_H +#define PONG_H + +int pong(); + +void resetScore(int *score1, int *score2); + +#endif diff --git a/src/main/c/main.c b/src/main/c/main.c index 922c8d4..0321f5a 100644 --- a/src/main/c/main.c +++ b/src/main/c/main.c @@ -4,6 +4,7 @@ #include "Template/game100.h" #include "Snake/snake_start.h" +#include "Pong/pong.h" int main(){ bool running = true; @@ -15,7 +16,7 @@ int main(){ system("clear"); printf("Waehlen Sie eine Option:\n"); printf("\t1.Spiel1 starten\n"); - printf("\t2.Spiel2 starten\n"); + printf("\t2.Pong starten\n"); printf("\t3.Snake starten\n"); printf("\t4.Spiel4 starten\n"); printf("\t100.Template starten\n"); @@ -29,7 +30,7 @@ int main(){ //start_game1(); break; case 2: - //start_game2(); + pong(); break; case 3: snake_start(); @@ -50,4 +51,4 @@ int main(){ } } return 0; -} \ No newline at end of file +} diff --git a/src/main/c/main.h b/src/main/c/main.h index 71870e0..013f02f 100644 --- a/src/main/c/main.h +++ b/src/main/c/main.h @@ -3,4 +3,4 @@ int main(); -#endif // MAIN_H \ No newline at end of file +#endif // MAIN_H diff --git a/test/test_pong.c b/test/test_pong.c new file mode 100644 index 0000000..0b12481 --- /dev/null +++ b/test/test_pong.c @@ -0,0 +1,27 @@ +#ifdef TEST +#include "unity.h" +#include "pong.h" + + +void setUp(void){ + //Wenn Funktion Vorraussetzungen braucht +} +void tearDown(void){ +} + + +void test_input_all_5(void){ + /* arrange */ + int a = 4, b = 5; + + /* act */ + resetScore( &a, &b ); + + /* assert */ + TEST_ASSERT_EQUAL_INT(0, a); + TEST_ASSERT_EQUAL_INT(0, b); +} + + + +#endif // TEST diff --git a/test/test_template.c b/test/test_template.c index a1b9ed4..4aba361 100644 --- a/test/test_template.c +++ b/test/test_template.c @@ -33,4 +33,4 @@ void test_ignore_rest_from_division(void){ TEST_ASSERT_EQUAL_INT(5, result);//5 / 6 + 5 = 5 } -#endif // TEST \ No newline at end of file +#endif // TEST From 9c7fe6d9417c4553040e668dd23b5181ec56f854 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Fri, 2 Feb 2024 11:30:18 +0000 Subject: [PATCH 124/164] =?UTF-8?q?Hinzuf=C3=BCgen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Pong/pong.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/c/Pong/pong.c b/src/main/c/Pong/pong.c index 44cfbc5..27e3c70 100644 --- a/src/main/c/Pong/pong.c +++ b/src/main/c/Pong/pong.c @@ -2,6 +2,7 @@ #include #include #include +#include #define WIDTH 40 //Breite Spielfeld #define HEIGHT 20 //Höhe Spielfeld From 82a03832cd9581bc3cce56c76b2524799af85d0e Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Fri, 2 Feb 2024 11:31:30 +0000 Subject: [PATCH 125/164] Aktualisieren Standardbibliothek --- src/main/c/Pong/pong.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/c/Pong/pong.c b/src/main/c/Pong/pong.c index 27e3c70..5d9eb00 100644 --- a/src/main/c/Pong/pong.c +++ b/src/main/c/Pong/pong.c @@ -3,6 +3,7 @@ #include #include #include +#include #define WIDTH 40 //Breite Spielfeld #define HEIGHT 20 //Höhe Spielfeld From f35b01c79bde8ab7dcf86a0e4e3cb20edbc5972e Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Fri, 2 Feb 2024 11:44:27 +0000 Subject: [PATCH 126/164] Erstelle eine neues Verzeichnis --- test/Pong/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/Pong/.gitkeep diff --git a/test/Pong/.gitkeep b/test/Pong/.gitkeep new file mode 100644 index 0000000..e69de29 From 165e41ae704a4c1a723248953c555244e6811b29 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Fri, 2 Feb 2024 11:45:04 +0000 Subject: [PATCH 127/164] Verschieben --- test/{ => Pong}/test_pong.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{ => Pong}/test_pong.c (100%) diff --git a/test/test_pong.c b/test/Pong/test_pong.c similarity index 100% rename from test/test_pong.c rename to test/Pong/test_pong.c From 7738edaa0b92635e2b9b42c13f82bcc1bfdea464 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 16:03:16 +0000 Subject: [PATCH 128/164] test_clearScreen --- test_clearScreen.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 test_clearScreen.c diff --git a/test_clearScreen.c b/test_clearScreen.c new file mode 100644 index 0000000..e859d99 --- /dev/null +++ b/test_clearScreen.c @@ -0,0 +1,38 @@ +#ifdef TEST +#include "unity.h" +#include "pong.h" + +#define TEST_SCREEN_WIDTH 40 +#define TEST_SCREEN_HEIGHT 20 + +char screen[TEST_SCREEN_HEIGHT][TEST_SCREEN_WIDTH+1]; + +void setUp(void){ + //Wenn Funktion Vorraussetzungen braucht +} + +void tearDown(void){ +} + +void test_clearScreen(void){ + /* arrange */ + int i, j; + for (i = 0; i < TEST_SCREEN_HEIGHT; i++) { + for (j = 0; j < TEST_SCREEN_WIDTH+1; j++) { + screen[i][j] = 'X'; + } + screen[i][j-1] = '\0'; + } + + /* act */ + clearScreen(); + + /* assert */ + for (i = 0; i < TEST_SCREEN_HEIGHT; i++) { + for (j = 0; j < TEST_SCREEN_WIDTH+1; j++) { + TEST_ASSERT_EQUAL_INT(' ', screen[i][j]); + } + } +} + +#endif // TEST From 3ce5fe25c9906db952c24249cc19391594641c6a Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 16:04:38 +0000 Subject: [PATCH 129/164] Aktualisieren test/Pong/test_clearScreen.c --- test_clearScreen.c => test/Pong/test_clearScreen.c | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test_clearScreen.c => test/Pong/test_clearScreen.c (100%) diff --git a/test_clearScreen.c b/test/Pong/test_clearScreen.c similarity index 100% rename from test_clearScreen.c rename to test/Pong/test_clearScreen.c From c3ab68b1dece08dff9ae9667360706fa3fbbaa49 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 16:07:52 +0000 Subject: [PATCH 130/164] test_updateBallPosition --- test/Pong/test_updateBallPosition.c | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 test/Pong/test_updateBallPosition.c diff --git a/test/Pong/test_updateBallPosition.c b/test/Pong/test_updateBallPosition.c new file mode 100644 index 0000000..5894273 --- /dev/null +++ b/test/Pong/test_updateBallPosition.c @@ -0,0 +1,30 @@ +#ifdef TEST +#include "unity.h" +#include "pong.h" + +void setUp(void){ + //Wenn Funktion Vorraussetzungen braucht +} + +void tearDown(void){ +} + +void test_updateBallPosition(void){ + /* arrange */ + Ball ball = { 10, 10, 1, 1 }; + int expectedX = ball.x + ball.speedX * 5; // erwartete Endposition nach 5 Schritten + int expectedY = ball.y + ball.speedY * 5; + + /* act */ + updateBallPosition(&ball); + updateBallPosition(&ball); + updateBallPosition(&ball); + updateBallPosition(&ball); + updateBallPosition(&ball); + + /* assert */ + TEST_ASSERT_EQUAL_INT(expectedX, ball.x); + TEST_ASSERT_EQUAL_INT(expectedY, ball.y); +} + +#endif // TEST From aafd7aed58063ca81734abaeb37c492af6551466 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 16:11:07 +0000 Subject: [PATCH 131/164] test_checkCollision --- test/Pong/test_checkCollision.c | 37 +++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 test/Pong/test_checkCollision.c diff --git a/test/Pong/test_checkCollision.c b/test/Pong/test_checkCollision.c new file mode 100644 index 0000000..12dac8a --- /dev/null +++ b/test/Pong/test_checkCollision.c @@ -0,0 +1,37 @@ +#ifdef TEST +#include "unity.h" +#include "pong.h" + + +void setUp(void){ + //Wenn Funktion Vorraussetzungen braucht +} + +void tearDown(void){ +} + +void test_checkCollision(void){ + /* Test 1: Ball und Schläger kollidieren nicht */ + Ball ball = {10, 10, 1, 1}; + Paddle paddle = {50, 10, 5, 10}; + + int result1 = checkCollision(ball, paddle); + TEST_ASSERT_EQUAL_INT(0, result1); + + /* Test 2: Ball kollidiert mit Schläger */ + ball.x = 50; + ball.y = 10; + int result2 = checkCollision(ball, paddle); + TEST_ASSERT_EQUAL_INT(1, result2); + + /* Test 3: Ball kollidiert mit Bildschirmrand */ + ball.x = 0; + ball.y = 0; + int result3 = checkCollision(ball, paddle); + TEST_ASSERT_EQUAL_INT(2, result3); + + /* Weitere Tests mit verschiedenen Kollisionsfällen können hinzugefügt werden */ + +} + +#endif // TEST From f80f94be5aaa826d6083e86893bb2eaa417b0d09 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 16:15:16 +0000 Subject: [PATCH 132/164] test_playerInputMovement --- test/Pongtest_playerInputMovement.c | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/Pongtest_playerInputMovement.c diff --git a/test/Pongtest_playerInputMovement.c b/test/Pongtest_playerInputMovement.c new file mode 100644 index 0000000..6d281d7 --- /dev/null +++ b/test/Pongtest_playerInputMovement.c @@ -0,0 +1,33 @@ +#ifdef TEST +#include "unity.h" +#include "pong.h" + +void setUp(void){ + //Wenn Funktion Vorraussetzungen braucht +} + +void tearDown(void){ +} + +void test_playerInputMovement(void){ + /* Test 1: Bewegung nach oben */ + Paddle paddle = {100, 200, 5, 20}; + int userInput = -1; // Benutzereingabe für Bewegung nach oben + int initialY = paddle.y; + + processPlayerInput(&paddle, userInput); + TEST_ASSERT_EQUAL_INT(initialY - paddle.speed, paddle.y); + + /* Test 2: Bewegung nach unten */ + initialY = paddle.y; + userInput = 1; // Benutzereingabe für Bewegung nach unten + + processPlayerInput(&paddle, userInput); + TEST_ASSERT_EQUAL_INT(initialY + paddle.speed, paddle.y); + + /* Weitere Tests mit anderen Bewegungsrichtungen und Grenzfällen können hinzugefügt werden */ + +} + + +#endif // TEST From 890b2bd7eac93fe226c1d45adea56214b27b2b03 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 16:16:22 +0000 Subject: [PATCH 133/164] Verschieben --- .../test_playerInputMovement.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename test/{Pongtest_playerInputMovement.c => Pong/test_playerInputMovement.c} (100%) diff --git a/test/Pongtest_playerInputMovement.c b/test/Pong/test_playerInputMovement.c similarity index 100% rename from test/Pongtest_playerInputMovement.c rename to test/Pong/test_playerInputMovement.c From d09233ecd0030c75f5ef491759318f062761a07c Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 16:17:43 +0000 Subject: [PATCH 134/164] Nur Kommentar --- test/Pong/test_playerInputMovement.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Pong/test_playerInputMovement.c b/test/Pong/test_playerInputMovement.c index 6d281d7..ab1d843 100644 --- a/test/Pong/test_playerInputMovement.c +++ b/test/Pong/test_playerInputMovement.c @@ -2,6 +2,8 @@ #include "unity.h" #include "pong.h" +// sicherstellen korrekte Funktion Steuerung für Schläger + void setUp(void){ //Wenn Funktion Vorraussetzungen braucht } From ab75538a33f5ecc8cb3192b26714bf7d7d7bf865 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 16:21:45 +0000 Subject: [PATCH 135/164] =?UTF-8?q?Pr=C3=BCfen=20Spiellogik=20f=C3=BCr=20B?= =?UTF-8?q?eenden=20des=20Spiels?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/Pong/test_endGameMaxScore.c | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 test/Pong/test_endGameMaxScore.c diff --git a/test/Pong/test_endGameMaxScore.c b/test/Pong/test_endGameMaxScore.c new file mode 100644 index 0000000..9fd92c2 --- /dev/null +++ b/test/Pong/test_endGameMaxScore.c @@ -0,0 +1,34 @@ +#ifdef TEST +#include "unity.h" +#include "pong.h" + +// Prüfen Spiellogik für Beenden des Spiels + +void setUp(void){ + //Wenn Funktion Vorraussetzungen braucht +} + +void tearDown(void){ +} + +void test_endGameMaxScore(void){ + /* arrange */ + int maxScore = 5; + int scorePlayer1 = 4, scorePlayer2 = 2; + + /* act */ + int result = checkGameEnd(scorePlayer1, scorePlayer2, maxScore); + + /* assert */ + TEST_ASSERT_EQUAL_INT(0, result); // Das Spiel sollte noch nicht enden + + /* Spieler 1 erreicht den Maximalscore */ + scorePlayer1 = 5; + result = checkGameEnd(scorePlayer1, scorePlayer2, maxScore); + TEST_ASSERT_EQUAL_INT(1, result); // Das Spiel sollte enden, da Spieler 1 den Maximalscore erreicht hat + + /* Weitere Tests mit anderen Spiellogikfällen und Endspielbedingungen können hinzugefügt werden */ + +} + +#endif // TEST From 9729861429297a99a24d1600b07b278f0954d375 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 16:40:02 +0000 Subject: [PATCH 136/164] Aktualisieren test/Pong/test_checkCollision.c --- test/Pong/test_checkCollision.c | 39 +++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/test/Pong/test_checkCollision.c b/test/Pong/test_checkCollision.c index 12dac8a..ab2a4fa 100644 --- a/test/Pong/test_checkCollision.c +++ b/test/Pong/test_checkCollision.c @@ -11,27 +11,38 @@ void tearDown(void){ } void test_checkCollision(void){ - /* Test 1: Ball und Schläger kollidieren nicht */ Ball ball = {10, 10, 1, 1}; Paddle paddle = {50, 10, 5, 10}; - int result1 = checkCollision(ball, paddle); - TEST_ASSERT_EQUAL_INT(0, result1); + // Test Ball trifft rechte und linke Wand + ball.x = 0; + int result1 = checkCollision(&ball, &paddle); + TEST_ASSERT_EQUAL_INT(1, result1); - /* Test 2: Ball kollidiert mit Schläger */ - ball.x = 50; - ball.y = 10; - int result2 = checkCollision(ball, paddle); + ball.x = WIDTH - 1; + int result2 = checkCollision(&ball, &paddle); TEST_ASSERT_EQUAL_INT(1, result2); - /* Test 3: Ball kollidiert mit Bildschirmrand */ - ball.x = 0; + // Test Ball trifft obere und untere Wand + ball.x = 5; ball.y = 0; - int result3 = checkCollision(ball, paddle); - TEST_ASSERT_EQUAL_INT(2, result3); - - /* Weitere Tests mit verschiedenen Kollisionsfällen können hinzugefügt werden */ - + int result3 = checkCollision(&ball, &paddle); + TEST_ASSERT_EQUAL_INT(0, result3); + + ball.y = HEIGHT - 1; + int result4 = checkCollision(&ball, &paddle); + TEST_ASSERT_EQUAL_INT(0, result4); + + // Test wenn Ball Paddle trifft + ball.x = paddle.x - 1; + ball.y = paddle.y + 1; + int result5 = checkCollision(&ball, &paddle); + TEST_ASSERT_EQUAL_INT(0, result5); + + ball.x = paddle.x + 1; + ball.y = paddle.y + 1; + int result6 = checkCollision(&ball, &paddle); + TEST_ASSERT_EQUAL_INT(0, result6); } #endif // TEST From 0169f259dc6ae0f6be10d384b94f600e0584f9e9 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 16:51:51 +0000 Subject: [PATCH 137/164] Aktualisieren test/Pong/test_checkCollision.c --- test/Pong/test_checkCollision.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/test/Pong/test_checkCollision.c b/test/Pong/test_checkCollision.c index ab2a4fa..0a67bac 100644 --- a/test/Pong/test_checkCollision.c +++ b/test/Pong/test_checkCollision.c @@ -2,6 +2,19 @@ #include "unity.h" #include "pong.h" +typedef struct { + int x; + int y; + int speedX; + int speedY; +} Ball; + +typedef struct { + int x; + int y; + int width; + int height; +} Paddle; void setUp(void){ //Wenn Funktion Vorraussetzungen braucht @@ -16,32 +29,32 @@ void test_checkCollision(void){ // Test Ball trifft rechte und linke Wand ball.x = 0; - int result1 = checkCollision(&ball, &paddle); + int result1 = checkCollision(ball, paddle.y, paddle.y); TEST_ASSERT_EQUAL_INT(1, result1); ball.x = WIDTH - 1; - int result2 = checkCollision(&ball, &paddle); + int result2 = checkCollision(ball, paddle.y, paddle.y); TEST_ASSERT_EQUAL_INT(1, result2); // Test Ball trifft obere und untere Wand ball.x = 5; ball.y = 0; - int result3 = checkCollision(&ball, &paddle); + int result3 = checkCollision(ball, paddle.y, paddle.y); TEST_ASSERT_EQUAL_INT(0, result3); ball.y = HEIGHT - 1; - int result4 = checkCollision(&ball, &paddle); + int result4 = checkCollision(ball, paddle.y, paddle.y); TEST_ASSERT_EQUAL_INT(0, result4); // Test wenn Ball Paddle trifft ball.x = paddle.x - 1; ball.y = paddle.y + 1; - int result5 = checkCollision(&ball, &paddle); + int result5 = checkCollision(ball, paddle.y, paddle.y); TEST_ASSERT_EQUAL_INT(0, result5); ball.x = paddle.x + 1; ball.y = paddle.y + 1; - int result6 = checkCollision(&ball, &paddle); + int result6 = checkCollision(ball, paddle.y, paddle.y); TEST_ASSERT_EQUAL_INT(0, result6); } From d59f8f861d8bd9dc21ee9f574eb580afa4225216 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 16:54:49 +0000 Subject: [PATCH 138/164] Aktualisieren test/Pong/test_checkCollision.c --- test/Pong/test_checkCollision.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Pong/test_checkCollision.c b/test/Pong/test_checkCollision.c index 0a67bac..74adc35 100644 --- a/test/Pong/test_checkCollision.c +++ b/test/Pong/test_checkCollision.c @@ -1,6 +1,8 @@ #ifdef TEST #include "unity.h" #include "pong.h" +#define WIDTH 40 //Breite Spielfeld +#define HEIGHT 20 //Höhe Spielfeld typedef struct { int x; From c89043355b34ce8bed35772188b142e455cf540d Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 16:56:03 +0000 Subject: [PATCH 139/164] Aktualisieren test/Pong/test_checkCollision.c --- test/Pong/test_checkCollision.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/Pong/test_checkCollision.c b/test/Pong/test_checkCollision.c index 74adc35..d94066d 100644 --- a/test/Pong/test_checkCollision.c +++ b/test/Pong/test_checkCollision.c @@ -31,32 +31,32 @@ void test_checkCollision(void){ // Test Ball trifft rechte und linke Wand ball.x = 0; - int result1 = checkCollision(ball, paddle.y, paddle.y); + int result1 = test_checkCollision(ball, paddle.y, paddle.y); TEST_ASSERT_EQUAL_INT(1, result1); ball.x = WIDTH - 1; - int result2 = checkCollision(ball, paddle.y, paddle.y); + int result2 = test_checkCollision(ball, paddle.y, paddle.y); TEST_ASSERT_EQUAL_INT(1, result2); // Test Ball trifft obere und untere Wand ball.x = 5; ball.y = 0; - int result3 = checkCollision(ball, paddle.y, paddle.y); + int result3 = test_checkCollision(ball, paddle.y, paddle.y); TEST_ASSERT_EQUAL_INT(0, result3); ball.y = HEIGHT - 1; - int result4 = checkCollision(ball, paddle.y, paddle.y); + int result4 = test_checkCollision(ball, paddle.y, paddle.y); TEST_ASSERT_EQUAL_INT(0, result4); // Test wenn Ball Paddle trifft ball.x = paddle.x - 1; ball.y = paddle.y + 1; - int result5 = checkCollision(ball, paddle.y, paddle.y); + int result5 = test_checkCollision(ball, paddle.y, paddle.y); TEST_ASSERT_EQUAL_INT(0, result5); ball.x = paddle.x + 1; ball.y = paddle.y + 1; - int result6 = checkCollision(ball, paddle.y, paddle.y); + int result6 = test_checkCollision(ball, paddle.y, paddle.y); TEST_ASSERT_EQUAL_INT(0, result6); } From 8ae07e26d165c0151f30cd8f6a67abb6a407806d Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 16:57:31 +0000 Subject: [PATCH 140/164] Aktualisieren test/Pong/test_checkCollision.c --- test/Pong/test_checkCollision.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/Pong/test_checkCollision.c b/test/Pong/test_checkCollision.c index d94066d..74adc35 100644 --- a/test/Pong/test_checkCollision.c +++ b/test/Pong/test_checkCollision.c @@ -31,32 +31,32 @@ void test_checkCollision(void){ // Test Ball trifft rechte und linke Wand ball.x = 0; - int result1 = test_checkCollision(ball, paddle.y, paddle.y); + int result1 = checkCollision(ball, paddle.y, paddle.y); TEST_ASSERT_EQUAL_INT(1, result1); ball.x = WIDTH - 1; - int result2 = test_checkCollision(ball, paddle.y, paddle.y); + int result2 = checkCollision(ball, paddle.y, paddle.y); TEST_ASSERT_EQUAL_INT(1, result2); // Test Ball trifft obere und untere Wand ball.x = 5; ball.y = 0; - int result3 = test_checkCollision(ball, paddle.y, paddle.y); + int result3 = checkCollision(ball, paddle.y, paddle.y); TEST_ASSERT_EQUAL_INT(0, result3); ball.y = HEIGHT - 1; - int result4 = test_checkCollision(ball, paddle.y, paddle.y); + int result4 = checkCollision(ball, paddle.y, paddle.y); TEST_ASSERT_EQUAL_INT(0, result4); // Test wenn Ball Paddle trifft ball.x = paddle.x - 1; ball.y = paddle.y + 1; - int result5 = test_checkCollision(ball, paddle.y, paddle.y); + int result5 = checkCollision(ball, paddle.y, paddle.y); TEST_ASSERT_EQUAL_INT(0, result5); ball.x = paddle.x + 1; ball.y = paddle.y + 1; - int result6 = test_checkCollision(ball, paddle.y, paddle.y); + int result6 = checkCollision(ball, paddle.y, paddle.y); TEST_ASSERT_EQUAL_INT(0, result6); } From effc2739bf3ce18d90c4f04e53ef58a871f3c246 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 17:05:06 +0000 Subject: [PATCH 141/164] Implementierung checkGameEnd --- src/main/c/Pong/pong.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/c/Pong/pong.c b/src/main/c/Pong/pong.c index 5d9eb00..a395207 100644 --- a/src/main/c/Pong/pong.c +++ b/src/main/c/Pong/pong.c @@ -203,6 +203,14 @@ int pong(){ printf("Spieler 2 gewinnt!\n"); } +int checkGameEnd(int score1, int score2, int maxScore) { + if (score1 >= maxScore || score2 >= maxScore) { + return 1; // Das Spiel endet + } else { + return 0; // Das Spiel endet nicht + } +} + return 0; } From e7bfc4f30ba5a205a57ea8605ce05382ef833b0b Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 17:15:06 +0000 Subject: [PATCH 142/164] Aktualisieren test/Pong/test_endGameMaxScore.c --- test/Pong/test_endGameMaxScore.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Pong/test_endGameMaxScore.c b/test/Pong/test_endGameMaxScore.c index 9fd92c2..700bcc1 100644 --- a/test/Pong/test_endGameMaxScore.c +++ b/test/Pong/test_endGameMaxScore.c @@ -14,17 +14,17 @@ void tearDown(void){ void test_endGameMaxScore(void){ /* arrange */ int maxScore = 5; - int scorePlayer1 = 4, scorePlayer2 = 2; + int score1 = 4, score2 = 2; /* act */ - int result = checkGameEnd(scorePlayer1, scorePlayer2, maxScore); + int result = checkGameEnd(score1, score2, maxScore); /* assert */ TEST_ASSERT_EQUAL_INT(0, result); // Das Spiel sollte noch nicht enden /* Spieler 1 erreicht den Maximalscore */ - scorePlayer1 = 5; - result = checkGameEnd(scorePlayer1, scorePlayer2, maxScore); + score1 = 5; + result = checkGameEnd(score1, score2, maxScore); TEST_ASSERT_EQUAL_INT(1, result); // Das Spiel sollte enden, da Spieler 1 den Maximalscore erreicht hat /* Weitere Tests mit anderen Spiellogikfällen und Endspielbedingungen können hinzugefügt werden */ From 27c60f6d2f068c8e1e98c8060897ceb0bdacd10f Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 17:17:13 +0000 Subject: [PATCH 143/164] Aktualisieren test/Pong/test_checkGameEnd.c --- test/Pong/{test_endGameMaxScore.c => test_checkGameEnd.c} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename test/Pong/{test_endGameMaxScore.c => test_checkGameEnd.c} (95%) diff --git a/test/Pong/test_endGameMaxScore.c b/test/Pong/test_checkGameEnd.c similarity index 95% rename from test/Pong/test_endGameMaxScore.c rename to test/Pong/test_checkGameEnd.c index 700bcc1..4f9144d 100644 --- a/test/Pong/test_endGameMaxScore.c +++ b/test/Pong/test_checkGameEnd.c @@ -11,7 +11,7 @@ void setUp(void){ void tearDown(void){ } -void test_endGameMaxScore(void){ +void test_checkGameEnd(void){ /* arrange */ int maxScore = 5; int score1 = 4, score2 = 2; From fdddc3ffc617ddc1dbcc39bca9d691bb5ea9a9a3 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 17:25:47 +0000 Subject: [PATCH 144/164] refactoring: checkGameEnd_verschoben --- src/main/c/Pong/pong.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/c/Pong/pong.c b/src/main/c/Pong/pong.c index a395207..09b72f0 100644 --- a/src/main/c/Pong/pong.c +++ b/src/main/c/Pong/pong.c @@ -124,6 +124,14 @@ void resetScore(int *score1, int *score2) { *score2 = 0; } +int checkGameEnd(int score1, int score2, int maxScore) { + if (score1 >= maxScore || score2 >= maxScore) { + return 1; // Das Spiel endet + } else { + return 0; // Das Spiel endet nicht + } +} + int pong(){ int paddle1PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; int paddle2PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; @@ -203,14 +211,6 @@ int pong(){ printf("Spieler 2 gewinnt!\n"); } -int checkGameEnd(int score1, int score2, int maxScore) { - if (score1 >= maxScore || score2 >= maxScore) { - return 1; // Das Spiel endet - } else { - return 0; // Das Spiel endet nicht - } -} - return 0; } From 5deb2f0023d4e0506b388d1e2230b0e53e1daf55 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 17:38:24 +0000 Subject: [PATCH 145/164] refactoring: Verbesserung_Funktion --- test/Pong/test_playerInputMovement.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/test/Pong/test_playerInputMovement.c b/test/Pong/test_playerInputMovement.c index ab1d843..6212f82 100644 --- a/test/Pong/test_playerInputMovement.c +++ b/test/Pong/test_playerInputMovement.c @@ -2,6 +2,12 @@ #include "unity.h" #include "pong.h" +typedef struct { + int x; + int y; + int speedX; + int speedY; +} Paddle; // sicherstellen korrekte Funktion Steuerung für Schläger void setUp(void){ @@ -13,19 +19,20 @@ void tearDown(void){ void test_playerInputMovement(void){ /* Test 1: Bewegung nach oben */ - Paddle paddle = {100, 200, 5, 20}; + Paddle paddle = {0, 10, 10, 10}; int userInput = -1; // Benutzereingabe für Bewegung nach oben - int initialY = paddle.y; + int expectedY = paddle.y - paddle.speedY; processPlayerInput(&paddle, userInput); - TEST_ASSERT_EQUAL_INT(initialY - paddle.speed, paddle.y); + TEST_ASSERT_EQUAL_INT(expectedY, paddle.y); /* Test 2: Bewegung nach unten */ - initialY = paddle.y; - userInput = 1; // Benutzereingabe für Bewegung nach unten + userInput = 1; + expectedY = paddle.y + paddle.speedY; + // Benutzereingabe für Bewegung nach unten processPlayerInput(&paddle, userInput); - TEST_ASSERT_EQUAL_INT(initialY + paddle.speed, paddle.y); + TEST_ASSERT_EQUAL_INT(expectedY, paddle.y); /* Weitere Tests mit anderen Bewegungsrichtungen und Grenzfällen können hinzugefügt werden */ From 64ad6921684a7b14bf37a4d6232f0dd2a67a827b Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 17:43:55 +0000 Subject: [PATCH 146/164] =?UTF-8?q?Hinzuf=C3=BCgen=20processPlayerInput?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Pong/pong.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/c/Pong/pong.c b/src/main/c/Pong/pong.c index 09b72f0..a07a430 100644 --- a/src/main/c/Pong/pong.c +++ b/src/main/c/Pong/pong.c @@ -132,6 +132,20 @@ int checkGameEnd(int score1, int score2, int maxScore) { } } +void processPlayerInput(Paddle *paddle, int userInput) { + if (userInput == -1) { + // Bewegt den Schläger nach oben, solange der obere Rand nicht erreicht ist + if (paddle->y > 0) { + paddle->y--; + } + } else if (userInput == 1) { + // Bewegt den Schläger nach unten, solange der untere Rand nicht erreicht ist + if (paddle->y < HEIGHT - PADDLE_LENGTH) { + paddle->y++; + } + } +} + int pong(){ int paddle1PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; int paddle2PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; From f1db12f759bba7b34b058563aa6bfb0425280261 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 17:51:40 +0000 Subject: [PATCH 147/164] =?UTF-8?q?refactoring:=20=C3=A4nderung=5Ffunktion?= =?UTF-8?q?=5FprocessPlayerInput?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Pong/pong.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/c/Pong/pong.c b/src/main/c/Pong/pong.c index a07a430..d962a4c 100644 --- a/src/main/c/Pong/pong.c +++ b/src/main/c/Pong/pong.c @@ -132,16 +132,16 @@ int checkGameEnd(int score1, int score2, int maxScore) { } } -void processPlayerInput(Paddle *paddle, int userInput) { +void processPlayerInput(int *paddlePositionY, int userInput) { if (userInput == -1) { // Bewegt den Schläger nach oben, solange der obere Rand nicht erreicht ist - if (paddle->y > 0) { - paddle->y--; + if (*paddlePositionY > 0) { + *paddlePositionY -=1; } } else if (userInput == 1) { // Bewegt den Schläger nach unten, solange der untere Rand nicht erreicht ist - if (paddle->y < HEIGHT - PADDLE_LENGTH) { - paddle->y++; + if (*paddlePositionY < HEIGHT - PADDLE_LENGTH) { + *paddlePositionY += 1; } } } From e231561f4d720630f1d447d0f6f741fd35675d6a Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 17:54:45 +0000 Subject: [PATCH 148/164] refactoring: ersetzen_integer --- test/Pong/test_playerInputMovement.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/Pong/test_playerInputMovement.c b/test/Pong/test_playerInputMovement.c index 6212f82..e8ebbdd 100644 --- a/test/Pong/test_playerInputMovement.c +++ b/test/Pong/test_playerInputMovement.c @@ -19,20 +19,20 @@ void tearDown(void){ void test_playerInputMovement(void){ /* Test 1: Bewegung nach oben */ - Paddle paddle = {0, 10, 10, 10}; + int paddlePositionY = 10; int userInput = -1; // Benutzereingabe für Bewegung nach oben - int expectedY = paddle.y - paddle.speedY; + int expectedY = paddlePositionY - 1; - processPlayerInput(&paddle, userInput); - TEST_ASSERT_EQUAL_INT(expectedY, paddle.y); + processPlayerInput(&paddlePositionY, userInput); + TEST_ASSERT_EQUAL_INT(expectedY, paddlePositionY); /* Test 2: Bewegung nach unten */ userInput = 1; - expectedY = paddle.y + paddle.speedY; + expectedY = paddlePositionY + 1; // Benutzereingabe für Bewegung nach unten - processPlayerInput(&paddle, userInput); - TEST_ASSERT_EQUAL_INT(expectedY, paddle.y); + processPlayerInput(&paddlePositionY, userInput); + TEST_ASSERT_EQUAL_INT(expectedY, paddlePositionY); /* Weitere Tests mit anderen Bewegungsrichtungen und Grenzfällen können hinzugefügt werden */ From 5c00cfc353689534924fcf27b9a00778f5682d9a Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 17:57:59 +0000 Subject: [PATCH 149/164] =?UTF-8?q?Hinzuf=C3=BCgen=20Ballstruktur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/Pong/test_updateBallPosition.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/Pong/test_updateBallPosition.c b/test/Pong/test_updateBallPosition.c index 5894273..fe5fc3d 100644 --- a/test/Pong/test_updateBallPosition.c +++ b/test/Pong/test_updateBallPosition.c @@ -2,6 +2,13 @@ #include "unity.h" #include "pong.h" +typedef struct { + int x; + int y; + int speedX; + int speedY; +} Ball; + void setUp(void){ //Wenn Funktion Vorraussetzungen braucht } From d99d95fa1b36bd0fad4ba293f148d2c2d5533e20 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 18:01:43 +0000 Subject: [PATCH 150/164] Aktualisieren src/main/c/Pong/pong.h --- src/main/c/Pong/pong.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/c/Pong/pong.h b/src/main/c/Pong/pong.h index 4e6cfdd..9074535 100644 --- a/src/main/c/Pong/pong.h +++ b/src/main/c/Pong/pong.h @@ -5,5 +5,14 @@ int pong(); void resetScore(int *score1, int *score2); +typedef struct { + int x; + int y; + int speedX; + int speedY; +} Ball; + +void updateBallPosition(Ball* ball); + #endif From 9fad188369fcf5398d7cd220882e89e767367350 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 18:08:39 +0000 Subject: [PATCH 151/164] refactoring: ballstruktur --- test/Pong/test_updateBallPosition.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/Pong/test_updateBallPosition.c b/test/Pong/test_updateBallPosition.c index fe5fc3d..a5c98a6 100644 --- a/test/Pong/test_updateBallPosition.c +++ b/test/Pong/test_updateBallPosition.c @@ -18,7 +18,11 @@ void tearDown(void){ void test_updateBallPosition(void){ /* arrange */ - Ball ball = { 10, 10, 1, 1 }; + Ball ball; + ball.x = 10; + ball.y = 10; + ball.speedX = 1; + ball.speedY = 1; int expectedX = ball.x + ball.speedX * 5; // erwartete Endposition nach 5 Schritten int expectedY = ball.y + ball.speedY * 5; From 8a2e0991b81d76a32c8e810262fdfdfb9ff942f1 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 18:11:12 +0000 Subject: [PATCH 152/164] =?UTF-8?q?refactoring:=20l=C3=B6schen=5Fnicht=5Fk?= =?UTF-8?q?onsistent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Pong/pong.h | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/main/c/Pong/pong.h b/src/main/c/Pong/pong.h index 9074535..4e6cfdd 100644 --- a/src/main/c/Pong/pong.h +++ b/src/main/c/Pong/pong.h @@ -5,14 +5,5 @@ int pong(); void resetScore(int *score1, int *score2); -typedef struct { - int x; - int y; - int speedX; - int speedY; -} Ball; - -void updateBallPosition(Ball* ball); - #endif From 4d705138bb6eaf3d1eb9a20ecd8b6e597ba186f1 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sat, 3 Feb 2024 18:16:23 +0000 Subject: [PATCH 153/164] Versuch Test zum laufen zu bringen --- test/Pong/test_updateBallPosition.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/Pong/test_updateBallPosition.c b/test/Pong/test_updateBallPosition.c index a5c98a6..73cb040 100644 --- a/test/Pong/test_updateBallPosition.c +++ b/test/Pong/test_updateBallPosition.c @@ -9,6 +9,18 @@ typedef struct { int speedY; } Ball; +void updateBallPosition(Ball *ball) { + struct Ball { + int x; + int y; + int speedX; + int speedY; + }; + + ball->x += ball->speedX; + ball->y += ball->speedY; +} + void setUp(void){ //Wenn Funktion Vorraussetzungen braucht } From 7ced4d7fca3a60389c9458f9fe8c7c7933ef4b45 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sun, 4 Feb 2024 13:58:38 +0000 Subject: [PATCH 154/164] refactoring: doppelt_schon_in_pong.c --- test/Pong/test_updateBallPosition.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/test/Pong/test_updateBallPosition.c b/test/Pong/test_updateBallPosition.c index 73cb040..7c4d814 100644 --- a/test/Pong/test_updateBallPosition.c +++ b/test/Pong/test_updateBallPosition.c @@ -2,20 +2,7 @@ #include "unity.h" #include "pong.h" -typedef struct { - int x; - int y; - int speedX; - int speedY; -} Ball; - void updateBallPosition(Ball *ball) { - struct Ball { - int x; - int y; - int speedX; - int speedY; - }; ball->x += ball->speedX; ball->y += ball->speedY; From d5b2c9c54c95163df41e8d3f2110cfeed75dc463 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sun, 4 Feb 2024 14:04:30 +0000 Subject: [PATCH 155/164] =?UTF-8?q?refactoring:=20einf=C3=BCgen=5Fballstru?= =?UTF-8?q?ktur=5Fheaderdatei?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Pong/pong.c | 8 -------- src/main/c/Pong/pong.h | 8 ++++++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/c/Pong/pong.c b/src/main/c/Pong/pong.c index d962a4c..3424283 100644 --- a/src/main/c/Pong/pong.c +++ b/src/main/c/Pong/pong.c @@ -11,14 +11,6 @@ #define PADDLE "\033[1;31m#\033[0m" #define BALL "\033[1;31mO\033[0m" -//Ballstruktur -typedef struct { - int x; - int y; - int speedX; - int speedY; -} Ball; - // Bildschirm löschen nach Veränderung Position void clearScreen() { system("clear"); diff --git a/src/main/c/Pong/pong.h b/src/main/c/Pong/pong.h index 4e6cfdd..f728064 100644 --- a/src/main/c/Pong/pong.h +++ b/src/main/c/Pong/pong.h @@ -1,6 +1,14 @@ #ifndef PONG_H #define PONG_H +//Ballstruktur +typedef struct { + int x; + int y; + int speedX; + int speedY; +} Ball; + int pong(); void resetScore(int *score1, int *score2); From 060e7da64edb7f92b4708cfb1eb60857f8d37a5e Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sun, 4 Feb 2024 14:07:28 +0000 Subject: [PATCH 156/164] =?UTF-8?q?refactoring:=20r=C3=BCckg=C3=A4ngig=5Fs?= =?UTF-8?q?onst=5FFehler=5FUnittest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/c/Pong/pong.c | 8 ++++++++ src/main/c/Pong/pong.h | 8 -------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/c/Pong/pong.c b/src/main/c/Pong/pong.c index 3424283..d962a4c 100644 --- a/src/main/c/Pong/pong.c +++ b/src/main/c/Pong/pong.c @@ -11,6 +11,14 @@ #define PADDLE "\033[1;31m#\033[0m" #define BALL "\033[1;31mO\033[0m" +//Ballstruktur +typedef struct { + int x; + int y; + int speedX; + int speedY; +} Ball; + // Bildschirm löschen nach Veränderung Position void clearScreen() { system("clear"); diff --git a/src/main/c/Pong/pong.h b/src/main/c/Pong/pong.h index f728064..4e6cfdd 100644 --- a/src/main/c/Pong/pong.h +++ b/src/main/c/Pong/pong.h @@ -1,14 +1,6 @@ #ifndef PONG_H #define PONG_H -//Ballstruktur -typedef struct { - int x; - int y; - int speedX; - int speedY; -} Ball; - int pong(); void resetScore(int *score1, int *score2); From df5a4a3af0fed08ef4a69312def6906d4df337ff Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sun, 4 Feb 2024 14:10:13 +0000 Subject: [PATCH 157/164] =?UTF-8?q?Gel=C3=B6scht=20test/Pong/test=5Fupdate?= =?UTF-8?q?BallPosition.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/Pong/test_updateBallPosition.c | 40 ----------------------------- 1 file changed, 40 deletions(-) delete mode 100644 test/Pong/test_updateBallPosition.c diff --git a/test/Pong/test_updateBallPosition.c b/test/Pong/test_updateBallPosition.c deleted file mode 100644 index 7c4d814..0000000 --- a/test/Pong/test_updateBallPosition.c +++ /dev/null @@ -1,40 +0,0 @@ -#ifdef TEST -#include "unity.h" -#include "pong.h" - -void updateBallPosition(Ball *ball) { - - ball->x += ball->speedX; - ball->y += ball->speedY; -} - -void setUp(void){ - //Wenn Funktion Vorraussetzungen braucht -} - -void tearDown(void){ -} - -void test_updateBallPosition(void){ - /* arrange */ - Ball ball; - ball.x = 10; - ball.y = 10; - ball.speedX = 1; - ball.speedY = 1; - int expectedX = ball.x + ball.speedX * 5; // erwartete Endposition nach 5 Schritten - int expectedY = ball.y + ball.speedY * 5; - - /* act */ - updateBallPosition(&ball); - updateBallPosition(&ball); - updateBallPosition(&ball); - updateBallPosition(&ball); - updateBallPosition(&ball); - - /* assert */ - TEST_ASSERT_EQUAL_INT(expectedX, ball.x); - TEST_ASSERT_EQUAL_INT(expectedY, ball.y); -} - -#endif // TEST From 36f0b9cc01513061c5dade96fe2c0b8e1e31351f Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sun, 4 Feb 2024 14:19:14 +0000 Subject: [PATCH 158/164] refactoring: wertevergleich --- test/Pong/test_checkCollision.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/Pong/test_checkCollision.c b/test/Pong/test_checkCollision.c index 74adc35..7d63643 100644 --- a/test/Pong/test_checkCollision.c +++ b/test/Pong/test_checkCollision.c @@ -32,7 +32,7 @@ void test_checkCollision(void){ // Test Ball trifft rechte und linke Wand ball.x = 0; int result1 = checkCollision(ball, paddle.y, paddle.y); - TEST_ASSERT_EQUAL_INT(1, result1); + TEST_ASSERT_EQUAL_INT(2, result1); ball.x = WIDTH - 1; int result2 = checkCollision(ball, paddle.y, paddle.y); @@ -42,22 +42,22 @@ void test_checkCollision(void){ ball.x = 5; ball.y = 0; int result3 = checkCollision(ball, paddle.y, paddle.y); - TEST_ASSERT_EQUAL_INT(0, result3); + TEST_ASSERT_EQUAL_INT(1, result3); ball.y = HEIGHT - 1; int result4 = checkCollision(ball, paddle.y, paddle.y); - TEST_ASSERT_EQUAL_INT(0, result4); + TEST_ASSERT_EQUAL_INT(1, result4); // Test wenn Ball Paddle trifft ball.x = paddle.x - 1; ball.y = paddle.y + 1; int result5 = checkCollision(ball, paddle.y, paddle.y); - TEST_ASSERT_EQUAL_INT(0, result5); + TEST_ASSERT_EQUAL_INT(1, result5); ball.x = paddle.x + 1; ball.y = paddle.y + 1; int result6 = checkCollision(ball, paddle.y, paddle.y); - TEST_ASSERT_EQUAL_INT(0, result6); + TEST_ASSERT_EQUAL_INT(1, result6); } #endif // TEST From e6a9a6f903b72be4aa05c586c4276e7d9fd20435 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sun, 4 Feb 2024 14:24:15 +0000 Subject: [PATCH 159/164] refactoring: werteausgabe --- test/Pong/test_checkCollision.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/Pong/test_checkCollision.c b/test/Pong/test_checkCollision.c index 7d63643..e2628be 100644 --- a/test/Pong/test_checkCollision.c +++ b/test/Pong/test_checkCollision.c @@ -32,11 +32,11 @@ void test_checkCollision(void){ // Test Ball trifft rechte und linke Wand ball.x = 0; int result1 = checkCollision(ball, paddle.y, paddle.y); - TEST_ASSERT_EQUAL_INT(2, result1); + TEST_ASSERT_EQUAL_INT(1, result1); ball.x = WIDTH - 1; int result2 = checkCollision(ball, paddle.y, paddle.y); - TEST_ASSERT_EQUAL_INT(1, result2); + TEST_ASSERT_EQUAL_INT(2, result2); // Test Ball trifft obere und untere Wand ball.x = 5; From 4cb53b42790b599798b88cbd882bb842d36a9ea9 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sun, 4 Feb 2024 14:28:42 +0000 Subject: [PATCH 160/164] refactoring: werteausgabe --- test/Pong/test_checkCollision.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Pong/test_checkCollision.c b/test/Pong/test_checkCollision.c index e2628be..cd7b0db 100644 --- a/test/Pong/test_checkCollision.c +++ b/test/Pong/test_checkCollision.c @@ -42,7 +42,7 @@ void test_checkCollision(void){ ball.x = 5; ball.y = 0; int result3 = checkCollision(ball, paddle.y, paddle.y); - TEST_ASSERT_EQUAL_INT(1, result3); + TEST_ASSERT_EQUAL_INT(0, result3); ball.y = HEIGHT - 1; int result4 = checkCollision(ball, paddle.y, paddle.y); From 490e7a8af95af67f1cb30d933bc9f1617faff05c Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sun, 4 Feb 2024 14:29:41 +0000 Subject: [PATCH 161/164] refactoring: werteausgabe --- test/Pong/test_checkCollision.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Pong/test_checkCollision.c b/test/Pong/test_checkCollision.c index cd7b0db..4b4e6e7 100644 --- a/test/Pong/test_checkCollision.c +++ b/test/Pong/test_checkCollision.c @@ -46,7 +46,7 @@ void test_checkCollision(void){ ball.y = HEIGHT - 1; int result4 = checkCollision(ball, paddle.y, paddle.y); - TEST_ASSERT_EQUAL_INT(1, result4); + TEST_ASSERT_EQUAL_INT(0, result4); // Test wenn Ball Paddle trifft ball.x = paddle.x - 1; From 7bb113ad02de63872a5264b651a5f1236db29c33 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sun, 4 Feb 2024 14:30:33 +0000 Subject: [PATCH 162/164] refactoring: werteausgabe --- test/Pong/test_checkCollision.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Pong/test_checkCollision.c b/test/Pong/test_checkCollision.c index 4b4e6e7..f05f7f8 100644 --- a/test/Pong/test_checkCollision.c +++ b/test/Pong/test_checkCollision.c @@ -52,7 +52,7 @@ void test_checkCollision(void){ ball.x = paddle.x - 1; ball.y = paddle.y + 1; int result5 = checkCollision(ball, paddle.y, paddle.y); - TEST_ASSERT_EQUAL_INT(1, result5); + TEST_ASSERT_EQUAL_INT(2, result5); ball.x = paddle.x + 1; ball.y = paddle.y + 1; From 2b1b3d81bb2f0cc1113c04be23f80e9d8b17a635 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sun, 4 Feb 2024 14:31:12 +0000 Subject: [PATCH 163/164] refactoring: werteausgabe --- test/Pong/test_checkCollision.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Pong/test_checkCollision.c b/test/Pong/test_checkCollision.c index f05f7f8..16be1ca 100644 --- a/test/Pong/test_checkCollision.c +++ b/test/Pong/test_checkCollision.c @@ -57,7 +57,7 @@ void test_checkCollision(void){ ball.x = paddle.x + 1; ball.y = paddle.y + 1; int result6 = checkCollision(ball, paddle.y, paddle.y); - TEST_ASSERT_EQUAL_INT(1, result6); + TEST_ASSERT_EQUAL_INT(2, result6); } #endif // TEST From a571ef920196e8f51c1457067a55689f10d6266c Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Sun, 4 Feb 2024 14:38:38 +0000 Subject: [PATCH 164/164] refactoring: optimierung_schleife --- test/Pong/test_clearScreen.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Pong/test_clearScreen.c b/test/Pong/test_clearScreen.c index e859d99..f2701a1 100644 --- a/test/Pong/test_clearScreen.c +++ b/test/Pong/test_clearScreen.c @@ -18,10 +18,10 @@ void test_clearScreen(void){ /* arrange */ int i, j; for (i = 0; i < TEST_SCREEN_HEIGHT; i++) { - for (j = 0; j < TEST_SCREEN_WIDTH+1; j++) { - screen[i][j] = 'X'; + for (j = 0; j < TEST_SCREEN_WIDTH; j++) { + screen[i][j] = ' '; } - screen[i][j-1] = '\0'; + screen[i][j] = '\0'; } /* act */ @@ -29,7 +29,7 @@ void test_clearScreen(void){ /* assert */ for (i = 0; i < TEST_SCREEN_HEIGHT; i++) { - for (j = 0; j < TEST_SCREEN_WIDTH+1; j++) { + for (j = 0; j < TEST_SCREEN_WIDTH; j++) { TEST_ASSERT_EQUAL_INT(' ', screen[i][j]); } }