五子棋大家对战C语言代码

# includestdio.h

# includestring.h

# includestdlib.h

#定义SPA 0

#定义男人1

# define COM 2 /*空位置设置为0,播放器下位置设置为1,电脑下位置设置为2 */

Int潘琪求用C语言写的五子棋程序。 # includestdio.h

#includestdlib.h

#includegraphics.h

#includebios.h

#includeconio.h

#定义左0x4b00

#定义右0x4d00

#向下定义0x5000

#定义高达0x4800

#定义ESC 0x011b

#定义空间0x3920

#定义BILI 20

#定义JZ 4

#定义JS 3

#定义N 19

int box[N][N];

int step_x,step _ y;

int键;

int flag = 1;

void draw _ box();

void draw_cicle(int x,int y,int color);

void change();

void judgewho(int x,int y);

void judge key();

int judger result(int x,int y);

void attention in();

忽略注意力()

{

char ch

窗口(1,1,80,25);

textbackground(浅蓝色);

textcolor(黄色);

clr SCR();

gotoxy(15,2);

Printf("游戏操作规则:");

gotoxy(15,4);

printf("玩法:");

gotoxy(15,6);

Printf("1,按左、右、上箭头键移动棋子");

gotoxy(15,8);

printf("1。按左、右、上、下键移动棋子”);

gotoxy(15,10);

Printf("2,按空格确定棋子");

gotoxy(15,12);

printf("2。按空格键放置棋子”);

gotoxy(15,14);

Printf("3,禁止按棋盘外空格");

gotoxy(15,16);

printf("3。不要按棋盘外的空格”);

gotoxy(15,18);

Printf("你接受以上游戏规则吗(Y/N)");

gotoxy(15,20);

printf("你接受以上玩法吗?[是/否]:);

while(1)

{

gotoxy(60,20);

ch = getche();

if(ch=='Y'||ch=='y ')

打破;

else if(ch=='N'||ch=='n ')

{

窗口(1,1,80,25);

textbackground(黑色);

textcolor(浅灰色);

clr SCR();

退出(0);

}

gotoxy(51,12);

printf(" ");

}

}

void draw_box()

{

int x1,x2,y1,y2;

setbkcolor(浅蓝色);

setcolor(黄色);

gotoxy(7,2);

printf("左,右,上,下键移动,空格放置,ESC-退出。");

for(x1=1,y1=1,y2 = 18x1 = 18x1)

行((x1 JZ)*BILI,(y1 JS)*BILI,(x1 JZ)*BILI,(y2 JS)* BILI);

for(x1=1,y1=1,x2 = 18y1 = 18y1)

行((x1 JZ)*BILI,(y1 JS)*BILI,(x2 JZ)*BILI,(y1 JS)* BILI);

for(x1 = 1;x1 = 18x1)

for(y1 = 1;y1 = 18y1)

box[x1][y1]= 0;

}

void draw_circle(int x,int y,int color)

{

setcolor(颜色);

setlinestyle(SOLID_LINE,0,1);

x =(x JZ)* BILI;

y =(y JS)* BILI;

circle(x,y,8);

}

void judgekey()

{

int I;

int j;

开关(钥匙)

{

案例左侧:

如果(步骤x-10)

打破;

其他

{

for(i=step_x-1,j = step _ y;I = 1;我-)

if(框[i][j]==0)

{

draw_circle(step_x,step_y,浅蓝色);

打破;

}

如果(i1)断开;

step _ x = I;

judgewho(step_x,step _ y);

打破;

}

案例权利:

如果(步骤x 118)

打破;

其他

{

for(i=step_x 1,j = step _ y;i = 18我)

if(框[i][j]==0)

{

draw_circle(step_x,step_y,浅蓝色);

打破;

}

如果(i18)断开;

step _ x = I;

judgewho(step_x,step _ y);

打破;

}

案例向下:

if((step _ y ^ 1)18)

打破;

其他

{

for(i=step_x,j = step _ y ^ 1;j = 18j)

if(框[i][j]==0)

{

draw_circle(step_x,step_y,浅蓝色);

打破;

}

如果(j18)断开;

step _ y = j;

judgewho(step_x,step _ y);

打破;

}

案例向上:

if((step_y-1)0)

打破;

其他

{

for(i=step_x,j = step _ y-1;j = 1;j -)

if(框[i][j]==0)

{

draw_circle(step_x,step_y,浅蓝色);

打破;

}

如果(j1)断开;

step _ y = j;

judgewho(step_x,step _ y);

打破;

}

案例ESC:

打破;

案例空间:

if(步骤x=1步骤x = 18步骤y=1步骤y=18)

{

if(框[步骤x][步骤y]==0)

{

box[step _ x][step _ y]=标志;

if(判断结果(步骤x,步骤y)==1)

{

声音(1000);

延时(1000);

nosound();

gotoxy(30,4);

if(flag==1)

{

setbkcolor(蓝色);

clear device();

setviewport(100,100,540,380,1);

/*定义图形窗口*/

setfillstyle(1,2);

/*绿色用实心填充*/

setcolor(黄色);

矩形(0,0,439,279);

洪水填充(50,50,14);

set color(12);

settextstyle(1,0,5);

/*三重笔画字体,横向?5次*/

outtextxy(20,20,“白棋赢了!”);

set color(15);

settextstyle(3,0,5);

/*无衬线字体,水平放大5倍*/

outtextxy(120,120,“白棋赢了!”);

set color(14);

settextstyle(2,0,8);

getch();

closegraph();

退出(0);

}

if(flag==2)

{

setbkcolor(蓝色);

clear device();

setviewport(100,100,540,380,1);

/*定义图形窗口*/

setfillstyle(1,2);

/*绿色用实心填充*/

setcolor(黄色);

矩形(0,0,439,279);

洪水填充(50,50,14);

set color(12);

settextstyle(1,0,8);

/*三笔画字体,水平放大8倍*/

outtextxy(20,20,“红色胜利!”);

set color(15);

settextstyle(3,0,5);

/*无衬线字体,水平放大5倍*/

outtextxy(120,120,“红色胜利!”);

set color(14);

settextstyle(2,0,8);

getch();

closegraph();

退出(0);

}

}

change();

打破;

}

}

其他

打破;

}

}

无效更改()

{

if(flag==1)

flag = 2;

其他

flag = 1;

}

void judgewho(int x,int y)

{

if(flag==1)

draw_circle(x,y,15);

if(flag==2)

draw_circle(x,y,4);

}

int judger result(int x,int y)

{

int j,k,n1,N2;

while(1)

{

n1 = 0;

N2 = 0;

/*向左水平计数*/

for(j=x,k = y;j = 1;j -)

{

if(框[j][k]= =标志)

n1;

其他

打破;

}

/*向右水平计数*/

for(j=x,k = y;j = 18j)

{

if(框[j][k]= =标志)

N2;

其他

打破;

}

if(n1 n2-1=5)

{

返回(1);

打破;

}

/*垂直向上*/

n1 = 0;

N2 = 0;

for(j=x,k = y;k = 1;k -)

{

if(框[j][k]= =标志)

n1;

其他

打破;

}

/*垂直向下计数*/

for(j=x,k = y;k = 18k)

{

if(框[j][k]= =标志)

N2;

其他

打破;

}

if(n1 n2-1=5)

{

返回(1);

打破;

}

/*左上角的数字*/

n1 = 0;

N2 = 0;

for(j=x,k = y;j=1,k = 1;j -,k -)

{

if(框[j][k]= =标志)

n1;

其他

打破;

}

/*右下方的数字*/

for(j=x,k = y;j=18,k = 18j,k)

{

if(框[j][k]= =标志)

N2;

其他

打破;

}

if(n1 n2-1=5)

{

返回(1);

打破;

}

/*右上方的数字*/

n1 = 0;

N2 = 0;

for(j=x,k = y;j=18,k = 1;j,k -)

{

if(框[j][k]= =标志)

n1;

其他

打破;

}

/*左下方的数字*/

for(j=x,k = y;j=1,k = 18j -,k)

{

if(框[j][k]= =标志)

N2;

其他

打破;

}

if(n1 n2-1=5)

{

返回(1);

打破;

}

return(0);

打破;

}

}

void main()

{

int gdriver=VGA,gmode = VGAHI

clr SCR();

注意();

initgraph(gdriver,gmode," c:\ \ TC ");

/* set write mode(XOR _ PUT);*/

flag = 1;

draw _ box();

{

step _ x = 0;

step _ y = 0;

/*draw_circle(step_x,step_y,8);*/

judgewho(步骤x-1,步骤y-1);

{

while(bios key(1)= = 0);

key = bios key(0);

judge key();

}

而(键!=SPACEkey!= ESC);

}

而(键!= ESC);

closegraph();

}

相关文章

发表新评论