?? c編小游戲.txt
字號(hào):
}
/*爆裂效果*/
void bomb(int x,int y)
{
int r1,i;
int pointX,pointY,point_color;
setcolor(YELLOW);
for(r1=1;r1<=4;r1++)
{
circle(x+16,y+7,r1);
delay(1000);
}
delay(3000);
setcolor(RED);
for(r1=1;r1>=6;r1++)
{
circle(x+16,y+7,r1);
delay(1000);
}
delay(3000);
setcolor(BLUE);
for(r1=6;r1>=1;r1--)
{
circle(x+16,y+7,r1);
delay(1000);
}
for(i=1;i<=50;i++)
{
point_color=rand()%15;
pointX=(rand()%32+x);
pointY=(rand()%15+y);
putpixel(pointX,pointY,point_color);
delay(1000);
}
setfillstyle(1,BLUE);
bar(x,y,x+32,y+15);
}
/*開(kāi)始游戲*/
void move()
{
int key;
int i,j,boxX,boxY;
int ballX,ballY,dX=1,dY=1;
int barX=300,barY=400,x,y;
randomize();
ballX=rand()%620+10;
ballY=rand()%200+190;
for(;;) /*受偵察的指點(diǎn)....*/
{
/*小球的運(yùn)動(dòng)*/
while(!kbhit())
{
if((ballX<=10)||(ballX>=630))
dX=dX*(-1);
if((ballY<=10)||(ballY>=470))
dY=dY*(-1);
setcolor(YELLOW);
circle(ballX+=dX,ballY-=dY,5);
setfillstyle(SOLID_FILL,YELLOW);
floodfill(ballX,ballY,YELLOW);
delay(2500);
setcolor(BLUE);
circle(ballX,ballY,5);
setfillstyle(SOLID_FILL,BLUE);
floodfill(ballX,ballY,BLUE);
/*判斷是否擊中方塊*/
for(boxY=0,i=0;boxY<=150;boxY=boxY+15,i++)
for(boxX=0,j=0;boxX<=640;boxX=boxX+32,j++)
{
if((ballX<boxX+32)&&(ballX>boxX)&&((ballY<=(boxY+20))&&(ballY>=boxY-5))&&(a[i][j].key==0))
{
dY=dY*(-1);
setfillstyle(1,BLUE);
bar(boxX,boxY,boxX+32,boxY+15);
bomb(boxX,boxY);
a[i][j].key=1;
break;
}
}
/*判斷反彈或出界*/
if((ballX>=barX)&&(ballX<=barX+60)&&(ballY>=390))
dY=dY*(-1);
if(((ballX<barX)||(ballX>barX+60))&&(ballY>410))
{
sleep(1);
k=1;
return;
}
}
/*球拍的運(yùn)動(dòng)*/
key=bioskey(0);
x=barX;
y=barY;
if(key==LEFT)
{
barX-=10;
setfillstyle(SOLID_FILL,BLUE);
bar(x,y,x+60,y+4);
setfillstyle(SOLID_FILL,RED);
bar(barX,barY,barX+60,barY+4);
}
else if(key==RIGHT)
{
barX+=10;
setfillstyle(SOLID_FILL,BLUE);
bar(x,y,x+60,y+4);
setfillstyle(SOLID_FILL,RED);
bar(barX,barY,barX+60,barY+4);
}
else if(key==ESC)
{
k=0;
break;
}
}
}
void main()
{
int i,j,x,y;
for(i=0,y=0;i<10;i++)
{
x=0;
for(j=0;j<20;j++)
{
a[i][j].x=x;
a[i][j].y=y;
a[i][j].key=0;
x=x+32;
}
y=y+15;
}
initgr();
picture();
move();
end();
closegr();
}
這是我們這學(xué)期的考試題目,要求是用C語(yǔ)言編一個(gè)五道棋的程序,用鼠標(biāo)走棋.并且能數(shù)棋盤(pán)上的棋子,能判斷勝負(fù),我寫(xiě)的程序如下,可能有些不足的地方,還請(qǐng)各位指教,謝謝,或許還能為出學(xué)者提供一些幫助
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<dos.h>
union REGS regs;
int a[5][5]={0};
int retcode;
int r=0;
int limtmouse() /*初始化鼠標(biāo)并且限制光標(biāo)的范圍*/
{ regs.x.ax=0;
int86(0x33,®s,®s); /*用該中斷函數(shù)驅(qū)動(dòng)鼠標(biāo)*/
retcode=regs.x.ax;
if(retcode==0)return 0;
regs.x.ax=7;
regs.x.cx=0;
regs.x.dx=639;
int86(0x33,®s,®s);
regs.x.ax=8;
regs.x.cx=0;
regs.x.dx=479;
int86(0x33,®s,®s);
return(retcode);
}
int mouseget(int *pa,int *pb,int *pc) /*獲得鼠標(biāo)的光標(biāo)值*/
{ regs.x.ax=3;
int86(0x33,®s,®s);
*pa=regs.x.cx;
*pb=regs.x.dx;
*pc=regs.x.bx;
}
void drawmouse(int x,int y) /*畫(huà)鼠標(biāo),/
{setcolor(1);
setlinestyle(0,0,1);
line(x,y,x+8,y+3);
line(x+8,y+3,x+6,y+4);
line(x+6,y+4,x+11,y+9);
line(x+11,y+9,x+9,y+11);
line(x+9,y+11,x+4,y+6);
line(x+4,y+6,x+3,y+8);
line(x+3,y+8,x,y);
}
void drawpic() /*畫(huà)棋盤(pán)*/
{ int i;
setbkcolor(12);
setfillstyle(1,2);
bar(40,40,440,450);
setlinestyle(0,0,3);
for(i=0;i<=640;i+=10)
{line(i,30,i+10,39);
line(i,440,i+10,449);
}
for(i=40;i<=440;i+=10) /*這是花邊*/
{rectangle(30,i,39,i+10);
rectangle(601,i,610,i+10);
}
setcolor(4);
for(i=80;i<=400;i+=80)
{line(80,i,400,i);
line(i,80,i,400);
}
bar(5,80,30,95); /*畫(huà)的兩個(gè)"begain" "eng"按扭*/
bar(5,160,30,175);
setlinestyle(0,0,1);
rectangle(5,80,30,95);
rectangle(5,160,30,175);
settextstyle(0,0,1);
setcolor(4);
outtextxy(6,83,"beg");
outtextxy(6,163,"end");
setcolor(4);
settextstyle(4,0,4);
outtextxy(50,0,"wellcome to play wu dao qi!!");
}
int count(int *pn,int *pm) /*數(shù)棋盤(pán)上的棋子*/
{int i,j,n1=0,n2=0;
for(i=0;i<5;i++)
for(j=0;j<5;j++)
{if(a[i][j]==1) n1++;
else if(a[i][j]==2) n2++;
else continue;
}
*pn=n1;
*pm=n2;
}
begjm() /*第一個(gè)界面,是為了美化游戲的*/
{ int i,j;
setbkcolor(12);
setlinestyle(0,0,4);
setfillstyle(1,0);
fillellipse(340,100,150,50);
setfillstyle(1,15);
fillellipse(280,90,20,15);
fillellipse(400,90,20,15);
setfillstyle(1,13);
setcolor(13);
fillellipse(340,130,30,10);
setcolor(14);
setfillstyle(1,2);
bar(130,150,550,400);
for(i=200;i>=100;i-=10)
for(j=100;j<=400;j+=20)
{line(i,j,i-10,j+20);
}
for(i=500;i<600;i+=10)
for(j=100;j<420;j+=20)
{line(i,j,i+10,j+20);
}
setcolor(6);
settextstyle(0,0,6);
outtextxy(200,200,"Please");
setcolor(13);
settextstyle(0,0,2);
outtextxy(135,300,"enter any key to begain!!!");
getch();
}
void printscore(int n1,int n2) /*在棋盤(pán)的右邊輸出分?jǐn)?shù)*/
{char tp[3],fp[3];
setfillstyle(1,3);
bar(440,40,600,440);
setfillstyle(1,r);
bar3d(460,120,560,240,30,1);
bar3d(460,300,560,420,30,1);
sprintf(tp,"%d",n1);
sprintf(fp,"%d",n2);
setcolor(r+1);
settextstyle(0,0,5);
outtextxy(500,180,tp);
outtextxy(500,360,fp);
settextstyle(1,0,2);
outtextxy(500,100,"white");
outtextxy(500,280,"green");
r++;
if(r>16) r=0;
if((n1+n2)==25&&n1>n2) /*當(dāng)棋盤(pán)下完后判斷勝負(fù)*/
{setfillstyle(1,3);
setcolor(4);
bar(50,50,440,440);
settextstyle(1,0,4);
outtextxy(150,200,"The wight win!!!");
}
else if((n1+n2)==25&&n1<n2)
{setfillstyle(1,3);
bar(50,50,440,440);
setcolor(4);
settextstyle(1,0,4);
outtextxy(150,200,"The green win!!!");
}
}
smath(int x,int y,int t,void *p1,void *p2,void *p3,void *p4,void *p5,void *p6,void *p7,void *p8,void *p9) /*判斷并吃掉棋子*/
{
int b1,b2,b3,b4,c1,c2,c3,c4;
b1=a[x-1][y];
b2=a[x-2][y];
b3=a[x+1][y];
b4=a[x+2][y];
c1=a[x][y-1];
c2=a[x][y-2];
c3=a[x][y+1];
c4=a[x][y+2];
if(b1==t&&b2!=t&&b2!=0&&x>=2) /*the up case*/
{if(x==2)
{if(y!=0&&y!=4) {putimage(y*80+40,40,p2,COPY_PUT);a[0][y]=0;}
else if(y==0) {putimage(40,40,p1,COPY_PUT);a[0][0]=0;}
else if(y==4) {putimage(360,40,p3,COPY_PUT);a[0][4]=0;}
}
else if(x>2)
{if(y!=0&&y!=4) {putimage(y*80+40,(x-2)*80+40,p9,COPY_PUT);a[x-2][y]=0;}
else if(y==0) {putimage(40,(x-2)*80+40,p8,COPY_PUT); a[x-2][0]=0;}
else if(y==4) {putimage(360,(x-2)*80+40,p4,COPY_PUT);a[x-2][4]=0;}
}
}
if(b3==t&&b4!=t&&b4!=0&&x<=2) /*the down case*/
{if(x==2)
{if(y!=0&&y!=4) {putimage(y*80+40,360,p6,COPY_PUT);a[4][y]=0;}
else if(y==0) {putimage(40,360,p7,COPY_PUT);a[4][0]=0;}
else if(y==4) {putimage(360,360,p5,COPY_PUT);a[4][4]=0;}
}
else if(x<2)
{if(y!=0&&y!=4) {putimage(y*80+40,(x+2)*80+40,p9,COPY_PUT);a[x+2][y]=0;}
else if(y==0) {putimage(40,(x+2)*80+40,p8,COPY_PUT); a[x+2][0]=0;}
else if(y==4) {putimage(360,(x+2)*80+40,p4,COPY_PUT);a[x+2][4]=0;}
}
}
if(b1!=0&&b3!=0&&x>0&&x<4) /*the middle case 1*/
{if(x==2)
{if(b1!=t&&b3==t)
{if(y!=0&&y!=4) {putimage(y*80+40,(x-1)*80+40,p9,COPY_PUT);a[1][y]=0;}
else if(y==0) {putimage(40,(x-1)*80+40,p8,COPY_PUT);a[1][0]=0;}
else if(y==4) {putimage(360,(x-1)*80+40,p4,COPY_PUT);a[1][4]=0;}
}
else if(b3!=t&&b1==t)
{if(y!=0&&y!=4) {putimage(y*80+40,(x+1)*80+40,p9,COPY_PUT); a[3][y]=0;}
else if(y==0) {putimage(40,(x+1)*80+40,p8,COPY_PUT);a[3][0]=0;}
else if(y==4) {putimage(360,(x+1)*80+40,p4,COPY_PUT);a[3][4]=0;}
}
}
else if(x==3)
{if(b1!=t&&b3==t)
{if(y!=0&&y!=4) {putimage(y*80+40,(x-1)*80+40,p9,COPY_PUT);a[2][y]=0;}
else if(y==0) {putimage(40,200,p8,COPY_PUT);a[2][0]=0;}
else if(y==4) {putimage(360,200,p4,COPY_PUT);a[2][4]=0;}
}
else if(b3!=t&&b1==t)
{if(y!=0&&y!=4) {putimage(y*80+40,360,p6,COPY_PUT); a[x+1][y]=0;}
else if(y==0) {putimage(40,360,p7,COPY_PUT);a[4][0]=0;}
else if(y==4) {putimage(360,360,p4,COPY_PUT);a[4][4]=0;}
}
}
else if(x==1)
{if(b1!=t&&b3==t)
{if(y!=0&&y!=4) {putimage(y*80+40,40,p2,COPY_PUT);a[0][y]=0;}
else if(y==0) {putimage(40,40,p1,COPY_PUT);a[0][0]=0;}
else if(y==4) {putimage(360,40,p3,COPY_PUT);a[0][4]=0;}
}
else if(b3!=t&&b1==t)
{if(y!=0&&y!=4) {putimage(y*80+40,200,p9,COPY_PUT); a[2][y]=0;}
else if(y==0) {putimage(40,200,p8,COPY_PUT);a[2][0]=0;}
else if(y==4) {putimage(360,200,p4,COPY_PUT);a[2][4]=0;}
}
}}
if(c1==t&&c2!=0&&c2!=t&&y>=2) /*the left case*/
{if(y==2)
{if(x!=0&&x!=4) {putimage(40,x*80+40,p8,COPY_PUT);a[x][0]=0;}
else if(x==0) {putimage(40,40,p1,COPY_PUT);a[0][0]=0;}
else if(x==4) {putimage(40,360,p7,COPY_PUT);a[4][0]=0;}
}
else if(y>2)
{if(x!=0&&x!=4) {putimage((y-2)*80+40,x*80+40,p9,COPY_PUT);a[x][y-2]=0;}
else if(x==0) {putimage((y-2)*80+40,40,p2,COPY_PUT); a[0][y-2]=0;}
else if(x==4) {putimage((y-2)*80+40,360,p6,COPY_PUT);a[4][y-2]=0;}
}
}
if(c3==t&&c4!=0&&c4!=t&&y<=2) /*the right case*/
{if(y==2)
{if(x!=0&&x!=4) {putimage(360,x*80+40,p4,COPY_PUT);a[x][4]=0;}
else if(x==0) {putimage(360,40,p3,COPY_PUT);a[0][4]=0;}
else if(x==4) {putimage(360,360,p5,COPY_PUT);a[4][4]=0;}
}
else if(y<2)
{if(x!=0&&x!=4) {putimage((y+2)*80+40,x*80+40,p9,COPY_PUT);a[x][y+2]=0;}
else if(x==0) {putimage((y+2)*80+40,40,p2,COPY_PUT); a[0][y+2]=0;}
else if(x==4) {putimage((y+2)*80+40,360,p6,COPY_PUT);a[4][y+2]=0;}
}
}
if(c1!=0&&c3!=0&&y>0&&y<4) /*the x middle case*/
{if(y==2)
{if(c1!=t&&c3==t)
{if(x!=0&&x!=4) {putimage(120,x*80+40,p9,COPY_PUT);a[x][1]=0;}
else if(x==0) {putimage(120,40,p2,COPY_PUT);a[0][1]=0;}
else if(x==4) {putimage(120,360,p6,COPY_PUT);a[4][1]=0;}
}
else if(c3!=t&&c1==t)
{if(x!=0&&x!=4) {putimage(280,x*80+40,p9,COPY_PUT); a[x][3]=0;}
else if(x==0) {putimage(280,40,p2,COPY_PUT);a[0][3]=0;}
else if(x==4) {putimage(280,360,p6,COPY_PUT);a[4][3]=0;}
}
}
else if(y==3)
{if(c1!=t&&c3==t)
{if(x!=0&&x!=4) {putimage(200,x*80+40,p9,COPY_PUT);a[x][2]=0;}
else if(x==0) {putimage(200,40,p2,COPY_PUT);a[0][2]=0;}
else if(x==4) {putimage(200,360,p6,COPY_PUT);a[4][2]=0;}
}
else if(c3!=t&&c1==t)
{if(x!=0&&x!=4) {putimage(360,x*80+40,p4,COPY_PUT); a[x][4]=0;}
else if(x==0) {putimage(360,40,p3,COPY_PUT);a[0][4]=0;}
else if(x==4) {putimage(360,360,p5,COPY_PUT);a[4][4]=0;}
}
}
else if(y==1)
{if(c1!=t&&c3==t)
{if(x!=0&&x!=4) {putimage(40,x*80+40,p8,COPY_PUT);a[x][0]=0;}
else if(x==0) {putimage(40,40,p1,COPY_PUT);a[0][0]=0;}
else if(x==4) {putimage(40,360,p7,COPY_PUT);a[4][0]=0;}
}
else if(c3!=t&&c1==t)
{if(x!=0&&x!=4) {putimage(200,x*80+40,p9,COPY_PUT); a[x][2]=0;}
else if(x==0) {putimage(200,40,p2,COPY_PUT);a[0][2]=0;}
else if(x==4) {putimage(200,360,p6,COPY_PUT);a[4][2]=0;}
}
}
}
}
forbegain() /*當(dāng)點(diǎn)擊開(kāi)始后方能下棋*/
{int x,y,z,*px,*py,*pz;
px=&x;
py=&y;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -