c井字游戏

/downloads 112/source code/game/49636984 jzgame . rar

还有这个。

井字游戏(Tick-tac-toe game):一种双人游戏,双方轮流掷骰子,当任意一行、一列、一条对角线都是三个相同的骰子时,即为胜利!

/downloads 63/source code/game/57578890 xtkdige . rar

/downloads 76/source code/game/55593407402922602 . rar

还有这个。

一个用C语言写的井字游戏,用Turbo C编译。

# include & ltstdio.h & gt

# include & ltgraphics.h & gt

# include & ltconio.h & gt

# include & ltbios.h & gt

# include & ltalloc.h & gt

# include & ltstdlib.h & gt

#定义x1 150

#定义x2 250

#定义x3 350

#定义x4 450

#定义y1 100

#定义y2 200

#定义y3 300

#定义y4 400

/* 1表示O,2表示X */

void *buf_yuan,*buf_cha,* buf;

FILE * fp

int a[4][4];

int flag = 0;

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

无效总管(无效)

{

int gd=DETECT,GM;

int END = 0;

int i,j,h,kai=0,restart,key

int恒=2,lie = 2;

int temp = 1;

void system initial(void);/*初始化游戏界面*/

虚空四交(int恒,int烈);/*显示要遍历的单元格的边框*/

虚空华(int恒,int列,int型);/*走,也就是画个圈或者十字*/

void显示(int类型);/*显示获胜者*/

void hz(int x,int y,int a,int COL,int b,char * s);/*显示汉字,只能显示中文*/

void电脑(void);/*玩单机游戏时,电脑走*/

void hanzi(int x,int y,char *p,int colour);/*也是汉字,可以中英文显示*/

init graph(& amp;amtgd,& ampamtgm,“”;

if ((fp=fopen("hzk16 "," rb"))==NULL)

{

printf("打不开hzk16,请补充");

getch();

closegraph();

退出(0);

}

clear device();

Hz(220,100,40,2,黄色,“井字”);

setcolor(蓝色);

寒子(400,460,《作者:08号邓永华,04年3班》,蓝);

setcolor(白色);

setfillstyle(SOLID_FILL,白色);

flag = 0;

If(flag==0)/*单人游戏*/

{

圆(195,242,4);

漫填(195,242,白色);

}

Else/*双人游戏*/

{

圆(195,262,4);

漫填(195,262,白色);

}

outtextxy(200,220,"请选择:");

setcolor(红色);

outtextxy(205,240,“玩电脑”);

outtextxy(205,260,“两个人玩”);

韩子(30,350,“游戏描述:双方轮流走,先把三个符号连成一条直线(横、竖、斜)就赢”,绿色);

while(温度)

{

开关(bioskey(0))

{

Case 0x1c0d:/* Enter */

{

temp = 0;

打破;

}

案例0x11b:/*Esc*/

退出(0);

案例0x4800:/* On */

如果(标志==0)

打破;

其他

{

flag = 0;

setcolor(黑色);

setfillstyle(SOLID_FILL,黑色);

圆(195,262,4);

漫填(195,262,黑色);

setcolor(白色);

setfillstyle(SOLID_FILL,白色);

圆(195,242,4);

漫填(195,242,白色);

}

打破;

案例0x5000:/* Under */

if(flag==1)

打破;

其他

{

flag = 1;

/*清除*/

setcolor(黑色);

setfillstyle(SOLID_FILL,黑色);

圆(195,242,4);

漫填(195,242,黑色);

setcolor(白色);

setfillstyle(SOLID_FILL,白色);

圆(195,262,4);

漫填(195,262,白色);

打破;

}

}

}

clear device();

/*开始播放*/

system initial();

而(END!=1)

{

重启= 0;

开关(bioskey(0))/* key */

{

案例0x11b:/*Esc退出*/

END = 1;

打破;

案例0x3920:/*space*/

if(kai==1)

打破;

如果(一个【恒】【烈】)破;

kai = 1;

华(恒,列,1);

a[恒][列]= 1;

if((a[1][1]= = 1 & amp;amt& ampamta[1][2]= = 1 & amp;amt& ampamtA[1][3]==1)/*判断你是否赢了*/

| |(a[2][1]= = 1 & amp;amt& ampamta[2][2]= = 1 & amp;amt& ampamta[2][3]==1)

| |(a[3][1]= = 1 & amp;amt& ampamta[3][2]= = 1 & amp;amt& ampamta[3][3]==1)

| |(a[1][1]= = 1 & amp;amt& ampamta[2][1]= = 1 & amp;amt& ampamta[3][1]==1)

| |(a[1][2]= = 1 & amp;amt& ampamta[2][2]= = 1 & amp;amt& ampamta[3][2]==1)

| |(a[1][3]= = 1 & amp;amt& ampamta[2][3]= = 1 & amp;amt& ampamta[3][3]==1)

| |(a[1][1]= = 1 & amp;amt& ampamta[2][2]= = 1 & amp;amt& ampamta[3][3]==1)

| |(a[1][3]= = 1 & amp;amt& ampamta[2][2]= = 1 & amp;amt& ampamta[3][1]==1))

{

显示(1);

END = 1;

}

如果(!结束)

{

h = 0;

for(I = 1;我& lt4;i++)

for(j = 1;j & lt4;j++)

if(a[i][j])

h++;

如果(h==9)

{

显示器(3);

END = 1;

}

}

if(END==1)

{

outtextxy(260,450,“再玩一次?y/N”);

while(1)

{

key = BIOS key(0);

if(key = = 0x 1579 | | key = = 0x 1559)/* y */的情况

{

END = 0;

重启= 1;

打破;

}

else if((key = = 0x 316e)| |(key = = 0x 314e))/* n case */

打破;

否则继续;

}

}

打破;

案例0x5230:/*0*/

if(kai==2)破;

如果(一个【恒】【烈】)破;

kai = 2;

华(恒,烈,二);

a[恒][列]= 20;

if((a[1][1]= = 20 & amp;amt& ampamta[1][2]= = 20 & amp;amt& ampamtA[1][3]==20)/*判断你是否赢了*/

| |(a[2][1]= = 20 & amp;amt& ampamta[2][2]= = 20 & amp;amt& ampamta[2][3]==20)

| |(a[3][1]= = 20 & amp;amt& ampamta[3][2]= = 20 & amp;amt& ampamta[3][3]==20)

| |(a[1][1]= = 20 & amp;amt& ampamta[2][1]= = 20 & amp;amt& ampamta[3][1]==20)

| |(a[1][2]= = 20 & amp;amt& ampamta[2][2]= = 20 & amp;amt& ampamta[3][2]==20)

| |(a[1][3]= = 20 & amp;amt& ampamta[2][3]= = 20 & amp;amt& ampamta[3][3]==20)

| |(a[1][1]= = 20 & amp;amt& ampamta[2][2]= = 20 & amp;amt& ampamta[3][3]==20)

| |(a[1][3]= = 20 & amp;amt& ampamta[2][2]= = 20 & amp;amt& ampamta[3][1]==20))

{

显示器(2);

END = 1;

}

如果(!结束)

{ h = 0;

for(I = 1;我& lt4;i++)

for(j = 1;j & lt4;j++)

if(a[i][j])

h++;

如果(h==9)

{

显示器(3);

END = 1;

}

}

if(END==1)

{

outtextxy(260,450,“再玩一次?y/N”);

while(1)

{

key = BIOS key(0);

if(key = = 0x 1579 | | key = = 0x 1559)

{

END = 0;

重启= 1;

打破;

}

if(key = = 0x 316e | | key = = 0x 314e)

打破;

否则继续;

}

}

打破;

案例0x4800:

案例0x1177:

恒-;

如果(恒& lt1)

恒= 1;

四角(恒、烈);

打破;

案例0x5000:

案例0x1f73:

恒++;

如果(恒& gt3)

恒= 3;

四角(恒、烈);

打破;

案例0x4b00:

案例0x1e61:

谎言-;

如果(lie & lt1)

lie = 1;

四角(恒、烈);

打破;

案例0x4d00:

案例0x2064:

lie++;

if(lie & gt;3)

lie = 3;

四角(恒、烈);

打破;

}

if(flag = = 0 & amp;amt& ampamtkai = = 1 & amp;amt& ampamt结束!=1。amt& ampamt重启!=1)

{

计算机();

kai = 2;

if((a[1][1]= = 20 & amp;amt& ampamta[1][2]= = 20 & amp;amt& ampamtA[1][3]==20)/*判断你是否赢了*/

| |(a[2][1]= = 20 & amp;amt& ampamta[2][2]= = 20 & amp;amt& ampamta[2][3]==20)

| |(a[3][1]= = 20 & amp;amt& ampamta[3][2]= = 20 & amp;amt& ampamta[3][3]==20)

| |(a[1][1]= = 20 & amp;amt& ampamta[2][1]= = 20 & amp;amt& ampamta[3][1]==20)

| |(a[1][2]= = 20 & amp;amt& ampamta[2][2]= = 20 & amp;amt& ampamta[3][2]==20)

| |(a[1][3]= = 20 & amp;amt& ampamta[2][3]= = 20 & amp;amt& ampamta[3][3]==20)

| |(a[1][1]= = 20 & amp;amt& ampamta[2][2]= = 20 & amp;amt& ampamta[3][3]==20)

| |(a[1][3]= = 20 & amp;amt& ampamta[2][2]= = 20 & amp;amt& ampamta[3][1]==20))

{

显示器(2);

END = 1;

}

如果(!结束)

{ h = 0;

for(I = 1;我& lt4;i++)

for(j = 1;j & lt4;j++)

if(a[i][j])

h++;

如果(h==9)

{

显示器(3);

END = 1;

}

}

if(END==1)

{

outtextxy(260,450,“再玩一次?y/N”);

while(1)

{

key = BIOS key(0);

if(key = = 0x 1579 | | key = = 0x 1559)

{

END = 0;

重启= 1;

打破;

}

if(key = = 0x 316e | | key = = 0x 314e)

打破;

否则继续;

}

}

}

if(restart==1)

{

clear device();

system initial();

kai = 0;

恒= 2;

lie = 2;

}

}

免费(buf _元);

免费(buf _ cha);

免费(buf);

fclose(FP);

closegraph();

}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

void SystemInitial(无效)

{

void hz(int x,int y,int a,int COL,int b,char * s);

虚空四交(int恒,int烈);

int size,I,j;

for(I = 1;我& lt4;i++)

for(j = 1;j & lt4;j++)

a[I][j]= 0;

四角(2,2);

Hz(240,30,40,2,黄色,“井字”);

setcolor(绿色);

outtextxy(10,200,“1P”);

setcolor(白色);

outtextxy(10,220," up:w ");

outtextxy(10,240," down:s ");

outtextxy(10,260," left:a ");

outtextxy(10,280,"右:d ");

outtextxy(10,300," fill:space ");

outtextxy(10,320,"退出:Esc ");

if(flag==1)

{

setcolor(绿色);

outtextxy(520,200,“2P”);

setcolor(白色);

outtextxy(520,220," up:");

outtextxy(520,240," down:");

outtextxy(520,260," left:");

outtextxy(520,280,"右:");

outtextxy(520,300," fill:0 ");

outtextxy(520,320," exit:Esc ");

hz(585,220,25,1,白色,“↑”);

hz(585,240,25,1,白色,“↓”;

hz(585,260,25,1,白色,“↓”;

hz(585,280,25,1,白色,"→");

}

行(x1,y1,x1,y4);

线(x1,y1,x4,y 1);

线(x4,y1,x4,y4);

行(x1,y4,x4,y4);

线(x2,y1,x2,y4);/*舒*/

线(x3,y1,x3,y4);

行(x1,y2,x4,y2);/*恒*/

行(x1,y3,x4,y3);

圆((x2+x3)/2,(y2+y3)/2,(y3-y2)/2-10);/*花园*/

size = imagesize((x2+x3)/2-(y3-y2)/2+9,(y2+y3)/2-(y3-y2)/2+9,(x2+x3)/2+(y3-y2)/2-9,(y2+y3)/2+(y3-y2)/2-9);

buf _ yuan = malloc(size);

如果(!buf_yuan)出口(1);

getimage((x2+x3)/2-(y3-y2)/2+9,(y2+y3)/2-(y3-y2)/2+9,(x2+x3)/2+(y3-y2)/2-9,(y2+y3)/2+(y3-y2)/2-9,buf _ yuan);

setcolor(黑色);

圆((x2+x3)/2,(y2+y3)/2,(y3-y2)/2-10);

setcolor(白色);/*花茶*/

线(x2+10,y2+10,x3-10,y3-10);

线(x2+10,y3-10,x3-10,y2+10);

buf _ cha = malloc(size);

getimage((x2+x3)/2-(y3-y2)/2+9,(y2+y3)/2-(y3-y2)/2+9,(x2+x3)/2+(y3-y2)/2-9,(y2+y3)/2+(y3-y2)/2-9,buf _ cha);

setcolor(黑色);

线(x2+10,y2+10,x3-10,y3-10);

线(x2+10,y3-10,x3-10,y2+10);

}

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

虚空四角

{

int a1,b1,a2,B2;

void花黑(void);/*用黑色覆盖原来显示为白色的边框*/

花黑();

setcolor(白色);

开关(恒)

{

案例1:

b 1 = y 1;

b2 = y2

打破;

案例二:

b 1 = y2;

b2 = y3

打破;

案例三:

b 1 = y3;

b2 = y4

打破;

}

开关(谎言)

{

案例1:

a 1 = x 1;

a2 = x2

打破;

案例二:

a 1 = x2;

a2 = x3

打破;

案例三:

a 1 = x3;

a2 = x4

打破;

}

线(a1+3,b1+3,a1+30,b 1+3);

线(a1+3,b1+3,a1+3,b 1+30);

线(a1+3,b2-3,a1+3,B2-30);

线(a1+3,b2-3,a1+30,B2-3);

线(a2-30,b1+3,a2-3,b 1+3);

线(a2-3,b1+3,a2-3,b 1+30);

线(a2-30,b2-3,a2-3,B2-3);

线(a2-3,b2-30,a2-3,B2-3);

}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

虚空华黑(虚空)

{

int i,j,a1,b1,a2,B2;

setcolor(黑色);

for(I = 1;我& lt4;i++)

for(j = 1;j & lt4;j++)

{

开关(一)

{

案例1:

b 1 = y 1;

b2 = y2

打破;

案例二:

b 1 = y2;

b2 = y3

打破;

案例三:

b 1 = y3;

b2 = y4

打破;

}

开关(j)

{

案例1:

a 1 = x 1;

a2 = x2

打破;

案例二:

a 1 = x2;

a2 = x3

打破;

案例三:

a 1 = x3;

a2 = x4

打破;

}

线(a1+3,b1+3,a1+30,b 1+3);

线(a1+3,b1+3,a1+3,b 1+30);

线(a1+3,b2-3,a1+3,B2-30);

线(a1+3,b2-3,a1+30,B2-3);

线(a2-30,b1+3,a2-3,b 1+3);

线(a2-3,b1+3,a2-3,b 1+30);

线(a2-30,b2-3,a2-3,B2-3);

线(a2-3,b2-30,a2-3,B2-3);

}

}

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

void Hua (int heng,int lie,int type)/* type的值对于圆是1,对于十字*/是2

{

int x,y;

setcolor(白色);

开关(谎言)

{

案例1:

x =(x 1+x2)/2-(x2-x 1)/2+9;

打破;

案例二:

x =(x2+x3)/2-(x3-x2)/2+9;

打破;

案例三:

x =(x3+x4)/2-(x4-x3)/2+9;

打破;

}

开关(恒)

{

案例1:

y =(y 1+y2)/2-(y2-y 1)/2+9;

打破;

案例二:

y =(y2+y3)/2-(y3-y2)/2+9;

打破;

案例三:

y =(y3+y4)/2-(y4-y3)/2+9;

打破;

}

开关(类型)

{

案例1:

buf = buf _元;

a[恒][列]= 1;

打破;

案例二:

buf = buf _ cha

a[恒][列]= 20;

打破;

}

putimage(x,y,buf,COPY _ PUT);

}

/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

空显示(int类型)

{

if(type==1)

outtextxy(270,430,“O赢”);

如果(类型==2)

outtextxy(270,430,“X赢”);

如果(类型==3)

outtextxy(270,430," draw ");

}

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

Voidhz (int x,int y,int a,int col,int b,char * s)/* x,y是显示的坐标,a是单词之间的间隔,b是单词的大小,s是指向显示的汉字的指针*/

{

int行;

充电缓冲器[32];

寄存器m,n,i1,j1,k;

无符号字符qh,wh;

无符号长偏移量;

ROW = COL

while(*s)

{

qh = *(s)-0xa 0;/*汉字位置码*/

wh = *(s+1)-0xa 0;

offset =(94 *(qh-1)+(wh-1))* 32L;/*计算字体中汉字的偏移量*/

fseek(fp,offset,SEEK _ SET);

fread(buffer,32,1,FP);/*取出汉字的32字节点阵字体,存入缓冲区(一个汉字)*/

for(I 1 = 0;I 1 & lt;16;I1++)/*在屏幕上逐位打印一个32位字节的点阵(1:打印,0:不打印),显示汉字*/

for(n = 0;n & lt排;n++)

for(j 1 = 0;j 1 & lt;2;j1++)

for(k = 0;k & lt8;k++)

for(m = 0;m & ltCOLm++)

if(((buffer[I 1 * 2+j 1]>;& gt(7-k))& amp;amt0x1)!=空)

put pixel(x+8 * j 1 * COL+k * COL+m,y+i1*ROW+n,b);

s+= 2;/*因为一个汉字内码占两个字节,所以S必须加2*/

x+= a;

}

}

/**************************************************************************/

无效计算机(无效)

{

int i,j;

for(I = 1;我& lt4;I++)/*横向判断*/

如果(a[I][1]+a[I][2]+a[I][3]= = 40)

for(j = 1;j & lt4;j++)

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

{

华(I,j,2);

返回;

}

for(I = 1;我& lt4;I++)/*横向判断*/

如果(a[I][1]+a[I][2]+a[I][3]= = 2)

for(j = 1;j & lt4;j++)

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

{

华(I,j,2);

返回;

}

for(I = 1;我& lt4;I++)/*垂直判断*/

if(a[1][I]+a[2][I]+a[3][I]= = 40)

{

for(j = 1;j & lt4;j++)

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

{

华(j,I,2);

返回;

}

}

for(I = 1;我& lt4;I++)/*垂直判断*/

if(a[1][I]+a[2][I]+a[3][I]= = 2)

for(j = 1;j & lt4;j++)

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

{

华(j,I,2);

返回;

}

if(A[1][1]+A[2][2]+A[3][3]= = 40)/*从左上角到右下角判断*/

{

for(I = 1;我& lt4;i++)

if(a[i][i]==0)

{

华(我,我,2);

返回;

}

}

else if(a[1][1]+a[2][2]+a[3][3]= = 2)

for(I = 1;我& lt4;i++)

if(a[i][i]==0)

{

华(我,我,2);

返回;

}

if(a[3][1]+a[2][2]+a[1][3]= = 40)/*从右上角到左下角判断*/

{

for(I = 1;我& lt4;i++)

如果(a[i][4-i]==0)

{

华(I,4-i,2);

返回;

}

}

else if(a[3][1]+a[2][2]+a[1][3]= = 2)

for(I = 1;我& lt4;i++)

如果(a[i][4-i]==0)

{

华(I,4-i,2);

返回;

}

for(I = 1;我& lt4;I++)/*随意填空*/

for(j = 1;j & lt4;j++)

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

{

华(I,j,2);

返回;

}

}

void汉字(int x,int y,char *p,int colour)

{

FILE * fp

充电缓冲器[32];

寄存器I,j,k;

无符号字符qh,wh;

无符号长位置;

if((fp=fopen("hzk16 "," rb"))==NULL)

{

printf("打不开hzk16!");

getch();

退出(0);

}

while(*p)

{

if(((无符号字符)* p & gt= 0xa 1 & amp;amt& ampamt(无符号字符)* p & lt= 0x Fe)& amp;amt& ampamt((无符号字符)*(p+1)>= 0xal & ampamt& ampamt(无符号字符)*(p+1)& lt;=0xfe))

{

qh = * p-0xa 0;

wh = *(p+1)-0xa 0;

位置=(94 *(qh-1)+(wh-1))* 32L;

fseek(fp,location,SEEK _ SET);

fread(buffer,32,1,FP);

for(I = 0;我& lt16;i++)

for(j = 0;j & lt2;j++)

for(k = 0;k & lt8;k++)

if(((buffer[I * 2+j]& gt;& gt(7-k))& amp;amt0x1)!=空)

putpixel(x+8*j+k,y+i,colour);

p+= 2;

x+= 18;

if(x & gt;600)

{

x = 15;y+= 18;

}

}

其他

{

char q[2];

moveto(x,y);

* q = * p;

*(q+1)= ' \ 0 ';

outtextxy(x,y+4,q);

x+= 8+1;p++;

}

}

fclose(FP);

}

它们是C语言的井字游戏。请参考它们。