#include <graphics.h>
#include <dos.h>
#define MaxWidth 640
#define MaxHeight 480
#define MiddX 320
#define MiddY 240
int main()
{
int gdriver,gmode;
int x1,y1,x2,y2; /*确定矩形的4个参数*/
int stepX=4,stepY=3; /*画图间距*/
x1=x2=MiddX;
y1=y2=MiddY; /*初始化数据*/
detectgraph(&gdriver,&gmode);
initgraph(&gdriver,&gmode,"");
setwritemode(XOR_PUT); /*异或方式*/
setbkcolor(RED);
setcolor(YELLOW);
setlinestyle(SOLID_LINE,0,1);/*设置线形,实线,线宽1*/
while (!kbhit())
{
x1=x1-stepX;
y1=y1-stepY;
x2=x2+stepX;
y2=y2+stepY;
rectangle(x1,y1,x2,y2);
if (x2>=MaxWidth || x2==MiddX || y2>=MaxHeight || y2==MiddY){
stepY=-stepY;
stepX=-stepX;
}
delay(1000);
}
closegraph();
return 0;
}
我在return 0;前面加不加getch();结果都是一闪而过,怎么回事呢?