#include <stdio.h>
#include <conio.h>
#include <windows.h>
#define SCREEN_WIDTH 50
#define SCREEN_HEIGHT 20
#define DINO_POS 5
int dinoY = SCREEN_HEIGHT - 2;
int isJumping = 0;
int jumpHeight = 6;
int jumpProgress = 0;
void gotoxy(int x, int y) {
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
void drawDino() {
gotoxy(DINO_POS, dinoY);
}
void eraseDino() {
gotoxy(DINO_POS, dinoY);
}
void jump() {
if (!isJumping) {
isJumping = 1;
jumpProgress = jumpHeight;
}
}
void update() {
if (isJumping) {
eraseDino();
if (jumpProgress > 0) {
dinoY--;
jumpProgress--;
} else {
isJumping = 0;
}
} else if (dinoY < SCREEN_HEIGHT - 2) {
eraseDino();
dinoY++;
}
drawDino();
}
int main() {
char input;
drawDino();
while (1) {
if (_kbhit()) {
input = _getch();
if (input == ' ') {
jump();
} else if (input == 'q') {
break;
}
}
update();
}
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxjb25pby5oPgojaW5jbHVkZSA8d2luZG93cy5oPgoKI2RlZmluZSBTQ1JFRU5fV0lEVEggNTAKI2RlZmluZSBTQ1JFRU5fSEVJR0hUIDIwCiNkZWZpbmUgRElOT19QT1MgNQoKaW50IGRpbm9ZID0gU0NSRUVOX0hFSUdIVCAtIDI7CmludCBpc0p1bXBpbmcgPSAwOwppbnQganVtcEhlaWdodCA9IDY7CmludCBqdW1wUHJvZ3Jlc3MgPSAwOwoKdm9pZCBnb3RveHkoaW50IHgsIGludCB5KSB7CiAgICBDT09SRCBjb29yZDsKICAgIGNvb3JkLlggPSB4OwogICAgY29vcmQuWSA9IHk7CiAgICBTZXRDb25zb2xlQ3Vyc29yUG9zaXRpb24oR2V0U3RkSGFuZGxlKFNURF9PVVRQVVRfSEFORExFKSwgY29vcmQpOwp9Cgp2b2lkIGRyYXdEaW5vKCkgewogICAgZ290b3h5KERJTk9fUE9TLCBkaW5vWSk7CiAgICBwcmludGYoIk8iKTsKfQoKdm9pZCBlcmFzZURpbm8oKSB7CiAgICBnb3RveHkoRElOT19QT1MsIGRpbm9ZKTsKICAgIHByaW50ZigiICIpOwp9Cgp2b2lkIGp1bXAoKSB7CiAgICBpZiAoIWlzSnVtcGluZykgewogICAgICAgIGlzSnVtcGluZyA9IDE7CiAgICAgICAganVtcFByb2dyZXNzID0ganVtcEhlaWdodDsKICAgIH0KfQoKdm9pZCB1cGRhdGUoKSB7CiAgICBpZiAoaXNKdW1waW5nKSB7CiAgICAgICAgZXJhc2VEaW5vKCk7CiAgICAgICAgaWYgKGp1bXBQcm9ncmVzcyA+IDApIHsKICAgICAgICAgICAgZGlub1ktLTsKICAgICAgICAgICAganVtcFByb2dyZXNzLS07CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgaXNKdW1waW5nID0gMDsKICAgICAgICB9CiAgICB9IGVsc2UgaWYgKGRpbm9ZIDwgU0NSRUVOX0hFSUdIVCAtIDIpIHsKICAgICAgICBlcmFzZURpbm8oKTsKICAgICAgICBkaW5vWSsrOwogICAgfQogICAgZHJhd0Rpbm8oKTsKfQoKaW50IG1haW4oKSB7CiAgICBjaGFyIGlucHV0OwogICAgc3lzdGVtKCJjbHMiKTsKICAgIGRyYXdEaW5vKCk7CiAgICAKICAgIHdoaWxlICgxKSB7CiAgICAgICAgaWYgKF9rYmhpdCgpKSB7CiAgICAgICAgICAgIGlucHV0ID0gX2dldGNoKCk7CiAgICAgICAgICAgIGlmIChpbnB1dCA9PSAnICcpIHsKICAgICAgICAgICAgICAgIGp1bXAoKTsKICAgICAgICAgICAgfSBlbHNlIGlmIChpbnB1dCA9PSAncScpIHsKICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIHVwZGF0ZSgpOwogICAgICAgIFNsZWVwKDUwKTsKICAgIH0KICAgIAogICAgcmV0dXJuIDA7Cn0K