c语言怎么做应用程序或游戏啊?

2024-11-21 23:16:47
推荐回答(1个)
回答1:

C语言做游戏

点灯游戏(把灯都打开变黄):
#include
#include
#include
#include
int j[8][6][6]={
0,0,0,0,0,0,0,1,1,0,1,1,0,1,0,1,0,1,0,0,1,1,1,0,0,1,0,1,0,1,0,1,1,0,1,1,
0,0,0,0,0,0,0,0,1,0,1,0,0,1,1,0,1,1,0,0,1,0,1,0,0,1,0,1,0,1,0,1,0,1,0,1,
0,0,0,0,0,0,0,1,1,0,1,1,0,0,0,0,0,0,0,1,1,0,1,1,0,0,0,0,0,1,0,1,1,0,0,0,
0,0,0,0,0,0,0,1,0,0,0,1,0,1,1,0,1,1,0,0,0,1,0,0,0,1,0,1,0,0,0,1,0,1,1,0,
0,0,0,0,0,0,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,1,1,
0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,1,1,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,1,1,1,1,1,0,0,1,1,1,0,0,0,0,0,0,0
},x,y,s,i,h=0,r=0,n;
pr(int u)
{ int g,f;
for (g=1;g<=5;g++)
for (f=1;f<=5;f++)
if (j[u][g][f]==1)
{gotoxy(f,g); textcolor(1); putch('o');}
else {gotoxy(f,g); textcolor(14); putch('o');}
}
hkg(int t,int y)
{ if (j[h][t][y]==1) {j[h][t][y]=0;}
else {j[h][t][y]=1;}
}
kg()
{ int e,r;
hkg(y,x); hkg(y-1,x); hkg(y,x+1); hkg(y+1,x); hkg(y,x-1); pr(h);
}
inkey()
{ char o;
if (kbhit()) {
o=getch();
if (o==27) {exit(0);}
if (o==13) {
kg(); r++;
gotoxy(7,5); printf("Bu Shu: %d",r);
if (r>=299) {over(); getch(); exit(0);}
}
if (o==0) {
o=getch();
if (o==72&&y>1) {y--;}
if (o==77&&x<5) {x++;}
if (o==80&&y<5) {y++;}
if (o==75&&x>1) {x--;}
}
}
}
test()
{ int o,p,k=0;
for (o=1;o<=5;o++)
for (p=1;p<=5;p++)
if (j[h][o][p]==1) {k=1;}
if (k==0)
{gotoxy(7,3); printf("Ni Ying Le! An Jian Ji Xu."); getch(); h++; pr(h);
gotoxy(7,3); printf(" ");
textcolor(10); gotoxy(3,7); printf("Di %d Guan",h+1);
}
}
over()
{ int v,b;
for (v=1;v<=24;v++)
for (b=1;b<=40;b++)
{gotoxy(b,v); textcolor(v); putch(219); delay(1000);}
for (v=1;v<=40;v++)
for (b=1;b<=24;b++)
{gotoxy(v,b); textcolor(v); putch(219); delay(1000);}
gotoxy(20,12); printf("Ni Shu Le!");
}
zai()
{ int g,h,y; gotoxy(15,10); printf("Zai Ru......");
gotoxy(15,15); printf("Zai Ru : Dong Hua ");
for (g=10;g<=15;g++)
{gotoxy(g,12); textcolor(2); putch(219);
for (h=1;h<=5;h++) delay(g*10000000);
gotoxy(19,17); printf("%d%",(g-10)*5);}
gotoxy(15,15); printf("Zai Ru : Di Tu ");
for (g=16;g<=25;g++)
{gotoxy(g,12); textcolor(2); putch(219);
for (h=1;h<=5;h++) delay(g*10000000);
gotoxy(19,17); printf("%d%",(g-10)*5);}
gotoxy(15,15); printf("Zai Ru : Tu Xing He Zi Ti");
for (g=26;g<=30;g++)
{gotoxy(g,12); textcolor(2); putch(219);
for (h=1;h<=5;h++) delay(g*10000000);
gotoxy(19,17); printf("%d%",(g-10)*5);}
for (y=1;y<=5;y++) delay(10000);
}
main()
{ textmode(C40); randomize(); clrscr(); zai(); clrscr(); textcolor(10);
gotoxy(7,5); printf("Bu Shu: %d",0);
gotoxy(3,7); printf("Di %d Guan",h+1);
for (i=1;i<=n;i++) {
do {x=rand()%5+1; y=rand()%5+1;} while (j[h][y][x]==1);
j[h][y][x]=1;
} pr(h); x=1; y=1;
while (1)
{ inkey(); gotoxy(x,y); test();
}
getch();
}

作者: 54qiuwenda

2008-7-26 12:17 回复此发言

--------------------------------------------------------------------------------

3 回复:C语言做游戏
走迷宫(用工具走到*):
#include
#include
#include
#include
main()
{ int map[20][20]={1,1,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
1,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,7,
1,0,1,0,0,0,0,0,0,0,0,1,1,1,1,0,1,1,0,7,
1,0,1,1,1,1,3,3,1,1,0,1,0,0,1,0,0,1,0,7,
1,0,0,0,1,2,4,2,0,1,0,1,1,0,1,0,0,1,1,7,
1,0,0,0,1,2,1,2,1,1,0,0,1,0,1,2,1,1,2,7,
1,0,1,1,1,0,1,2,2,2,2,1,1,0,2,2,1,2,2,7,
1,0,1,0,0,0,1,2,1,2,2,1,1,0,1,2,2,2,2,7,
1,0,1,1,1,0,1,2,1,2,2,1,0,0,1,1,2,1,2,7,
1,0,0,0,1,0,1,2,1,2,2,1,0,1,1,0,2,1,2,7,
1,0,1,0,0,0,1,2,1,1,0,1,0,0,0,0,2,1,2,7,
1,0,1,1,1,1,1,2,2,3,0,1,1,1,1,2,2,1,2,7,
1,0,0,0,2,2,2,2,8,1,0,0,1,2,2,2,1,1,2,7,
1,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,2,7,
1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,1,2,7,
1,2,1,1,1,1,0,0,1,1,1,1,2,2,1,2,2,2,2,7,
1,2,1,6,0,1,0,0,0,0,0,2,2,2,1,2,1,1,1,7,
1,2,1,1,5,1,1,1,1,1,1,2,2,2,1,2,1,2,0,7,
1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,0,9,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
,x,y,q,w,
z[5][2]={{-1,0},{0,1},{1,0},{0,-1},{0,0}},l=4,s=0,d=0,j,i,u=0;
char o;
textmode(C40); randomize(); q=2; w=2; clrscr();
while (1) {
gotoxy(22,3); printf("D: ChuanQiang");
gotoxy(22,4); printf("(CrossWall)");
gotoxy(22,6); putch(219); printf(": QiangBi(Wall)");
gotoxy(22,8); printf("=: Shui(Water)");
gotoxy(22,10); printf("F: ShuiShang");
gotoxy(22,11); printf("FeiXing(FlyOn");
gotoxy(22,12); printf("Water)");
gotoxy(22,14); printf("/: Men(Door)");
gotoxy(22,16); printf("*: BaoZang");
gotoxy(22,17); printf("(Treasure)");
gotoxy(22,19); printf("Esc:TuiChu(Exit)");
for (y=0;y<20;y++) {
for (x=0;x<20;x++) {
if (map[y][x]==1||map[y][x]==7) {gotoxy(x+1,y+1); putch(219);}
if (map[y][x]==9) {gotoxy(x+1,y+1); putch('*');}
if (map[y][x]==3) {gotoxy(x+1,y+1); putch(219);}
if (map[y][x]==2) {gotoxy(x+1,y+1); putch('=');}
if (map[y][x]==5) {gotoxy(x+1,y+1); putch('/');}
if (map[y][x]==8) {gotoxy(x+1,y+1); putch('8');}
if (map[y][x]==4) {gotoxy(x+1,y+1); putch('F');}
if (map[y][x]==6) {gotoxy(x+1,y+1); putch('D');}
}
}
if (kbhit()) {
o=getch();
if (o==27) {exit(0);}
if (o==72) {l=0;}
if (o==77) {l=1;}
if (o==80) {l=2;}
if (o==75) {l=3;}
j=map[q-1+z[l][0]][w-1+z[l][1]];
if (j!=0&&j!=4&&j!=8&&j!=3&&j!=s*2&&j!=9&&j!=6&&j!=u*1&&j!=7)
{l=4;}
gotoxy(w,q); putch(' ');
gotoxy(22,22); for (i=1;i<=18;i++) putch(' ');
q=q+z[l][0]; w=w+z[l][1]; l=4;
if (j==4) {map[q-1][w-1]=0; s=1; gotoxy(35,10); printf(" /");
gotoxy(35,11); printf(" \\/");}
if (j==8) {map[q-1][w-1]=0; map[17][4]=0; gotoxy(5,18); putch(' ');
gotoxy(35,14); printf(" /"); gotoxy(35,15); printf(" \\/");}
if (j==3) {gotoxy(22,22); printf("AnMen(SecretDoor)");}
if (j==6) {map[q-1][w-1]=0; u=1; gotoxy(4,16); putch(' ');
gotoxy(35,3); printf(" /"); gotoxy(35,4); printf(" \\/");}
} gotoxy(w,q); putch(178);
if (map[q-1][w-1]==9)
{gotoxy(10,23); printf("You won! Very good!"); gotoxy(35,16);
printf(" /"); gotoxy(35,17); printf(" \\/"); break;}
delay(8000);
}
getch();
}

贪吃蛇(上下左右移动吃食物):
#include
#include
#include
#include
int x=5,y=2,r=1,mx[4]={0,1,0,-1},my[4]={-1,0,1,0},s[40][3],u=5,g=1,
map[40][24]={0},score=0;
boxx(int x1,int y1,int x2,char c)
{ int j;
for (j=x1;j<=x2;j++) {gotoxy(j,y1); putch©;}
}
boxy(int x1,int y1,int y2,char c)
{ int j;
for (j=y1;j<=y2;j++) {gotoxy(x1,j); putch©;}
}
inkey()
{ char o;
randomize();
if (kbhit()) {
o=getch();
if (o==27) {exit(0);}
if (o==0) {
o=getch();
if (o==72) r=0;
if (o==77) r=1;
if (o==80) r=2;
if (o==75) r=3;
}
}
x=x+mx[r]; y=y+my[r];
if (x<2||x>39) {x=x-mx[r];}
if (y<2||y>23) {y=y-my[r];}
gotoxy(x,y); putch(178); p(u); if (map[x][y]==1) {score++;
gotoxy(20,1); printf("Score : %d",score); map[x][y]=0;
u++; s[u][1]=s[u-1][1]; s[u][2]=s[u-1][2];
}
gotoxy(s[g][1],s[g][2]); putch(' ');
s[g][1]=x; s[g][2]=y; g=g++;
if (g>u) g=1;
}
p(int h)
{int z; for (z=1;z<=h;z++) {gotoxy(s[z][1],s[z][2]); putch(178);}
}
egg()
{int ex,ey,h;
for (h=1;h<=30;h++){ex=rand()%38+2; ey=rand()%22+2;
map[ex][ey]=1; gotoxy(ex,ey); putch('O');}
}
main()
{ randomize();
textmode(C40); textcolor(rand()%16);
s[1][1]=2; s[1][2]=2; s[2][1]=3; s[2][2]=2; s[3][1]=4;
s[3][2]=2; s[4][1]=5; s[4][2]=2; s[5][1]=6; s[5][2]=2;
boxx(1,1,40,219); boxx(1,24,40,219);
boxy(1,1,24,219); boxy(40,1,24,219); egg();
gotoxy(20,1); printf("Score : %d",score);
while (1) {
gotoxy(x,y); putch(' ');
inkey();
delay(30000); delay(30000);
}
getch();
}

猫捉老鼠(躲开猫吃食物):
#include
#include
#include
#include
main()
{ int cx,cy,x,y,xx,yy,fx,fy,n,kb,r=0,p,o,g=0,sc=0; int set[25][41]={0};
int mx[2][5]={{0,1,0,-1,0},{0,2,0,-2,0}},
my[2][5]={{0,0,-1,0,1},{0,0,-2,0,2}};
clrscr(); textmode(C40); randomize(); n=0;
while (n<50) { do{ fx=rand()%38+2; fy=rand()%22+2;} while(set[fy][fx]!=0);
set[fy][fx]=1; gotoxy(fx,fy); putch('.'); n++;} n=3;
while (n) { do{ fx=rand()%38+2;fy=rand()%22+2;} while (set[fy][fx]!=0);
set[fy][fx]=2; gotoxy(fx,fy); putch('o'); n--;}
gotoxy(2,2); cx=2; cy=2; putch('&');
for (x=1;x<=40;x++) {gotoxy(x,1); putch(219); gotoxy(x,24); putch(219);
if (x<=24) {gotoxy(1,x); putch(219); gotoxy(40,x); putch(219);}}
gotoxy(15,1); printf("Score: %d",sc);
gotoxy(39,23); putch('@'); x=39; y=23;
gotoxy(40,8); putch(' '); gotoxy(1,16); putch(' ');
while (1)
{ if (kbhit()) { kb=getch(); if (kb==27) exit(0); kb=getch();
if (x==40&&y==8) {
if (kb==75)
{gotoxy(x,y); putch(' '); x=x-1; gotoxy(x,y); putch('@');}
if (kb==77)
{gotoxy(x,y); putch(' '); x=2; gotoxy(x,y); putch('@');}
}
if (x==1&&y==16) {
if (kb==75)
{gotoxy(x,y); putch(' '); x=39; gotoxy(x,y); putch('@');}
if (kb==77)
{gotoxy(x,y); putch(' '); x=x+1; gotoxy(x,y); putch('@');}
}
if (kb==77&&y==8&&x==39) {gotoxy(x,y); putch(' ');
x=x+1; gotoxy(x,y); putch('@');} else
if (kb==75&&y==16&&x==2) {gotoxy(x,y); putch(' ');
x=x-1; gotoxy(x,y); putch('@');} else
{if (kb==77&&x<39) r=1; else if (kb==72&&y>2) r=2; else
if (kb==75&&x>2) r=3; else if (kb==80&&y<23) r=4; else r=0;
gotoxy(x,y); putch(' '); xx=x+mx[0][r]; yy=y+my[0][r];
if (g==0) {x=x+mx[0][r]; y=y+my[0][r];} else
{x=x+mx[1][r]; y=y+my[1][r]; g=g-1;
gotoxy(3,1); printf("Gao neng:%d",g); putch(219);}
if ((x==39&&kb==77)||(x==38&&kb==77&&g>0)) x=2;
if ((y==2&&kb==72)||(y==3&&kb==72&&g>0)) y=23;
if ((x==2&&kb==75)||(x==3&&kb==75&&g>0)) x=39;
if ((y==23&&kb==80)||(y==22&&kb==80&&g>0)) y=2;
gotoxy(x,y); putch('@'); if (set[y][x]==1||set[yy][xx]==1)
{gotoxy(15,1); printf("Score: %d",sc+1); sc=sc+1; set[y][x]=0;
gotoxy(xx,yy); putch(' '); gotoxy(x,y); putch('@');} else
if (set[y][x]==2||set[yy][xx]==2)
{gotoxy(3,1); printf("Gao neng:%d",g+10); putch(219); g=g+10;
set[y][x]=0; set[yy][xx]=0;}
if (g==0) { gotoxy(3,1); for (n=1;n<=11;n++) putch(219);}}
if (sc==20) break; if (x==cx&&y==cy) break;}
if ((x==40&&y==8)||(x==1&&y==16)) {} else {
gotoxy(cx,cy); if (set[cy][cx]==1) putch('.'); else putch(' ');
if (cxx) cx=cx-1;
if (cyy) cy=cy-1;
gotoxy(cx,cy); putch('&'); delay(10000); if (x==cx&&y==cy) break;}
}
if (cx==x&&cy==y) {gotoxy(15,3); printf("The cat win!");} else
if (sc>=20) {gotoxy(15,3); printf("The mouse(you) win!");}
getch();
}

俄罗斯方块(移动方块消行):
#include
#include
#include
#include
int x[8][4]={0,0,0,0,
0,1,2,0,
0,1,-1,0,
0,0,0,0,
0,0,1,2,
0,1,0,1,
0,-1,0,1,
0,1,0,-1};
int y[8][4]={0,0,0,0,
0,0,0,-1,
0,0,0,-1,
0,1,2,3,
0,1,0,0,
0,0,1,1,
0,0,1,1,
0,0,1,1};
int fxj[4]={0,1,0,-1},fyj[4]={-1,0,1,0},k[8]={0,0,0,3,1,3,2,2};
int fx,fy,j=2,map[25][41]={0},mapc[25][41]={0},h,w=0,z,nx[4],ny[4],score;
p(int t,char o,int b)
{ int i;
for (i=0;i<=3;i++)
{textcolor(t); gotoxy(fx+nx[i],fy+ny[i]); putch(o);
map[fy+ny[i]][fx+nx[i]]=b;
}
}
inkey()
{ int l,e,k,nnx[4],nny[4]; char o;
if (kbhit()) {
o=getch();
if (o==27) exit(0);
if (o==0) {
o=getch();
if (o==77)
{e=0; for (l=0;l<=3;l++) {
if (fx+nx[l]+1==41) {e=1; break;}
if (map[fy+ny[l]][fx+nx[l]+1]==1) {e=1; break;}
}
if (e==0) {j=1;}
}
if (o==75)
{e=0; for (l=0;l<=3;l++) {
if (fx+nx[l]-1==10) {e=1; break;}
if (map[fy+ny[l]][fx+nx[l]-1]==1) {e=1; break;}
}
if (e==0) {j=3;}
}
if (o==80)
{e=0; for (l=0;l<=3;l++) {
if (map[fy+ny[l]+1][fx+nx[l]]==1) {e=1; break;}
}
if (e==0) {w=10; z=19;}
}
if (o==72)
{ k=0;
for (l=0;l<=3;l++) {
e=nx[l]; nx[l]=ny[l]*(-1); ny[l]=e;
if (map[fy+ny[l]][fx+nx[l]]==1) {k=1;}
if (fx+nx[l]<11||fx+nx[l]>40) {k=1;}
if (fy+ny[l]>24||fy+ny[l]<2) {k=1;}
}
if (k==1)
for (l=0;l<=3;l++) {e=nx[l]; nx[l]=ny[l]; ny[l]=e/(-1);}
}
}
}
}
win()
{gotoxy(20,12); textcolor(3); printf("You won!");
}
over()
{gotoxy(19,12); textcolor(14); printf("Game over!");
}
main()
{ int g,c,u,b,v; textmode(C40); clrscr(); randomize(); h=rand()%7+1;
for (g=1;g<=24;g++) {gotoxy(10,g); putch('|');}
gotoxy(3,3); printf("Next :"); gotoxy(3,15); printf("Score:");
gotoxy(3,16); printf("%d",0); gotoxy(3,11); printf("Esc=");
gotoxy(3,12); printf("TuiChu");
while (1) {
c=0; for (g=0;g<=3;g++) {nx[g]=x[h][g]; ny[g]=y[h][g];}
b=rand()%7+1; fx=25; fy=2;
for (g=0;g<=3;g++)
{textcolor(b); gotoxy(3+x[b][g],5+y[b][g]); putch(219);
}
while (c==0) {
inkey();
p(h,219,0); for (g=1;g<=30-z;g++) delay(1000);
w=w-1; if (w==0) z=0;
p(h,32,0); if (j!=2) {fx=fx+fxj[j]; fy=fy+fyj[j];}
j=2; fx=fx+fxj[2]; fy=fy+fyj[2];
for (g=0;g<=3;g++) {
if (fy+ny[g]>24) {c=1; break;}
if (map[fy+ny[g]][fx+nx[g]]==1) {c=1; break;}
}
} fx=fx-fxj[j]; fy=fy-fyj[j];
p(h,219,1); u=0; w=0;
for (g=0;g<=3;g++) {mapc[fy+ny[g]][fx+nx[g]]=h;}
for (g=0;g<=3;g++)
{textcolor(b); gotoxy(3+x[b][g],5+y[b][g]); putch(32);
}
for (g=1;g<=40;g++) if (map[2][g]==1||map[1][g]) {u=1; break;}
if (u==1)
{ over(); b=rand()%7+1; fx=30; fy=2;
for (g=0;g<=3;g++)
{textcolor(b); gotoxy(3+x[b][g],5+y[b][g]); putch(219);}
getch(); exit(0);
}
h=b; z=1;
do {
u=0; for (g=11;g<=40;g++) {if (map[z][g]==0) {u=1; break;}}
if (u==0) {
for (g=11;g<=40;g++) {gotoxy(g,z); putch(32);}
for (g=z-1;g>=1;g--) for (v=11;v<=40;v++) {map[g+1][v]=map[g][v];}
for (g=z-1;g>=1;g--) for (v=11;v<=40;v++) {mapc[g+1][v]=mapc[g][v];}
for (g=1;g<=24;g++) for (v=11;v<=40;v++)
{gotoxy(v,g); textcolor(mapc[g][v]); putch(219);}
score=score+10; gotoxy(3,16); printf("%d",score);
if (score>=30) {win(); getch(); exit;}
}
z++;
} while (z<25); z=0;
}
}
圈圈叉叉游戏(光标控制):
#include
#include
int w[3][3]={2,1,2,
1,3,1,
2,1,2},i,j,k,l,kk,ll,x,y,m,prx=3,pry=3,s=0,f,g,e,r,h,m,q;
inkey()
{ char o,c[1];
if (kbhit())
{ o=getch();
if (o==27) {exit(0);}
if (o==13) {
gettext(x,y,x,y,&c);
if (c[0]==32) {gotoxy(x,y); putch('o'); s=1;
w[(y-pry)/2][(x-prx)/2]=-1;
}
}
if (o==0) {
o=getch();
if (o==72&&y>pry) {y--;}
if (o==77&&x if (o==80&&y if (o==75&&x>prx) {x--;}
}
}
}
pr()
{ gotoxy(prx,pry+0); printf(" | | ");
gotoxy(prx,pry+1); printf("-+-+-");
gotoxy(prx,pry+2); printf(" | | ");
gotoxy(prx,pry+3); printf("-+-+-");
gotoxy(prx,pry+4); printf(" | | ");
}
p()
{ for (h=0;h<=2;h++) {
q=0; for (m=0;m<=2;m++) if (w[h][m]==-1) q++;
if (q==3) {gotoxy(10,5); printf("Ni Ying Le"); getch(); exit(0);}
q=0; for (m=0;m<=2;m++) if (w[m][h]==-1) q++;
if (q==3) {gotoxy(10,5); printf("Ni Ying Le"); getch(); exit(0);}
q=0; for (m=0;m<=2;m++) if (w[h][m]==-2) q++;
if (q==3) {gotoxy(10,5); printf("Wo Ying Le"); getch(); exit(0);}
q=0; for (m=0;m<=2;m++) if (w[m][h]==-2) q++;
if (q==3) {gotoxy(10,5); printf("Wo Ying Le"); getch(); exit(0);}
}
q=w[0][0]+w[1][1]+w[2][2];
if (q==-6) {gotoxy(10,5); printf("Wo Ying Le"); getch(); exit(0);}
q=w[0][2]+w[1][1]+w[2][0];
if (q==-6) {gotoxy(10,5); printf("Wo Ying Le"); getch(); exit(0);}
q=0; for (h=0;h<=2;h++) for (m=0;m<=2;m++) if (w[h][m]>0) {q=1;}
if (q==0) {gotoxy(10,5); printf("Ping Ju"); getch(); exit(0);}
}
main()
{ textmode(C40); pr(); gotoxy(prx+2,pry+2); putch('x');
w[1][1]=-2; x=prx; y=pry; gotoxy(10,7); printf("Esc Tui Chu");
while (1) {
inkey(); gotoxy(x,y);
if (s==1) {s=0; e=-1; r=-1;
for (i=0;i<=2;i++)
{ l=0; f=-1; g=-1; ll=0; for (j=0;j<=2;j++) {
if (w[i][j]==-1) {l++;}
if (w[i][j]==-2) {ll++;}
if (w[i][j]>0) {f=i; g=j;}
}
if ((l==2)&&(e<0||r<0)&&f>=0&&g>=0) {e=f; r=g;}
if (ll==2&&f>=0&&g>=0) {e=f; r=g;}
k=0; f=-1; g=-1; kk=0; for (j=0;j<=2;j++) {
if (w[j][i]==-1) {k++;}
if (w[j][i]==-2) {kk++;}
if (w[j][i]>0) {f=j; g=i;}
}
if ((k==2)&&(e<0||r<0)&&f>=0&&g>=0) {e=f; r=g;}
if (kk==2&&f>=0&&g>=0) {e=f; r=g;}
}
k=0; f=-1; g=-1;
if (w[0][0]==-1) {k++;} if (w[0][0]>0) {f=0; g=0;}
if (w[1][1]==-1) {k++;} if (w[1][1]>0) {f=1; g=1;}
if (w[2][2]==-1) {k++;} if (w[2][2]>0) {f=2; g=2;}
if (k==2) {e=f; r=g;}
l=0; f=-1; g=-1;
if (w[0][2]==-1) {l++;} if (w[0][2]>0) {f=0; g=0;}
if (w[1][1]==-1) {l++;} if (w[1][1]>0) {f=1; g=1;}
if (w[2][0]==-1) {l++;} if (w[2][0]>0) {f=2; g=2;}
if (l==2&&f>=0&&g>=0) {e=f; r=g;}
if (e<0||r<0) {
k=0; l=0; m=0;
for (i=0;i<=2;i++)
for (j=0;j<=2;j++)
if (w[i][j]>m) {m=w[i][j]; k=i; l=j;}
gotoxy(l+prx+l,k+pry+k); w[k][l]=-2; putch('x');
} else {gotoxy(r+prx+r,e+pry+e); putch('x'); w[e][r]=-2;}
p();
}
}
}
弹球游戏(WASD和8546控制):
#include
#include
main()
{ int x,y,xf=1,yf=1,bf=6,bg=22,pf=30,pg=22,k=800,o,j,i,score=0;
char p;
clrscr(); textmode(C40);
for (x=1;x<=40;x++) { gotoxy(x,1); putch(219); gotoxy(x,24); putch(219);}
for (y=1;y<=24;y++) { gotoxy(1,y); putch(219); gotoxy(40,y); putch(219);}
gotoxy(3,3); putch('O'); x=3; y=3; gotoxy(bf,bg); printf("----");
gotoxy(pf,pg); printf("----");
gotoxy(3,1); printf("<=-20--Lost");
gotoxy(16,1); printf("Score: %d **",score);
gotoxy(30,1); printf(">=50--Win");
while (k&&score<50&&score>-20)
{ gotoxy(bf,bg); printf("----");
gotoxy(pf,pg); printf("----");
gotoxy(x,y); putch('O'); delay(1000000000);
gotoxy(x,y); putch(' ');
if (x==39) {xf=-1;} if (x==2) {xf=1;}
if (y==23) {yf=-1;} if (y==2) {yf=1;}
x+=xf; y+=yf;
if (y==bg-1&&x>=(bf-1)&&x<=(bf+6)&&yf==1)
if ((x==bf-1&&xf==1)||(x>=bf&&x<=(bf+5))||(x==bf+6&&xf==-1)) {
if (x==bf-1&&xf==1) xf=-1; if (x==bf+6&&xf==-1) xf=1; yf=-1;
if (yf==1) {score+=5; gotoxy(15,1);
printf("Score: %d +5",score); putch(219);}
}
if (y==pg-1&&x>=(pf-1)&&x<=(pf+6))
if ((x==pf-1&&xf==1)||(x>=pf&&x<=(pf+5))||(x==pf+6&&xf==-1)) {
yf=-1; score+=5; gotoxy(15,1);
printf("Score: %d +5",score); putch(219);}
if (y==23) {score-=5; gotoxy(15,1);
printf("Score: %d -5",score); putch(219);}
if (kbhit())
{ p=getch(); o=p;
if (o==27) exit();
if (p=='a'&&bf>3) {gotoxy(bf,bg); printf(" "); bf=bf-2;
gotoxy(bf,bg); printf("----");}
if (p=='d'&&bf+5 gotoxy(bf,bg); printf("----");}
if (p=='w'&&bg-1>1) {gotoxy(bf,bg); printf(" "); bg=bg-1;
gotoxy(bf,bg); printf("----");}
if (p=='s'&&bg+1<24) {gotoxy(bf,bg); printf(" "); bg=bg+1;
gotoxy(bf,bg); printf("----");}
if (p=='4'&&pf>bf+6) {gotoxy(pf,pg); printf(" "); pf=pf-2;
gotoxy(pf,pg); printf("----");}
if (p=='6'&&pf+5<38) {gotoxy(pf,pg); printf(" "); pf=pf+2;
gotoxy(pf,pg); printf("----");}
if (p=='8'&&pg-1>1) {gotoxy(pf,pg); printf(" "); pg=pg-1;
gotoxy(pf,pg); printf("----");}
if (p=='5'&&pg+1<24) {gotoxy(pf,pg); printf(" "); pg=pg+1;
gotoxy(pf,pg); printf("----");}
}

k--;
} gotoxy(x,y); putch('O');
if (score>=50) {gotoxy(10,3); printf("Score>=50! You win!");}
if (score<=-20) {gotoxy(10,3); printf("Score<=-20! You lost!");}
getch();
}