在,你写的那个flappy bird为什么我运行的时候只能显示到主界面,但键盘输入之后没有反应?
小鸟与移动的障碍物
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<windows.h>
int high, width;
int x, y;
int bar_y, bar_D, bar_T; //障碍物的坐标
int score;
void gotoxy(int x, int y)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(handle, pos);
}
void HideCursor()
{
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
void startup()
{
high = 15;
width = 20;
x = high / 2;
y = 3;
bar_y = width / 2;
bar_D = high / 4;
bar_T = high / 2;
score = 0;
}
void show()
{
gotoxy(0, 0);
HideCursor();
int i, j;
for(i = 0; i < high; i++)
{
for(j = 0; j < width; j++)
{
if((i == x) && (j == y))
printf("@");
else if((j == bar_y) && ((i < bar_D) || (i > bar_T)))
printf("*");
else
printf(" ");
}
printf("\n");
}
for(j = 0; j < width; j++)
printf("-");
}
void updateWithoutInput()
{
x++;
bar_y--;
sleep(1);
}
void updateWithInput()
{
char input;
if(kbhit())
{
input = getch();
if(input == ' ')
x -= 2;
}
}
int main()
{
startup();
while(1)
{
show();
updateWithoutInput();
updateWithInput();
}
return 0;
}
有什么报错的信息吗,因为其他人都没有出现过这个问题。系统没有识别到你的键盘输入,有可能是小键盘没开启,也可能是没有点击游戏界面,如果后台没有报错的话,换一个设备试试