|
@ -22,7 +22,7 @@ void clearScreen() { |
|
|
system("clear"); |
|
|
system("clear"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void drawField(int paddle1PositionY, int paddle2PositionY, Ball ball) { |
|
|
|
|
|
|
|
|
void drawField(int paddle1PositionY, int paddle2PositionY, Ball ball, int score1, int score2) { |
|
|
clearScreen(); |
|
|
clearScreen(); |
|
|
|
|
|
|
|
|
for (int i = 0; i <= HEIGHT; i++){ |
|
|
for (int i = 0; i <= HEIGHT; i++){ |
|
@ -43,6 +43,9 @@ void drawField(int paddle1PositionY, int paddle2PositionY, Ball ball) { |
|
|
} |
|
|
} |
|
|
printf("\n"); |
|
|
printf("\n"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
printf("Spieler 1: %d\tSpieler 2: %d\n", score1, score2); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int kbhit(void){ |
|
|
int kbhit(void){ |
|
@ -64,7 +67,7 @@ int kbhit(void){ |
|
|
if (ch != EOF) { |
|
|
if (ch != EOF) { |
|
|
ungetc(ch, stdin); |
|
|
ungetc(ch, stdin); |
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -118,6 +121,20 @@ int main(){ |
|
|
ball.speedX = -ball.speedX; |
|
|
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); |
|
|
draw Field(paddle1PositionY, paddle2PositionY); |
|
|
|
|
|
|
|
|
usleep(100000); //Verlangsamen Schleife/Spiel |
|
|
usleep(100000); //Verlangsamen Schleife/Spiel |
|
|