玩过炸弹超人吧,玩过qq堂吧,制作这些很适合我这个初c学者,我学习c语言也近2个月了,就随手编了个游戏,用了2天啊~~~
两个人碗的,A控制WASD空格,B控制光标键和回车
命数,关的风格自己在文件头自己搞定;可以吃的道具由种分别加威力和雷数(最多8个)--简单的16色游戏。
没有注解,看完后,给点建议---------------badming————————————
/* WIN-TC BGI 图形编程模板 */
#include "Conio.h"
#include "graphics.h"
#include <stdio.h>
#include <bios.h>
#define closegr closegraph
#define UP 0x4800
#define DOWN 0x5000
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define SPACE 0x3920
#define W 0x1177
#define S 0x1f73
#define A 0x1e61
#define D 0x2064
#define ENTER 0x1c0d
#define ESC 0x011b
int a[13][19]={
{10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10},
{0,1,1,10,2,10,10,104,103,102,101,10,10,10,10,10,10,10,10},
{0,1,10,12,10,10,102,102,103,103,103,10,10,10,10,10,10,10,10},
{0,10,10,10,10,120,120,12,12,103,103,13,130,130,10,10,10,10,10},
{0,10,10,10,10,120,1204,102,102,103,103,130,130,130,10,10,10,10,10},
{0,10,10,10,10,120,1204,102,102,103,103,130,130,130,10,10,10,10,10},
{0,10,10,10,10,1204,1204,102,102,13,130,130,130,130,10,10,10,10,10},
{0,10,10,10,10,120,1204,120,102,103,130,130,130,130,10,10,10,10,10},
{0,10,10,10,10,120,1204,120,102,104,140,140,10,10,10,103,10,10,10},
{0,10,10,10,10,140,14,14,14,140,104,140,10,10,103,10,104,104,104},
{0,10,10,10,10,140,14,14,14,140,104,140,10,104,10,104,10,104,10},
{0,10,10,10,10,140,14,14,14,140,104,140,10,10,102,102,102,10,1},
{0,10,10,10,10,140,144,1440,1400,104,140,140,10,10,10,10,4,1,1}};
int a1=1,b1=1,mov1=1,high1=1,wide1=1,num1=1,lnum1=1,life1=100;
int a2=18,b2=12,mov2=1,high2=1,wide2=1,num2=1,lnum2=1,life2=10;
struct po{int x;int y;int lmax;int rmax;int umax;int dmax;
int feel;long time;struct po *next;};
struct po po1,po2,po3,po4,po5,po6,po7,po8,po9,po10,po11,po12,po13,po14,po15,po16,*p1,*p2;
f(x,y)
{int z;
if(a[y][x]<10)z=a[y][x];else z=a[y][x]/10;
return z;}
g(x,y)
{int z;
z=a[y][x]%10;
return z;
}
void initgr(void) /* BGI初始化 */
{
int gd = DETECT, gm = 0; /* 和gd = VGA,gm = VGAHI是同样效果 */
registerbgidriver(EGAVGA_driver);/* 注册BGI驱动后可以不需要.BGI文件的支持运行 */
initgraph(&gd, &gm, "");
}
draw0(x,y)
{setfillstyle(1,14);bar(30*x+20,30*y+30,30*x+50,30*y+60);}
draw1(x,y)
{setcolor(BLUE);setfillstyle(1,GREEN);bar(30*x+20,30*y+30,30*x+50,30*y+60);}
draw2(x,y)
{setcolor(RED);line(30*x+35,30*y+30,30*x+35,30*y+60);
line(30*x+20,30*y+45,30*x+35,30*y+30);line(30*x+35,30*y+30,30*x+50,30*y+45);}
draw3(x,y)
{setcolor(RED);line(30*x+20,30*y+45,30*x+50,30*y+45);
line(30*x+35,30*y+30,30*x+50,30*y+45);line(30*x+50,30*y+45,30*x+35,30*y+60);}
draw4(x,y)
{setcolor(9);line(30*x+20,30*y+45,30*x+50,30*y+45);
line(30*x,30*y+15,30*x+30,30*y+15);circle(30*x+35,30*y+45,15);}
draw5(x,y)
{setcolor(0);setfillstyle(1,0);pieslice(30*x+35,30*y+45,0,360,15);}
draw6(x,y)
{setcolor(RED);setfillstyle(1,13);bar(30*x+20,30*y+30,30*x+50,30*y+60);}
draw7(x,y)
{setcolor(RED);circle(30*x+35,30*y+40,10);
line(30*x+35,30*y+50,30*x+35,30*y+60);line(30*x+35,30*y+50,30*x+40,30*y+60);} draw8(x,y)
{setcolor(YELLOW);circle(30*x+35,30*y+40,10);
line(30*x+35,30*y+50,30*x+35,30*y+60);line(30*x+35,30*y+50,30*x+40,30*y+60);}
draw(x,y,z)
{switch(z){
case 0:draw0(x,y);break;
case 1:draw1(x,y);break;
case 2:draw2(x,y);break;
case 3:draw3(x,y);break;
case 4:draw4(x,y);break;
case 5:draw5(x,y);break;
case 6:draw6(x,y);break;
case 7:draw7(x,y);break;
case 8:draw8(x,y);break;
}
}
initpic()
{int i,j;
cleardevice();
setbkcolor(WHITE);
for(j=1;j<=12;j+=1)for(i=1;i<=18;i+=1)draw(i,j,g(i,j));
draw(a1,b1,7);
draw(a2,b2,8);
}
/**************************/
eatpo1(){
if(num1<=7)
{num1+=1;lnum1+=1;switch(num1){
case 2:po1.next=&po2;po2.next=&po1;po2.feel=0;break;
case 3:po2.next=&po3;po3.next=&po1;po3.feel=0;break;
case 4:po3.next=&po4;po4.next=&po1;po4.feel=0;break;
case 5:po4.next=&po5;po5.next=&po1;po5.feel=0;break;
case 6:po5.next=&po6;po6.next=&po1;po6.feel=0;break;
case 7:po6.next=&po7;po7.next=&po1;po7.feel=0;break;
case 8:po7.next=&po8;po8.next=&po1;po8.feel=0;break;}}}
eatpo2(){if(num2<=7)
{num2+=1;lnum2+=1;switch(num2){
case 2:po9.next=&po10;po10.next=&po9;po10.feel=0;break;
case 3:po10.next=&po11;po11.next=&po9;po11.feel=0;break;
case 4:po11.next=&po12;po12.next=&po9;po12.feel=0;break;
case 5:po12.next=&po13;po13.next=&po9;po13.feel=0;break;
case 6:po13.next=&po14;po14.next=&po9;po14.feel=0;break;
case 7:po14.next=&po15;po15.next=&po9;po15.feel=0;break;
case 8:po15.next=&po16;po16.next=&po9;po16.feel=0;break;}}}
/***********/
eat1()
{switch(g(a1,b1))
{case 2:high1+=1;a[b1][a1]=f(a1,b1);break;
case 3:wide1+=1;a[b1][a1]=f(a1,b1);break;
case 4:eatpo1();a[b1][a1]=f(a1,b1);break;
}
}eat2()
{switch(g(a2,b2))
{case 2:high2+=1;a[b2][a2]=f(a2,b2);break;
case 3:wide2+=1;a[b2][a2]=f(a2,b2);break;
case 4:eatpo2();a[b2][a2]=f(a2,b2);break;
}
}
/**********************************/
up1()
{if(b1>=2&&g(a1,(b1-1))!=0&&g(a1,(b1-1))!=5)
{draw(a1,b1,1);draw(a1,b1,g(a1,b1));b1-=1;draw(a1,b1,1);draw(a1,b1,7);eat1();}}
down1()
{if(b1<=11&&g(a1,(b1+1))!=0&&g(a1,(b1+1))!=5)
{draw(a1,b1,1);draw(a1,b1,g(a1,b1));b1+=1;draw(a1,b1,1);draw(a1,b1,7);eat1();}}
left1()
{if(a1>=2&&g((a1-1),b1)!=0&&g((a1-1),b1)!=5)
{draw(a1,b1,1);draw(a1,b1,g(a1,b1));a1-=1;draw(a1,b1,1);draw(a1,b1,7);eat1();}}
right1()
{if(a1<=17&&g((a1+1),b1)!=0&&g((a1+1),b1)!=5)
{draw(a1,b1,1);draw(a1,b1,g(a1,b1));a1+=1;draw(a1,b1,1);draw(a1,b1,7);eat1();}}
put1()
{if(lnum1>=1){draw(a1,b1,5);a[b1][a1]=5;(*p1).x=a1;(*p1).y=b1;(*p1).time=110000;(*p1).feel=1;p1=(*p1).next;lnum1-=1;}}
/*********************************************/
up2()
{if(b2>=2&&g(a2,(b2-1))!=0&&g(a2,(b2-1))!=5)
{draw(a2,b2,1);draw(a2,b2,g(a2,b2));b2-=1;draw(a2,b2,1);draw(a2,b2,8);eat2();}}
down2()
{if(b2<=11&&g(a2,(b2+1))!=0&&g(a2,(b2+1))!=5)
{draw(a2,b2,1);draw(a2,b2,g(a2,b2));b2+=1;draw(a2,b2,1);draw(a2,b2,8);eat2();}}
left2()
{if(a2>=2&&g((a2-1),b2)!=0&&g((a2-1),b2)!=5)
{draw(a2,b2,1);draw(a2,b2,g(a2,b2));a2-=1;draw(a2,b2,1);draw(a2,b2,8);eat2();}}
right2()
{if(a2<=17&&g((a2+1),b2)!=0&&g((a2+1),b2)!=5)
{draw(a2,b2,g(a2,b2));a2+=1;draw(a2,b2,1);draw(a2,b2,8);eat2();}} put2()
{if(lnum2>=1){draw(a2,b2,5);a[b2][a2]=5;(*p2).x=a2;(*p2).y=b2;(*p2).time=110000;(*p2).feel=1;p2=(*p2).next;lnum2-=1;}}
getkey()
{
if(bioskey(1)!=0)
{switch(bioskey(0))
{
case UP:if(mov1==1)up1();break;
case DOWN: if(mov1==1)down1();break;
case LEFT: if(mov1==1)left1();break;
case RIGHT: if(mov1==1)right1();break;
case ENTER: if(mov1==1)put1();break;
case ESC: closegr();exit(1);break;
case W: if(mov2==1)up2();break;
case S: if(mov2==1)down2();break;
case A: if(mov2==1)left2();break;
case D: if(mov2==1)right2();break;
case SPACE : if(mov2==1)put2();break;
}
}
}
/*****************************/
die1()
{if(a1==(*p1).x&&b1==(*p1).y){mov1=0;life1-=1;}
if(a2==(*p1).x&&b2==(*p1).y){mov2=0;life2-=1;}
}
die2()
{if(a1==(*p2).x&&b1==(*p2).y){mov1=0;life1-=1;}
if(a2==(*p2).x&&b2==(*p2).y){mov2=0;life2-=1;}
}
poon1()
{int i;
for(i=(*p1).lmax;i<=(*p1).rmax;i+=1)
{draw(i,(*p1).y,6);a[(*p1).y][i]=f(i,(*p1).y);
if(a1==i&&b1==(*p1).y){mov1=0;life1-=1;}
if(a2==i&&b2==(*p1).y){mov2=0;life2-=1;}}
for(i=(*p1).umax;i<=(*p1).dmax;i+=1)
{draw((*p1).x,i,6);a[i][(*p1).x]=f((*p1).x,i);
if(a1==(*p1).x&&b1==i){mov1=0;life1-=1;}
if(a2==(*p1).x&&b2==i){mov2=0;life2-=1;}
}
}
poon2()
{int i;
for(i=(*p2).lmax;i<=(*p2).rmax;i+=1)
{draw(i,(*p2).y,6);a[(*p2).y][i]=f(i,(*p2).y);
if(a1==i&&b1==(*p2).y){mov1=0;life1-=1;}
if(a2==i&&b2==(*p2).y){mov2=0;life2-=1;}}
for(i=(*p2).umax;i<=(*p2).dmax;i+=1)
{draw((*p2).x,i,6);a[i][(*p2).x]=f((*p2).x,i);
if(a2==(*p2).x&&b2==i){mov2=0;life2-=1;}
if(a1==(*p2).x&&b1==i){mov1=0;life1-=1;}}
}
pooff1()
{int i;
for(i=(*p1).lmax;i<=(*p1).rmax;i+=1){draw(i,(*p1).y,1);draw(i,(*p1).y,g(i,(*p1).y));}
for(i=(*p1).umax;i<=(*p1).dmax;i+=1){draw((*p1).x,i,1);draw((*p1).x,i,g((*p1).x,i));}
}
pooff2()
{int i;
for(i=(*p2).lmax;i<=(*p2).rmax;i+=1){draw(i,(*p2).y,1);draw(i,(*p2).y,g(i,(*p2).y));}
for(i=(*p2).umax;i<=(*p2).dmax;i+=1){draw((*p2).x,i,1);draw((*p2).x,i,g((*p2).x,i));}
}
open12()
{(*p1).time-=1;if((*p1).time==200)(*p1).feel=2;}
open22()
{(*p2).time-=1;if((*p2).time==200)(*p2).feel=2;}
get1()
{if(high1>=(*p1).y)(*p1).umax=1;else (*p1).umax=(*p1).y-high1;
if(high1+(*p1).y>12)(*p1).dmax=12;else (*p1).dmax=(*p1).y+high1;
if(wide1>=(*p1).x)(*p1).lmax=1;else (*p1).lmax=(*p1).x-wide1;
if(wide1+(*p1).x>18)(*p1).rmax=1;else (*p1).rmax=(*p1).x+wide1;
}
get2()
{if(high2>=(*p2).y)(*p2).umax=1;else (*p2).umax=(*p2).y-high2;
if(high2+(*p2).y>12)(*p2).dmax=12;else (*p2).dmax=(*p2).y+high2;
if(wide2>=(*p2).x)(*p2).lmax=1;else (*p2).lmax=(*p2).x-wide2;
if(wide2+(*p2).x>18)(*p2).rmax=18;else (*p2).rmax=(*p2).x+wide2;
}
open13()
{int i;
if((*p1).time==200){get1();poon1();(*p1).time-=1;}
if((*p1).time==0){a[(*p1).y][(*p1).x]=1;pooff1();(*p1).feel=0;lnum1+=1;}
else{poon1();(*p1).time-=1; }
}
open23()
{int i;
if((*p2).time==200){get2();poon2();(*p2).time-=1;}
if((*p2).time==0){a[(*p2).y][(*p2).x]=1;pooff2();(*p2).feel=0;lnum2+=1;}
else{poon2();(*p2).time-=1; }
}
/*********************************/
broken1()
{int i;
for(i=1;i<=num1;i+=1)
{switch((*p1).feel){
case 1:open12();break;
case 2:open13();break;
}
p1=(*p1).next;
}
}
broken2()
{int i;
for(i=1;i<=num2;i+=1)
{switch((*p2).feel){
case 1:open22();break;
case 2:open23();break;
}
p2=(*p2).next;
}
}
reborn()
{if(mov1==0&&life1>0){draw(1,1,7);a1=1;b1=1;mov1=1;}
if(mov2==0&&life2>0){draw(18,12,8);a2=18;b2=12;mov2=1;}
}
/**************************/
int main(void)
{
initgr(); /* BGI初始化 */
po1.next=&po1;
po9.next=&po9;
p1=&po1;
p2=&po9;
initpic();
while(1){getkey();broken1();broken2();reborn();}
getch(); /* 暂停一下,看看前面绘图代码的运行结果 */
closegr(); /* 恢复TEXT屏幕模式 */
return 0;
}
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |