Browse Source

Bildschirm löschen

remotes/origin/branchJulia
fdai8040 11 months ago
parent
commit
30b212b1cf
  1. 11
      src/main/c/Pong/game.c

11
src/main/c/Pong/game.c

@ -1,12 +1,20 @@
#include <stdio.h>
#include <termios.h>
#include <stdlib.h>
#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)

Loading…
Cancel
Save