New Text Document
New Text Document
h>
#include <graphics.h>
#include <dos.h>
#include <stdlib.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
// Game loop
while (1) {
cleardevice(); // Clear the screen
// Car controls
if (kbhit()) {
ch = getch();
if (ch == 27) // Exit if ESC key is pressed
break;
if (ch == 75 && carX > 160) // Left arrow key
carX -= 10;
if (ch == 77 && carX < 260) // Right arrow key
carX += 10;
}
// Display score
setcolor(WHITE);
char scoreStr[10];
sprintf(scoreStr, "Score: %d", score);
outtextxy(10, 10, scoreStr);