0

私は単純な弾むボールのコードを実行しようとしています.以下のコードはボールを弾ませません.Enterボタンを使用するとボールが動くだけです.プログラムが走る?

#include<alloc.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>
#include<dos.h>

void main()
{
int d=DETECT,m;
initgraph(&d,&m,"H:\\tc\\bgi");
int l=getmaxx()/2,t=0;
int x=1,y=1;
int xstep=1,ystep=1;
while(!kbhit())
{
cleardevice();
 circle(l,t,18);
  delay(5);
circle(l,t,18);

  if(l>=getmaxx()||l<=0)
  {
x*=-1;
xstep=x*(random(4)+1);
ystep=y*(random(3)+1);

  if (l<=0)
   t=0;
 else
  l=getmaxx();
   }
   if(t>=getmaxy()||t<=0)
   {
 y*=-1;
 ystep=(y*random(4)+1);
 xstep=(x*random(3)+1);
   if(t<=0)
 t=0;
   else
 t=getmaxy();
  }
l+=x+xstep;
t+=y+ystep ;
getch();

}
closegraph();

}

4

1 に答える 1

0

早い段階でいくつかの変更を加えることをお勧めします。

  • ループでは使用getch()しないでください。while
  • 関数のパラメーターの値を増減してみてください delay()
  • ellipseの代わりに試してくださいcircle
于 2012-12-06T12:45:23.837 に答える