#include <stdio.h>
#include <stdlib.h>
#include <conio.h> // Windows ke liye, agar online compiler mein na ho toh getchar() use kar sakte hain
#include <stdbool.h>
#define WIDTH 20
void printGame(int position) {
system("cls"); // Screen clear karta hai (Windows). Online compiler me kaam na kare toh use "\n" se screen clear karen
for (int i = 0; i < WIDTH; i++) {
if (i == position)
printf("M"); // Mario ko M se represent kar rahe hain
else
printf("-");
}
printf("\n");
}
int main() {
int position = WIDTH / 2;
char input;
bool running = true;
printf("Use 'a' to move left, 'd' to move right, 'q' to quit.\n");
while (running) {
printGame(position);
input = getchar();
if (input == 'a' || input == 'A') {
if (position > 0)
position--;
} else if (input == 'd' || input == 'D') {
if (position < WIDTH - 1)
position++;
} else if (input == 'q' || input == 'Q') {
running = false;
}
// Input buffer clear karne ke liye
while ((input = getchar()) != '\n' && input != EOF) {}
}
printf("Game over!\n");
return 0;
}