小游戏编程代码内容

tl.h & gt

# include & ltstdlib.h & gt

# include & ltconio.h & gt

# include & ltgraphics.h & gt

#定义HH '0 '

#定义N 6

int Q = 0;

char键;

int fine = 1;

int A=0,B = 0;

char s[N][N],m[N][N];

void *球;

int maxx

无符号int大小;

正在加载()

{ int z = 1;

白色(z)

{ if(z & gt;77)破;

printf("<);

延时(5000);

z++;

}

延迟(2000年);

clear device();

}

无符号字符Get_Ascii_Key(void)

{

if(bioskey(1))

return(BIOS key(0));

否则返回(0);

}

int测试_ Ascii _密钥(int ascii)

{

if(Get_Ascii_Key()==ascii)

返回(1);

其他

return(0);

}

void tu(){

maxx = get maxx();

size=imagesize(210,390,450,420);

ball=malloc(大小);

setfillstyle(1,10);

吧(160,170,473,253);

setfillstyle(1,9);

吧(163,173,470,250);

set color(13);

outtextxy(200,200,“欢迎来到黑& amp白棋”);

set color(14);

outtextxy(250,220,“开发者:吴思远”);

outtextxy(290,240,“2002.8”);

outtextxy(210,390,"按任意键继续...");

getimage(210,390,450,420,球);

而(!kbhit()){

putimage(210,390,球,XOR _ PUT);

延时(30000);

}

clear device();

}

void sou(void){

}

作废打印()

{ int i=0,j = 30

set color(11);

outtextxy(35,20," 0 1 2 3 4 5 ");

outtextxy(14,50," 0 ");

outtextxy(14,100,“1”);

outtextxy(14,150," 2 ");

out textxy(14200," 3 ");

outtextxy(14,250," 4 ");

out textxy(14300," 5 ");

setbkcolor(0);

setlinestyle(SOLID_LINE,0,2);

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

{ setcolor(绿色);

线(j,30,j,330);

j+= 50;

}

j = 30

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

{ setcolor(绿色);

线(30,j,330,j);

j+= 50;

}

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

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

{ if(s[i][j]=='o ')

{

setcolor(白色);

圆(55+j*50,55+i*50,15);

}

else if(s[i][j]=='x ')

{ setcolor(红色);

圆(55+j*50,55+i*50,15);}

}

}

内部校准(字符z)

{ int * p = 0;

int num=0,I,j;

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

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

if(s[I][j]= = z)num++;

p = & ampnum

return(* p);

}

无效保存()

{int i,j;

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

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

m[I][j]= s[I][j];

}

无效载荷()

{ int i,j;

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

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

s[I][j]= m[I][j];

}

snew(int x,int y,char z1,char z2)

{int i,j,a;int can[]={0,0,0,0,0,0,0,0},k[N * N];

if(s[x][y-1]= = z 1 & amp;& amp(y-1)>=0)

{

I = 0;

while(我& lty)

{

if(s[x][I]= = z2){ can[1]= 1;打破;}

i++;

}

}

if(s[x][y+1]==z1)

{

I = y+2;

while(我& ltn)

{

if(s[x][I]= = z2){ can[2]= 1;打破;}

i++;

}

}

if(s[x-1][y]= = z 1 & amp;& amp(x-1)>=0)

{

I = 0;

while(我& ltx)

{

if(s[I][y]= = z2){ can[3]= 1;打破;}

i++;

}

}

if(s[x+1][y]==z1)

{ I = x+2;

while(我& ltn)

{

if(s[I][y]= = z2){ can[4]= 1;打破;}

i++;

}

}

if(s[x-1][y+1]= = z 1 & amp;& amp(x-1)>=0)

{ I = 2;

while(y+I & lt;N & amp& amp(x-I & gt;=0))

{ if(s[x-I][y+I]= = z2){ can[5]= 1;打破;}

i++;

}

}

if(s[x+1][y-1]= = z 1 & amp;& amp(y-1)>=0)

{ I = 2;

while(我& ltN & amp& amp(y-I & gt;=0))

{if(s[x+i][y-i]==z2)

{ can[6]= 1;打破;}

i++;

}

}

if(s[x-1][y-1]= = z 1 & amp;& amp(x-1)*(y-1)>=0)

{ I = 2;

while(x-I & gt;= 0 & amp& ampy-I & gt;=0)

{if(s[x-i][y-i]==z2)

{ can[7]= 1;

打破;}

i++;

}

}

if(s[x+1][y+1]= = z 1)

{ I = 2;

while(I+x & lt;n)

{if(s[x+i][y+i]==z2)

{ can[8]= 1;

打破;}

i++;

}

}

for(i=1,j = 0;我& lt=8;i++)

if(can[I]= = 0)j++;

if(j = = 8 & amp;& ampQ==1)

{printf("错误!");

退出(1);}

else if(j!= 8)s[x][y]= z2;

if(can[1]==1)

{ I = 1;

while(s[x][y-i]==z1)

{ s[x][y-I]= z2;

i++;

}

can[1]= 0;

}

if(can[2]==1)

{ I = 1;

while(s[x][y+i]==z1)

{ s[x][y+I]= z2;

i++;

}

can[2]= 0;

}

if(can[3]==1)

{ I = 1;

while(s[x-i][y]==z1)

{ s[x-I][y]= z2;

i++;

}

can[3]= 0;

}

if(can[4]==1)

{ I = 1;

while(s[x+i][y]==z1)

{ s[x+I][y]= z2;

i++;

}

can[4]= 0;

}

if(can[5]==1)

{ I = 1;

while(s[x-i][y+i]==z1)

{ s[x-I][y+I]= z2;

i++;

}

can[5]= 0;

}

if(can[6]==1)

{ I = 1;

while(s[x+i][y-i]==z1)

{ s[x+I][y-I]= z2;

i++;

}

can[6]= 0;

}

if(can[7]==1)

{ I = 1;

while(s[x-i][y-i]==z1)

{ s[x-I][y-I]= z2;

i++;

}

can[7]= 0;

}

if(can[8]==1)

{ I = 1;

while(s[x+i][y+i]==z1)

{ s[x+I][y+I]= z2;

i++;

}

can[8]= 0;

}

} /* snew */

void one()

{ int a,b;char g = ' o

load();

set color(15);

printf(" \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n ";

printf("\n要退出游戏,请按“q”键。\ n ");

print();

printf("请输入x (0到5):");

while(1){

a = Get _ Ascii _ Key();

if(a = = 113 | | a = = 81){

printf("\nQuit?(y或n)");

while(1)

{

if(Test _ Ascii _ Key(89)| | Test _ Ascii _ Key(121))

退出(0);

else if(Test _ Ascii _ Key(110)| | Test _ Ascii _ Key(78))

{ printf(" \ n \ t欢迎返回游戏!\ n ");打破;}

}}

如果(a & gt= 48 & amp& ampa & lt=53){printf("\tGood!x有get!\ n ");

打破;}

}

a = a-48;

printf("请输入y (0到5):");

while(1){

b = Get _ Ascii _ Key();

if(b = = 113 | | b = = 81)

{

printf("\nQuit?(Y或Y)");

while(1)

{

if(Test _ Ascii _ Key(89)| | Test _ Ascii _ Key(121))

退出(0);

else if(Test _ Ascii _ Key(110)| | Test _ Ascii _ Key(78))

打破;

}}

如果(b & gt= 48 & amp& ampa & lt=53){printf("\tGood!y有get!”);打破;}

}

b = b-48;

q = 1;

snew(a,b,' x ',' o ');

q = 0;

save();

a =卡(克);

b = cal(' x ');

/* printf("\t\t\t\t\t\t\rA=%d,B=%d ",A,B);*/

}/* one */

无效搜索()

{

int i,j,r = 0;

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

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

if(s[i][j]==HH)

r++;

if(r = = 0)fine = 0;

}

void two()

{ char h = ' xint row[N*N],col[N * N];

int a=1,ii,j,t,t1,k[N * N];

load();

for(ii = 0;ii & ltn;ii++)

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

if(s[ii][j]==HH)

{

行[a]= ii;

col[a]= j;

a++;

}

/*右空格*/

for(ii = 1;ii & lta;ii++)

{

load();/*二*/

snew(row[ii],col[ii],' o ',' x ');

k[ii]= cal(h);

}

t = k[1];

ii-;

t 1 = ii;

而(二)

{

if(t & lt;=k[ii])

{ t = k[ii];t 1 = ii;}

ii-;

}

a = t 1;

a = cal(' o ');

b = t;

load();

snew(行[a],列[a],' o ',' x ');

save();

clear device();

printf("\n\n\t\t\t\t\t计算机位于:%d,%d ",行[a],列[a])。

}

主()

{ int i,j;

int gd=DETECT,GM;

clr SCR();

init graph(& amp;gd,& ampgm," d:\ \ TC \ \ bgi ");

setbkcolor(黑色);

tu();

sou();

setbkcolor(0);

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

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

s[I][j]= ' 0 ';

s[2][2]= s[3][3]= ' x ';

s[2][3]= s[3][2]= ' o ';

save();

正在加载();

clear device();

while(好的)

{

print();

one();

二();

search();

if(key = = 113 | | key = = 81)

{

printf("\nQuit?(Y或Y)");

而(!Test_Ascii_Key(89)和amp& amp!test _ Ascii _ Key(121));

打破;

}

}

如果(A & gtB)outtextxy(400,200,“你赢了!”);

else if(A & lt;B)outtextxy(400,200,“我赢了!”);

else outtextxy(400,200,“平局!”);

printf("\n你:%d我:%d ",A,B);

getch();

}