Browse Source

Hinzufügen Tastatureingabe

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

31
src/main/c/Pong/game.c

@ -1,4 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <termios.h>
#define WIDTH 40 //Breite Spielfeld #define WIDTH 40 //Breite Spielfeld
#define HEIGHT 20 //Höhe Spielfeld #define HEIGHT 20 //Höhe Spielfeld
@ -24,6 +25,36 @@ void drawField(int paddle1PositionY, int paddle2PositionY) {
} }
} }
int kbhit(void){
struct termios oldt, newt;
int ch, oldf;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);
ch = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
fcntl(STDIN_FILENO, F_SETFL, oldf);
if (ch != EOF) {
ungetc(ch, stdin);
return 1;
}
return 0;
}
int getch(void) {
int ch;
while ((ch = getchar()) == '\n');
return ch;
}
int main(){ int main(){
int paddle1PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; int paddle1PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2;

Loading…
Cancel
Save