c言语编的打砖块游戏

c言语编的打砖块游戏

03月 15, 2020 阅读 喜欢 0

  这是一个c言语编的打砖块游戏的雏形

  编译前在主目次下建立一个文本文件(xia.txt)内容为:0 0 0 0 0

  #include

  #include

  #include

  #include

  union REGS regs;

  unsigned int zhuan[5];

  int Msinit();

  void Setmouse(int left,int right,int top,int buttom);

  int Msread(int *xp,int *yp,int *bup);

  void Draw(int x,int y,int sizex,int sizey);

  main()

  {int mode=VGAHI,driver=VGA;
unsigned int l;
int i,gi,gj,j,flag=1;
double qx,qy,k,b=0.0,speech=0.4,x,y;
double r=2.0,bx=60.0,byy=270.0;
double pianx=100.0,piany=100.0,tx=20.0,ty=10.0,jx=2.0,jy=2.0;
int mx=0,my=0,mb,sum;
FILE * p;
if((p=fopen("xia.txt", "r"))==NULL)
{printf("The file cannot open!\n");
exit(1);}

  initgraph(&driver,&mode,"\\tc\\BGI");

  Msinit();

  Setmouse((int)(pianx+1+bx/2),(int)((tx+jx)*8+pianx-1-bx/2),(int)byy+piany,(int)byy+piany);

  star:cleardevice();

  sum=0;

  qx=100.0+pianx-10;qy=180.0+pianx-10;k=0.33;

  setcolor(7);

  rectangle((int)(pianx-2),(int)(piany-2),(int)((tx+jx)*8+2+pianx),302+piany);

  setcolor(1);

  rectangle((int)(pianx-1),(int)(piany-1),(int)((tx+jx)*8+1+pianx),301+piany);

  for(i=0;i<5;i++)

  fscanf(p,"%x ",&zhuan[i]);

  for(i=0;i<5;i++)

  {l=1;
for(j=0;j<16;j++)
{if((zhuan[i]&l)==0)
{Draw((int)((jx+tx)*((16*i+j)%8)+pianx+jx),(int)((jy+ty)*((int)((16*i+j)/8))+piany+jy),

(int)tx,(int)ty);
sum+=1;
}

  l=l*2;

  }

  }

  for(;;)

  { setfillstyle(1, 0);

  bar(mx-bx/2,my,mx+bx/2,my+5);

  Msread(&mx, &my, &mb);

  Draw(mx-bx/2,my,bx,5);

  setcolor(0);

  circle(qx,qy,r);

  if(qx-r<=pianx+1 || qx+r>=(tx+jx)*8+pianx-1) {flag=-flag;k=-k;}

  if(qy-r<=piany+1) k=-k;

  for(gi=0;gi<5;gi++)

  {l=1;
for(gj=0;gj<16;gj++)
{
if((zhuan[gi]&l)==0)
{j=(16*gi+gj)/8;
i=(16*gi+gj)%8;
x=(jx+tx)*i+jx+tx/2+pianx;
y=(jy+ty)*j+jy+ty/2+piany;

if(qy>=y-ty/2 && qy<=y+ty/2 &&(pow(qx+r-x+tx/2,2)<1 || pow(qx-r-x-tx/2,2)<1))
{flag=-flag;k=-k;
zhuan[gi]=zhuan[gi]|l;
sum-=1;
if(sum==0) {printf("Win!\n");getch();goto star;}

  setfillstyle(1, 0);

  bar((jx+tx)*i+pianx+jx,(jy+ty)*j+piany+jy,(jx+tx)*i+pianx+jx+tx,(jy+ty)

  *j+piany+jy+ty);

  }

  else

  if(qx>=x-tx/2 && qx<=x+tx/2 &&(pow(qy+r-y+ty/2,2)<1 || pow(qy-r-y-ty/2,2)<1))

  {k=-k;