From 30b212b1cff3dfaa6bbf2a31b1dc354f5c63acf5 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 14:54:05 +0000 Subject: [PATCH] =?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)