From eadc41ecfb1554d6dae53cc4ad57e5da65ce62b9 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 15:46:23 +0000 Subject: [PATCH] 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 }