+ 1

where i was wrong?

#include <stdio.h> #include <stdlib.h> #include <conio.h> #define SCREEN_WIDTH 80 #define SCREEN_HEIGHT 25 struct player { int x; int y; }; struct obstacle { int x; int y; }; int main() { int score = 0; struct player p = {SCREEN_WIDTH / 2, SCREEN_HEIGHT - 1}; struct obstacle o = {rand() % SCREEN_WIDTH, 0}; while (1) { // Update player position based on user input if (kbhit()) { char key = getch(); if (key == 'a') { p.x--; } else if (key == 'd') { p.x++; } } // Update obstacle position o.y++; // Check for collision between player and obstacle if (o.y == p.y && o.x == p.x) { printf("Game over! Final score: %d\n", score); break; } // Spawn new obstacle if necessary if (o.y == SCREEN_HEIGHT) { o.y = 0; o.x = rand() % SCREEN_WIDTH; score++; } // Clear screen and draw player and obstacle system("cls"); printf("Score: %d\n", score); for (int i = 0; i < SCREEN_WIDTH; i++) { if (i == p.x) { printf("P"); } else if (i == o.x && o.y < SCREEN_HEIGHT) { printf("O"); } else { printf(" "); } } } return 0; }

5th Mar 2023, 3:51 PM
Gaurav Kumar
Gaurav Kumar - avatar
3 odpowiedzi
+ 3
What are you trying to do? What is the error? Be more clear.
5th Mar 2023, 4:00 PM
Lamron
Lamron - avatar
+ 1
conio.h doesn't work in sololearn. It may also be compiler specific.
5th Mar 2023, 6:07 PM
Kashyap Kumar
Kashyap Kumar - avatar
+ 1
Not working in this app
6th Mar 2023, 4:01 PM
Gaurav Kumar
Gaurav Kumar - avatar