From 753dd2211c81e1989d33795aebe3ba6cbd3a4434 Mon Sep 17 00:00:00 2001 From: fdai8040 Date: Wed, 31 Jan 2024 13:32:36 +0000 Subject: [PATCH] =?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; } + +