求C语言编写的壁球小游戏的源代码,谢谢。

2021-12-15 教育 150阅读
速度和接板长度不能改

所以比较难玩

#include"graphics.h"
#include"stdio.h"
#include"conio.h"

inton;
staticintscore;



intopen()
{
setviewport(100,100,500,380,1);
setcolor(4);
rectangle(0,0,399,279);
setfillstyle(SOLID_FILL,7);
floodfill(50,50,4);
setcolor(8);
settextstyle(0,0,9);
outtextxy(90,80,"BALL");
settextstyle(0,0,1);
outtextxy(110,180,"version1.0");
outtextxy(110,190,"madebyddt");
setcolor(128);
settextstyle(0,0,1);
outtextxy(120,240,"Pressanykeytocontinue......");
}


intquitwindow()
{
chars[100];
setviewport(100,150,540,420,1);
setcolor(YELLOW);
rectangle(0,0,439,279);
setfillstyle(SOLID_FILL,7);
floodfill(50,50,14);
setcolor(12);
settextstyle(0,0,8);
outtextxy(120,80,"End");
settextstyle(0,0,2);
outtextxy(120,200,"quit?Y/N");
sprintf(s,"Yourscoreis:%d",score);
outtextxy(120,180,s);
on=1;
}


main()
{
intgdriver,gmode;
gdriver=DETECT;
gmode=0;
registerbgidriver(EGAVGA_driver);
initgraph(&gdriver,&gmode,"");
setbkcolor(14);
open();
getch();

while(1)
{
intdriver,mode,l=320,t=400,r,a,b,dl=5,n,x=200,y=400,r1=10,dx=-2,dy=-2;
intleft[100],top[100],right[100],bottom[100],i,j,k,off=1,m,num[100][100];
staticintpp;
staticintphrase;
intoop=15;
pp=1;
score=0;
driver=DETECT;
mode=VGA;
registerbgidriver(EGAVGA_driver);
initgraph(&driver,&mode,"");
setbkcolor(10);
cleardevice();
clearviewport();
b=t+6;
r=l+60;
setcolor(1);
rectangle(0,0,639,479);
setcolor(4);
rectangle(l,t,r,b);
setfillstyle(SOLID_FILL,1);
floodfill(l+2,t+2,4);

for(i=0,k=0;i<=6;i++)
{
top[i]=k;
bottom[i]=top[i]+20;
k=k+21;
oop--;
for(j=0,m=0;j<=7;j++)
{
left[j]=m;
right[j]=left[j]+80;
m=m+81;
setcolor(4);
rectangle(left[j],top[i],right[j],bottom[i]);
setfillstyle(SOLID_FILL,j+oop);
floodfill(left[j]+1,top[i]+1,4);
num[i][j]=pp++;
}
}

while(1)
{
while(!kbhit())
{
x=x+dx;
y=y+dy;
if(x+r1>r||x+r1{phrase=0;}
if((x-r1<=r||x+r1<=r)&&x+r1>=l)
{
if(yphrase=1;
if(y+r1>=t&&phrase==1)
{dy=-dy;y=t-1-r1;}
}

if(off==0)
continue;

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

for(j=0;j<=7;j++)
{
if((x+r1<=right[j]&&x+r1>=left[j])||(x-r1<=right[j]&&x-r1>=left[j]))
{
if((y-r1>top[i]&&y-r1<=bottom[i])||(y+r1>=top[i]&&y+r1<=bottom[i]))
{
if(num[i][j]==0)
{continue;}
setcolor(10);
rectangle(left[j],top[i],right[j],bottom[i]);
setfillstyle(SOLID_FILL,10);
floodfill(left[j]+1,top[i]+1,10);
dy=-dy;
num[i][j]=0;
score=score+10;
printf("%d\b\b\b",score);
}
}
if((y+r1>=top[i]&&y+r1<=bottom[i])||(y-r1>=top[i]&&y-r1<=bottom[i]))
{
if((x+r1>=left[j]&&x+r1left[j]))
{
if(num[i][j]==0)
{continue;}
setcolor(10);
rectangle(left[j],top[i],right[j],bottom[i]);
setfillstyle(SOLID_FILL,10);
floodfill(left[j]+1,top[i]+1,10);
dx=-dx;
num[i][j]=0;
score=score+10;
printf("%d\b\b\b",score);
}
}
}

if(x+r1>639)
{dx=-dx;x=638-r1;}
if(x<=r1)
{dx=-dx;x=r1+1;}
if(y+r1>=479)
{off=0;quitwindow();break;}
if(y<=r1)
{dy=-dy;y=r1+1;}
if(score==560)
{off=0;quitwindow();break;}
setcolor(6);
circle(x,y,r1);
setfillstyle(SOLID_FILL,14);
floodfill(x,y,6);
delay(1000);
setcolor(10);
circle(x,y,r1);
setfillstyle(SOLID_FILL,10);
floodfill(x,y,10);
}

a=getch();
setcolor(10);
rectangle(l,t,r,b);
setfillstyle(SOLID_FILL,10);
floodfill(l+2,t+2,10);
if(a==77&&l<=565)
{dl=20;l=l+dl;}
if(a==75&&l>=15)
{dl=-20;l=l+dl;}
if(a=='y'&&on==1)
break;
if(a=='n'&&on==1)
break;
if(a==27)
{quitwindow();off=0;}
r=l+60;
setcolor(4);
rectangle(l,t,r,b);
setfillstyle(SOLID_FILL,1);
floodfill(l+5,t+5,4);
delay(100);
}
if(a=='y'&&on==1)
{break;}
if(a=='n'&&on==1)
{continue;}
}
closegraph();

}

你不是要求在TC里运行么
C++和C不同的
如果要在C++里
你前面要写函数的声明的
C里就不用

修改过了,试一试吧。
我这里可以
一闪而过那个是图形界面的问题
驱动没安装好
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com