Browse Source

Spiel Pausieren

remotes/origin/branchJulia
fdai8040 11 months ago
parent
commit
13a15d1fc6
  1. 19
      src/main/c/Pong/game.c

19
src/main/c/Pong/game.c

@ -45,6 +45,7 @@ void drawField(int paddle1PositionY, int paddle2PositionY, Ball ball, int score1
} }
printf("Spieler 1: %d\tSpieler 2: %d\n", score1, score2); printf("Spieler 1: %d\tSpieler 2: %d\n", score1, score2);
printf("Drücken Sie 'p', um das Spiel zu pausieren.\n");
} }
@ -86,28 +87,38 @@ int main(){
int score1 = 0; int score1 = 0;
int score2 = 0; int score2 = 0;
int maxScore = 5; int maxScore = 5;
int isPaused = 0;
while (1) { while (1) {
//Steuerung für Schläger 1 //Steuerung für Schläger 1
if (kbhit()){ if (kbhit()){
char input = getch(); char input = getch();
if (input == 'w' && paddle1PositionY > 1)
if (input == 'w' && paddle1PositionY > 1 && !isPaused)
{ {
paddle1PositionY--; paddle1PositionY--;
} else if (input == 's' && paddle1PositionY < HEIGHT - PADDLE_LENGTH - 1) {
} else if (input == 's' && paddle1PositionY < HEIGHT - PADDLE_LENGTH - 1 && !isPaused) {
paddle1PositionY++; paddle1PositionY++;
} else if (input == 'p') {
isPaused = !isPaused;
} }
} }
//Steuerung für Schläger 2 //Steuerung für Schläger 2
if (kbhit()){ if (kbhit()){
char input = getch(); char input = getch();
if (input == 'i' && paddle2PositionY > 1) {
if (input == 'i' && paddle2PositionY > 1 && !isPaused) {
paddle2PositionY--; paddle2PositionY--;
} else if (input == 'k' && paddle2PositionY < HEIGHT - PADDLE_LENGTH - 1){
} else if (input == 'k' && paddle2PositionY < HEIGHT - PADDLE_LENGTH - 1 && !isPaused){
paddle2PositionY++; paddle2PositionY++;
} else if (input == 'p') {
isPaused = !isPaused;
} }
} }
//Wenn Pauseiert
if (isPaused) {
continue;
}
//Bewegung Ball //Bewegung Ball
ball.x += ball.speedX; ball.x += ball.speedX;

Loading…
Cancel
Save