本人想设计一个坦克大战的游戏,刚用了kbhit函数键盘操作这个坦克移动时,我的窗口一直在闪烁!求哪位大帮我 试着运行这个程序,萌新刚学easyx图形库想做个游戏。
代码如下:
#include <iostream>
#include <graphics.h>
#include<conio.h>
#include<windows.h>
using namespace std;
//全局变量
int x ;
int y ;
void Update()
{
x = 100;
y = 180;
}
// 坦克图形
void show()
{
initgraph(1200, 640);
BeginBatchDraw();
setbkcolor(WHITE);
cleardevice();
setfillcolor(GREEN);
setlinecolor(GREEN);
fillrectangle(x, y, x+250, y+120);
setlinecolor(BLACK);
fillrectangle(x+80, y-30, x+170, y);
setfillcolor(BLACK);
FlushBatchDraw();
fillroundrect(x-30, y+120, x+280, y+170, 40, 40);
setfillcolor(BROWN);
fillrectangle(x+250, y+40, x+380, y+70);
Sleep(50);
EndBatchDraw();
_getch();
closegraph();
}
void Updatewithinput()
{
char input;
if (_kbhit())
{
input = _getch();
if(input=='a')
x=x-50;
if(input=='d')
x=x+50;
}
}
int main()
{
Update();
while (1)
{
show();
Updatewithinput();
}
return 0;
}