Browse Source

Hinzufügen Schlägel

remotes/origin/branchJulia
fdai8040 11 months ago
parent
commit
753dd2211c
  1. 32
      src/main/c/Pong/game.c

32
src/main/c/Pong/game.c

@ -2,14 +2,20 @@
#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 '#'
void drawField() {
void drawField(int paddle1PositionY, int paddle2PositionY) {
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){
printf("-"); printf("-");
} else if ("i == 0 || j == WIDTH") {
} else if ("j == 0 || j == WIDTH") && (i < paddle1PositionY || i >= paddle1PositionY + PADDLE_LENGTH) && (i < paddle2PositionY || i >= paddle2PositionY + PADDLE_LENGTH)) {
printf("|"); printf("|");
} else if (i >= paddle1PositionY && i < paddle1PositionY + PADDLE_LENGTH && j == WIDTH) {
printf("%c", PADDLE);
}else if (i >= paddle2PositionY && i < paddle2PositionY + PADDLE_LENGTH && j == 0) {
printf("%c", PADDLE);
} else { } else {
printf(" "); printf(" ");
} }
@ -19,7 +25,27 @@ void drawField() {
} }
int main(){ int main(){
drawField();
int paddle1PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2;
int paddle2PositionY = HEIGHT / 2 - PADDLE_LENGTH / 2;
while (1) {
if (kbhit()){
char input = getch();
if (input == 'w' && paddle1PositionY > 1)
{
paddle1PositionY--;
} else if (input == 's' && paddle1PositionY < HEIGHT - PADDLE_LENGTH - 1) {
paddle1PositionY++;
}
}
// Hier Steuerung für Schläger 2 noch reinschreiben
draw Field(paddle1PositionY, paddle2PositionY);
}
return 0; return 0;
} }
Loading…
Cancel
Save