189 8069 5689

c语言中弹球函数问题,c语言反弹球

三维弹球游戏C语言程式码怎么写

C语言写不了界面程序的,更别说3D的了,你得再用一个图形库或者接口,opengl之类的,不过做游戏最好是用现成的游戏引擎。

创新互联是一家集网站建设,河东企业网站建设,河东品牌网站建设,网站定制,河东网站建设报价,网络营销,网络优化,河东网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

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

C语言做游戏

点灯游戏(把灯都打开变黄):

#include conio.h

#include stdio.h

#include stdlib.h

#include time.h

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==72y1) {y--;}

if (o==77x5) {x++;}

if (o==80y5) {y++;}

if (o==75x1) {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 conio.h

#include time.h

#include stdlib.h

#include stdio.h

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;y20;y++) {

for (x=0;x20;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!=0j!=4j!=8j!=3j!=s*2j!=9j!=6j!=u*1j!=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 stdio.h

#include conio.h

#include stdlib.h

#include time.h

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 (x2||x39) {x=x-mx[r];}

if (y2||y23) {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 (gu) 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();

}

猫捉老鼠(躲开猫吃食物):

#includestdio.h

#includeconio.h

#includestdlib.h

#includetime.h

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 (n50) { 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==40y==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==1y==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==77y==8x==39) {gotoxy(x,y); putch(' ');

x=x+1; gotoxy(x,y); putch('@');} else

if (kb==75y==16x==2) {gotoxy(x,y); putch(' ');

x=x-1; gotoxy(x,y); putch('@');} else

{if (kb==77x39) r=1; else if (kb==72y2) r=2; else

if (kb==75x2) r=3; else if (kb==80y23) 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==39kb==77)||(x==38kb==77g0)) x=2;

if ((y==2kb==72)||(y==3kb==72g0)) y=23;

if ((x==2kb==75)||(x==3kb==75g0)) x=39;

if ((y==23kb==80)||(y==22kb==80g0)) 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==cxy==cy) break;}

if ((x==40y==8)||(x==1y==16)) {} else {

gotoxy(cx,cy); if (set[cy][cx]==1) putch('.'); else putch(' ');

if (cxx) cx=cx+1; if (cxx) cx=cx-1;

if (cyy) cy=cy+1; if (cyy) cy=cy-1;

gotoxy(cx,cy); putch(''); delay(10000); if (x==cxy==cy) break;}

}

if (cx==xcy==y) {gotoxy(15,3); printf("The cat win!");} else

if (sc=20) {gotoxy(15,3); printf("The mouse(you) win!");}

getch();

}

俄罗斯方块(移动方块消行):

#include stdio.h

#include stdlib.h

#include time.h

#include conio.h

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 (z25); z=0;

}

}

圈圈叉叉游戏(光标控制):

#include conio.h

#include stdio.h

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==72ypry) {y--;}

if (o==77xprx+4) {x++;}

if (o==80ypry+4) {y++;}

if (o==75xprx) {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)(e0||r0)f=0g=0) {e=f; r=g;}

if (ll==2f=0g=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)(e0||r0)f=0g=0) {e=f; r=g;}

if (kk==2f=0g=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==2f=0g=0) {e=f; r=g;}

if (e0||r0) {

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 stdio.h

#include conio.h

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 (kscore50score-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-1x=(bf-1)x=(bf+6)yf==1)

if ((x==bf-1xf==1)||(x=bfx=(bf+5))||(x==bf+6xf==-1)) {

if (x==bf-1xf==1) xf=-1; if (x==bf+6xf==-1) xf=1; yf=-1;

if (yf==1) {score+=5; gotoxy(15,1);

printf("Score: %d +5",score); putch(219);}

}

if (y==pg-1x=(pf-1)x=(pf+6))

if ((x==pf-1xf==1)||(x=pfx=(pf+5))||(x==pf+6xf==-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'bf3) {gotoxy(bf,bg); printf(" "); bf=bf-2;

gotoxy(bf,bg); printf("----");}

if (p=='d'bf+5pf-1) {gotoxy(bf,bg); printf(" "); bf=bf+2;

gotoxy(bf,bg); printf("----");}

if (p=='w'bg-11) {gotoxy(bf,bg); printf(" "); bg=bg-1;

gotoxy(bf,bg); printf("----");}

if (p=='s'bg+124) {gotoxy(bf,bg); printf(" "); bg=bg+1;

gotoxy(bf,bg); printf("----");}

if (p=='4'pfbf+6) {gotoxy(pf,pg); printf(" "); pf=pf-2;

gotoxy(pf,pg); printf("----");}

if (p=='6'pf+538) {gotoxy(pf,pg); printf(" "); pf=pf+2;

gotoxy(pf,pg); printf("----");}

if (p=='8'pg-11) {gotoxy(pf,pg); printf(" "); pg=pg-1;

gotoxy(pf,pg); printf("----");}

if (p=='5'pg+124) {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();

}

怎么用c语言编一个简单弹球问题

/*Ball.h:定义结构体和BALL相关的函数*/

#ifndef _BALL_VC_SUPER_ADMI_2009_12_13_INCLUDE_

#define _BALL_VC_SUPER_ADMI_2009_12_13_INCLUDE_

typedef struct tagPOINT3D //3D坐标系

{

float x;

float y;

float z;

}POINT3D;

typedef struct tagBALL //球

{

POINT3D cur_coor;

POINT3D speed;

float radius;

}BALL;

typedef struct tagBOX //球的长方体运动场所,中空

{

POINT3D angle_coor[8]; //坐标,从下往上,顺时针

float length;

float width;

float height;

}BOX;

void init_box(BOX *mybox,POINT3D origi_coor,POINT3D LWH)

{

int i;

mybox-height=LWH.x;

mybox-width=LWH.y;

mybox-height=LWH.z;

for(i=0;i8;i++)mybox-angle_coor[i]=origi_coor;

mybox-angle_coor[1].x=origi_coor.x+LWH.x;

mybox-angle_coor[2].x=origi_coor.x+LWH.x;

mybox-angle_coor[2].y=origi_coor.y+LWH.y;

mybox-angle_coor[3].y=origi_coor.y+LWH.y;

for(i=4;i8;i++)mybox-angle_coor[i].z=origi_coor.z+LWH.z;

mybox-angle_coor[5].x=origi_coor.x+LWH.x;

mybox-angle_coor[6].x=origi_coor.x+LWH.x;

mybox-angle_coor[6].y=origi_coor.y+LWH.y;

mybox-angle_coor[7].y=origi_coor.y+LWH.y;

}

void move_in_box(BALL* myball,BOX mybox) //匀速运动

{

myball-cur_coor.x+=myball-speed.x;

myball-cur_coor.y+=myball-speed.y;

myball-cur_coor.z+=myball-speed.z;

}

void hit_wall(BALL* myball,POINT3D dir) //撞墙

{

myball-speed.x*=dir.x;

myball-speed.y*=dir.y;

myball-speed.z*=dir.z;

}

int coll_dete_rad_ign(BALL* myball,BOX mybox) //检测(忽略半径)

{

POINT3D dir;

dir.x=1;dir.y=1;dir.z=1;

if(myball-cur_coor.x=mybox.angle_coor[0].x ||myball-cur_coor.x=mybox.angle_coor[6].x)

dir.x=-1;

if(myball-cur_coor.y=mybox.angle_coor[0].y ||myball-cur_coor.y=mybox.angle_coor[6].y)

dir.y=-1;

if(myball-cur_coor.z=mybox.angle_coor[0].z ||myball-cur_coor.z=mybox.angle_coor[6].z)

dir.z=-1;

if(dir.x==-1 ||dir.y==-1 ||dir.z==-1){hit_wall(myball,dir);return 1;}

return 0;

}

#endif

//BALL.H文件结束

/*Ball.c:测试代码*/

#include "Ball.h"

#include stdio.h

int main(void)

{

POINT3D origi;

POINT3D LWH;

BOX mybox;

BALL myball;

int i;

origi.x=0;origi.y=0;origi.z=0;

printf("矩形空间尺寸:");

scanf("%f%f%f",LWH.x,LWH.y,LWH.z);

printf("球的初始坐标:");

scanf("%f%f%f",myball.cur_coor.x,myball.cur_coor.y,myball.cur_coor.z);

printf("球的速度:");

scanf("%f%f%f",myball.speed.x,myball.speed.y,myball.speed.z);

/* LWH.x=10;LWH.y=10;LWH.z=10;

myball.cur_coor.x=5;myball.cur_coor.y=5;myball.cur_coor.z=5;

myball.speed.x=0.2;myball.speed.y=0.5;myball.speed.z=1;*/

i=0;init_box(mybox,origi,LWH);

printf("\n相关信息如下:\n");

printf("矩形空间尺寸--L:%f,W:%f,H:%f\n",LWH.x,LWH.y,LWH.z);

printf("球的初始坐标--X:%f,Y:%f,Z:%f\n",myball.cur_coor.x,myball.cur_coor.y,myball.cur_coor.z);

printf("球的初始速度--X:%f,Y:%f,Z:%f\n",myball.speed.x,myball.speed.y,myball.speed.z);

printf("碰撞点坐标如下:\n");

while(i10)

{

if(coll_dete_rad_ign(myball,mybox)==1)

{

i++;

printf("%f,%f,%f\n",myball.cur_coor.x,myball.cur_coor.y,myball.cur_coor.z);

}

move_in_box(myball,mybox);

}

return 0;

}


网页题目:c语言中弹球函数问题,c语言反弹球
网页路径:http://cdxtjz.cn/article/dseppec.html

其他资讯