井字棋游戏源代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

井字棋C语言源代码#includegraphics.h#includemath.h#includedos.h#includebios.h#includeconio.h#includestring.h#defineENTER0x1c0d#defineesc0x11b#defineup0x4800#definedown0x5000#defineleft0x4b00#defineright0x4d00inti,j,x1,y1,v,n,m,key,d,e,p,q,h,o,x,y,k;inta[3][3]={0,0,0,0,0,0,0,0,0};intscore[3][3]={0,0,0,0,0,0,0,0,0};chars[30];intmain(){voiddrawone();voiddrawtwo();voiddrawthree();voiddrawfour();voiddrawfive();voiddrawsix();voidxianka();intrenzouqi();intxuanze();intpy(inta[][3]);intjisuanji();intxuanzeyouxi();intbioskey(intcmd);xianka();drawone();if((key=bioskey(0))==ENTER)drawtwo();key=bioskey(0);if(key==ENTER)drawfour();v=1;while(v==1){drawthree();n=xuanze();x1=220;y1=230;circle(220,230,20);o=pan_y(a);while(o==2){if(n==1)n=renzouqi();if(n==-1)n=jisuanji();o=pan_y(a);}drawsix();getch();drawfive();v=xuanzeyouxi();}closegraph();}/*显卡驱动*/voidxianka(){intgraphdriver,graphmode;intdriver=DETECT,mode;initgraph(&driver,&mode,);graphdriver=DETECT;initgraph(&graphdriver,&graphmode,);}/*定义判赢函数*/intpan_y(inta[][3]){intn,b,c,i,j,k=2;for(i=0;i3;i++){n=a[i][0];b=a[i][1];c=a[i][2];if(n+b+c==3)k=1;if(n+b+c==-3)k=-1;}for(j=0;j3;j++){n=a[0][j];b=a[1][j];c=a[2][j];if(n+b+c==3)k=1;if(n+b+c==-3)k=-1;}n=a[0][0];b=a[1][1];c=a[2][2];if(n+b+c==3)k=1;if(n+b+c==-3)k=-1;n=a[0][2];b=a[1][1];c=a[2][0];if(n+b+c==3)k=1;if(n+b+c==-3)k=-1;if(a[0][0]!=0&&a[0][1]!=0&&a[0][2]!=0&&a[1][0]!=0&&a[1][1]!=0&&a[1][2]!=0&&a[2][0]!=0&&a[2][1]!=0&&a[2][2]!=0)k=0;returnk;}/*选择哪一方先下*/intxuanze(){key=bioskey(0);n=-1;while(key!=ENTER){if(key==up){setfillstyle(1,3);floodfill(471,150,4);setfillstyle(1,14);floodfill(471,200,4);n=-1;}if(key==down){setfillstyle(1,14);floodfill(471,150,4);setfillstyle(1,3);floodfill(550,200,4);n=1;}key=bioskey(0);}returnn;}/*界面1*/voiddrawone(){for(i=1;i6;i++){setcolor(i);settextstyle(0,HORIZ_DIR,i);outtextxy(250-43*i,80*i,WelcomeToYou);}setcolor(10);settextstyle(0,VERT_DIR,2);outtextxy(20,80,***HowDoYouDo***);settextstyle(0,VERT_DIR,2);outtextxy(620,80,***HowDoYouDo***);setcolor(13);line(20,0,20,479);line(22,0,22,479);line(600,0,600,479);line(602,0,602,479);}/*界面2*/voiddrawtwo(){cleardevice();setbkcolor(2);setviewport(0,0,639,479,0);settextstyle(1,0,6);setfillstyle(1,12);rectangle(230,10,370,280);floodfill(150,350,13);settextstyle(1,0,5);setbkcolor(0);outtextxy(250,10,Jing);outtextxy(280,100,Zi);outtextxy(280,200,Qi);settextstyle(1,0,3);setcolor(0);outtextxy(250,300,Designedby:ZhangKaiXuan);outtextxy(402,350,YangShaoHua);outtextxy(402,400,RenJian);}/*界面3*/voiddrawthree(){cleardevice();setbkcolor(14);setviewport(0,0,639,479,1);setfillstyle(1,2);setcolor(4);line(70,180,370,180);line(70,280,370,280);line(170,80,170,380);line(270,80,270,380);line(470,180,570,180);rectangle(470,130,570,230);setfillstyle(1,3);floodfill(500,150,4);settextstyle(1,0,2);outtextxy(475,190,person);outtextxy(475,140,computer);settextstyle(3,0,1);outtextxy(468,260,person);circle(557,274,10);setfillstyle(1,13);floodfill(555,274,4);outtextxy(468,300,computer);circle(557,308,10);setfillstyle(1,3);floodfill(555,300,4);}/*界面4*/voiddrawfour(){inti,x5=300,y5=200,r=100,x6=350,y6=200;cleardevice();setbkcolor(8);setcolor(14);settextstyle(1,0,5);setviewport(0,0,639,479,0);for(i=0;i800;i++){x6=x5+r*cos(i*2*3.1415926/50);y6=y5+r*sin(i*2*3.1415926/50);setcolor(i%15);line(x5,y5,x6,y6);outtextxy(222,350,Loading.....);}}/*界面5*/voiddrawfive(){cleardevice();setviewport(0,0,639,479,1);circle(120,240,30);setfillstyle(1,3);circle(115,225,4);circle(135,225,4);floodfill(115,225,2);floodfill(135,225,2);setfillstyle(1,7);floodfill(120,240,2);line(115,251,133,247);settextstyle(1,0,1);outtextxy(400,400,choosequitornewgame);outtextxy(381,325,NEW);outtextxy(480,325,QUIT);settextstyle(1,0,5);if(o==-1)outtextxy(200,230,Youlost!Comeon!);if(o==1)outtextxy(200,230,Youwin!);if(o==0)outtextxy(200,230,DRAW!);circle(400,330,25);circle(500,330,25);setfillstyle(1,12);floodfill(400,330,2);}/*界面6*/voiddrawsix(){settextstyle(1,0,5);setcolor(2);outtextxy(110,410,GAMEOVER!);}/*人下棋*/intrenzouqi(){key=bioskey(0);while(key!=ENTER){if(key==up){x=x1;y=y1-100;if(y80){setcolor(14);circle(x1,y1,20);setcolor(4);circle(x,y,20);x1=x;y1=y;}}if(key==down){x=x1;y=y1+100;if(y380){setcolor(14);circle(x1,y1,20);setcolor(4);circle(x,y,20);x1=x;y1=y;}}if(key==left){x=x1-100;y=y1;if(x70){setcolor(14);circle(x1,y1,20);setcolor(4);circle(x,y,20);x1=x;y1=y;}}if(key==right){x=x1+100;y=y1;if(x370){setcolor(14);circle(x1,y1,20);setcolor(4);circle(x,y,20);x1=x;y1=y;}}key=bioskey(0);}if(a[(x1-120)/100][(y1-130)/100]==0){setfillstyle(1,13);floodfill(x1,y1,4);d=(x1-120)/100;e=(y1-130)/100;a[d][e]=1;n=-1;}elsen=1;returnn;}/*计算机下棋*/intjisuanji(){for(i=0;i3;i++){for(j=0;j3;j++){if(a[i][j]!=0)score[i][j]=-2;}}for(i=0;i3;i++){m=a[i][0];p=a[i][1];q=a[i][2];if(m+p+q==2){if(m==0)score[i][0]=25;if(p==0)score[i][1]=25;if(q==0)score[i][2]=25;}if(m+p+q==-2){if(m==0)score[i][0]=50;if(p==0)score[i][1]=50;if(q==0)score[i][2]=50;}if(m+p+q==1){if(p==0&&q==0)score[i][1]=score[i][2]=8;if(m==0&&q==0)score[i][0]=score[i][2]=8;if(p==0&&p==0)score

1 / 11
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功