井字棋游戏源代码.docx

上传人:b****1 文档编号:10688567 上传时间:2023-05-27 格式:DOCX 页数:11 大小:16.49KB
下载 相关 举报
井字棋游戏源代码.docx_第1页
第1页 / 共11页
井字棋游戏源代码.docx_第2页
第2页 / 共11页
井字棋游戏源代码.docx_第3页
第3页 / 共11页
井字棋游戏源代码.docx_第4页
第4页 / 共11页
井字棋游戏源代码.docx_第5页
第5页 / 共11页
井字棋游戏源代码.docx_第6页
第6页 / 共11页
井字棋游戏源代码.docx_第7页
第7页 / 共11页
井字棋游戏源代码.docx_第8页
第8页 / 共11页
井字棋游戏源代码.docx_第9页
第9页 / 共11页
井字棋游戏源代码.docx_第10页
第10页 / 共11页
井字棋游戏源代码.docx_第11页
第11页 / 共11页
亲,该文档总共11页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

井字棋游戏源代码.docx

《井字棋游戏源代码.docx》由会员分享,可在线阅读,更多相关《井字棋游戏源代码.docx(11页珍藏版)》请在冰点文库上搜索。

井字棋游戏源代码.docx

井字棋游戏源代码

井字棋游戏源代码

井字棋C语言源代码

#include#include

#include

#include

