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 <stdio.h>
#include <termios.h> #include <termios.h>
#include <stdlib.h>
#define WIDTH 40 //Breite Spielfeld #define WIDTH 40 //Breite Spielfeld
#define HEIGHT 20 //Höhe Spielfeld #define HEIGHT 20 //Höhe Spielfeld
#define PADDLE_LENGTH 4 #define PADDLE_LENGTH 4
#define PADDLE '#' #define PADDLE '#'
// Bildschirm löschen nach Veränderung Position
void clearScreen() {
system("clear");
}
void drawField(int paddle1PositionY, int paddle2PositionY) { void drawField(int paddle1PositionY, int paddle2PositionY) {
clearScreen();
for (int i = 0; i <= HEIGHT; i++){ for (int i = 0; i <= HEIGHT; i++){
for (int j = 0; j <= WIDTH; j++){ for (int j = 0; j <= WIDTH; j++){
if (i == 0 || i == HEIGHT){ if (i == 0 || i == HEIGHT){
@ -15,7 +23,7 @@ void drawField(int paddle1PositionY, int paddle2PositionY) {
printf("|"); printf("|");
} else if (i >= paddle1PositionY && i < paddle1PositionY + PADDLE_LENGTH && j == WIDTH) { } else if (i >= paddle1PositionY && i < paddle1PositionY + PADDLE_LENGTH && j == WIDTH) {
printf("%c", PADDLE); 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); printf("%c", PADDLE);
} else { } else {
printf(" "); printf(" ");
@ -61,6 +69,7 @@ int main(){
int paddle2PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2; int paddle2PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2;
while (1) { while (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)

Loading…
Cancel
Save