Browse Source

Spielstand

remotes/origin/branchJulia
fdai8040 11 months ago
parent
commit
16041ce711
  1. 21
      src/main/c/Pong/game.c

21
src/main/c/Pong/game.c

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

Loading…
Cancel
Save