#include#include#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();

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;i<3;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;j<3;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);

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;i<6;i++){setcolor(i);

settextstyle(0,HORIZ_DIR,i);outtextxy(250-43*i,80*i,"WelcomeTo

You");}setcolor(10);

settextstyle(0,VERT_DIR,2);outtextxy(20,80,"***HowDoYouDo***"settextstyle(0,VERT_DIR,2);outtextxy(620,80,"***HowDoYouDosetcolor(13);

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);

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);

setviewport(0,0,639,479,0);for(i=0;i<800;i++){

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(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(y>80){setcolor(14);

setcolor(4);

if(key==down){x=x1;y=y1+100;

if(y<380){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(x>70){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(x<370){setcolor(14);

circle(x1,y1,20);

setcolor(4);

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;i<3;i++){for(j=0;j<3;j++){if(a[i][j]!

=0)score[i][j]=-2;}for(i=0;i<3;i++){m=a[i][0];p=a[i][1];q=a[i][2];

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[i][1]=score[i][0]=8;

if(m+p+q==-1){if(p==0&&q==0)score[i][1]=score[i][2]=10;

if(m==0&&q==0)score[i][0]=score[i][2]=10;

if(p==0&&m==0)score[i][1]=score[i][0]=10;

if(m+p+q==0){if(m==0&&p==0&&q==0)score[i][0]=score[i][1]=score[i][2]=4;

}/*end横*/

for(i=0;i<3;i++){m=a[0][i];p=a[1][i];q=a[2][i];

if(p==0){if(score[1][i]<25)score[1][i]=25;}if(q==0){if(score[2][i]<25)score[2][i]=25;}if(m+p+q==-2){if(m==0){if(score[0][i]<50)score[0][i]=50;}if(p==0){if(score[0][i]<50)score[1][i]=50;}if(q==0){if(score[0][i]<50)score[2][i]=50;}if(m+p+q==1){if(p==0&&q==0){if(score[1][i]<8)score[1][i]=8;

if(score[2][i]<8)score[2][i]=8;}if(m==0&&q==0){if(score[0][i]<8)score[0][i]=8;

if(score[2][i]<8)score[2][i]=8;}if(p==0&&m==0){if(score[1][i]<8)score[1][i]=8;

if(score[0][i]<8)score[0][i]=8;}if(m+p+q==-1){if(p==0&&q==0){if(score[1][i]<10)score[1][i]=10;

if(score[2][i]<10)score[2][i]=10;}if(m==0&&q==0){if(score[0][i]<10)score[0][i]=10;

if(score[2][i]<10)score[2][i]=10;}if(p==0&&m==0){if(score[1][i]<10)score[1][i]=10;

if(score[0][i]<10)score[0][i]=10;}if(m+p+q==0){if(m==0&&p==0&&q==0){if(score[0][i]<4)score[0][i]=4;

if(score[1][i]<4)score[1][i]=4;

if(score[2][i]<4)score[2][i]=4;

}/*end竖*/

m=a[0][0];p=a[1][1];q=a[2][2];

if(m+p+q==2){if(m==0){if(score[0][0]<25)score[0][0]=25;}if(p==0){if(score[1][1]<25)score[1][1]=25;}if(q==0){if(score[2][2]<25)score[2][2]=25;}if(m+p+q==-2){if(m==0){if(score[0][0]<50)score[0][0]=50;}if(p==0){if(score[1][1]<50)score[1][1]=50;}if(q==0){if(score[2][2]<50)score[2][2]=50;}if(m+p+q==1){if(p==0&&q==0){if(score[1][1]<8)score[1][1]=8;

if(score[2][2]<8)score[2][2]=8;}if(m==0&&q==0){if(score[0][0]<8)score[0][0]=8;

if(score[2][2]<8)score[2][2]=8;}if(p==0&&m==0){if(score[1][1]<8)score[1][1]=8;

if(score[0][0]<8)score[0][0]=8;}if(m+p+q==-1){if(p==0&&q==0){if(score[1][1]<10)score[1][1]=10;

if(score[0][0]<10)score[0][0]=10;}if(m+p+q==0){if(m==0&&p==0&&q==0){if(score[0][0]<4)score[0][0]=4;

if(score[1][1]<4)score[1][1]=4;

if(score[2][2]<4)score[2][2]=4;}}/*斜扫描*/m=a[0][2];p=a[1][1];q=a[2][0];

if(m+p+q==2){if(m==0){if(score[0][2]<25)score[0][2]=25;}if(p==0){if(score[1][1]<25)score[1][1]=25;}if(q==0){if(score[2][0]<25)score[2][0]=25;}if(m+p+q==-2){if(m==0){if(score[0][2]<50)score[0][2]=50;}if(p==0){if(score[1][1]<50)score[1][1]=50;}if(q==0){if(score[2][0]<50)score[2][0]=50;}if(m+p+q==1){if(p==0&&q==0){if(score[1][1]<8)score[1][1]=8;

if(score[2][0]<8)score[2][0]=8;}if(m==0&&q==0){if(score[2][0]<8)score[2][0]=8;

if(m+p+q==-1){if(p==0&&q==0){if(score[1][1]<10)score[1][1]=10;

if(score[2][0]<10)score[2][0]=10;}if(m==0&&q==0){if(score[0][2]<10)score[0][2]=10;

if(score[2][0]<10)score[2][0]=10;}if(p==0&&m==0){if(score[1][1]<10)score[1][1]=10;

if(score[0][2]<10)score[0][2]=10;}if(m+p+q==0){if(m==0&&p==0&&q==0){if(score[0][2]<4)score[0][2]=4;

if(score[1][1]<4)score[1][1]=4;

if(score[2][0]<4)score[2][0]=4;}

/*斜扫描*/h=k=1;

for(i=0;i<3;i++){for(j=0;j<3;j++){if(score[i][j]>score[h][k]){h=i;k=j;}}}x1=120+100*h;

y1=130+100*k;

circle(x1,y1,20);

setfillstyle(1,3);

floodfill(x1,y1,4);

a[h][k]=-1;

n=1;

for(i=0;i<3;i++){

for(j=0;j<3;j++)

score[i][j]=0;}

returnn;

/*重新开始游戏*/

intxuanzeyouxi(){

key=bioskey(0);

while(key!

=ENTER){

if(key==left){setfillstyle(1,12);floodfill(400,330,2);

setfillstyle(1,14);floodfill(500,330,2);settextstyle(1,0,2);v=1;

if(key==right){setfillstyle(1,12);floodfill(500,330,2);

setfillstyle(1,14);floodfill(400,330,2);v=0;

key=bioskey(0);

for(i=0;i<3;i++){for(j=0;j<3;j++){a[i][j]=0;}

returnv;

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 工程科技 > 能源化工

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2