From c3865b164d9defa4a3517efa1462beb07ad2f939 Mon Sep 17 00:00:00 2001 From: Julia Selig Date: Wed, 31 Jan 2024 13:09:11 +0000 Subject: [PATCH 01/73] 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 02/73] =?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 03/73] =?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 04/73] =?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 05/73] =?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 06/73] 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 07/73] 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 08/73] 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 09/73] 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 10/73] =?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 11/73] 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 12/73] 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 13/73] 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 14/73] 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 15/73] 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 16/73] 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 17/73] 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 18/73] 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 19/73] 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 20/73] 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 21/73] 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 22/73] =?UTF-8?q?refactoring:=5Fbesser=5Fpunkte=5Fz=C3=A4h?= =?UTF-8?q?len?= 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 23/73] =?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 24/73] 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 25/73] =?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 26/73] 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 27/73] 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 28/73] 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 29/73] =?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 b16143b39f4d20d6fe2ec0d7bef14521501ebf2d Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Fri, 2 Feb 2024 11:05:03 +0000 Subject: [PATCH 30/73] 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 31/73] 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 32/73] 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 33/73] =?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 34/73] 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 35/73] 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 36/73] 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 37/73] 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 38/73] 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 39/73] 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 40/73] 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 41/73] 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 42/73] 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 43/73] 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 44/73] =?UTF-8?q?Pr=C3=BCfen=20Spiellogik=20f=C3=BCr=20Bee?= =?UTF-8?q?nden=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 45/73] 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 46/73] 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 47/73] 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 48/73] 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 49/73] 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 50/73] 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 51/73] 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 52/73] 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 53/73] 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 54/73] 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 55/73] =?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 56/73] =?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 57/73] 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 58/73] =?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 59/73] 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 60/73] 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 61/73] =?UTF-8?q?refactoring:=20l=C3=B6schen=5Fnicht=5Fkon?= =?UTF-8?q?sistent?= 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 62/73] 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 63/73] 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 64/73] =?UTF-8?q?refactoring:=20einf=C3=BCgen=5Fballstrukt?= =?UTF-8?q?ur=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 65/73] =?UTF-8?q?refactoring:=20r=C3=BCckg=C3=A4ngig=5Fson?= =?UTF-8?q?st=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 66/73] =?UTF-8?q?Gel=C3=B6scht=20test/Pong/test=5FupdateBa?= =?UTF-8?q?llPosition.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 67/73] 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 68/73] 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 69/73] 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 70/73] 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 71/73] 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 72/73] 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 73/73] 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]); } }