资源预览内容
第1页 / 共21页
第2页 / 共21页
第3页 / 共21页
第4页 / 共21页
第5页 / 共21页
第6页 / 共21页
第7页 / 共21页
第8页 / 共21页
第9页 / 共21页
第10页 / 共21页
亲,该文档总共21页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
/* Note:Your choice is C IDE */#include graphics.h#include stdlib.h#include stdio.h#define a_UP 0x4800/*定义A坦克按键*/#define a_DOWN 0x5000#define a_LEFT 0x4b00#define a_RIGHT 0x4d00#define a_shoot 0x1c0d#define b_UP 0x1177/*定义B坦克按键*/#define b_DOWN 0x1f73#define b_LEFT 0x1e61#define b_RIGHT 0x2064#define b_shoot 0x246a#define ESC 0x011b/*定义退出键*/#define UPWAY 1/*定义方向*/#define DOWNWAY 2#define LEFTWAY 3#define RIGHTWAY 4int enemynum=3;/*定义敌人数量*/int player_life=2;/*定义ESC退出判断条件*/struct SHOOT /*定义炮弹结构体*/int life;int x,y;int way;shoot5=0,0,0,UPWAY,0,0,0,UPWAY,0,0,0,UPWAY,0,0,0,UPWAY,0,0,0,UPWAY;struct PLAYER /*定义玩家结构体*/int life;int x,y;int i,j;int way;player2=1,0,0,3,13,UPWAY,1,0,0,10,13,UPWAY;struct ENEMY /*定义敌人结构体*/int life;int x,y;int i,j;int way;int control;enemy3=1,0,0,1,1,DOWNWAY,0,1,0,0,1,2,DOWNWAY,0,1,0,0,1,3,DOWNWAY,0;/*声明区*/void firsthappy(void);/*开场动画*/void play();/*定义游戏过程主函数*/void map_all(int map1515);/*初始化地图函数*/void judge_tank_my(int map1515,int key);/*判断己方坦克运动函数*/void enemy_control(int map1515);/*控制敌人运动函数*/void judge_moveshootway(int map1515,int i);/*炮弹运动时判断炮弹方向函数*/void judge_shoot(int m,int map1515,int i);/*判断炮弹打中的物体函数*/void judge_shootway(int map1515,int i);/*炮弹打中物体时判断方向函数*/void uptank(int i,int j,int color);/*画坦克函数*/void downtank(int i,int j,int color);void lefttank(int i,int j,int color);void righttank(int i,int j,int color);void allcircle(int i,int j);/*画坦克中圆圈函数*/void blank(int i,int j);/*画空白函数*/void map_water(int i,int j);/*画地图函数*/void map_steel(int i,int j);void map_wall(int i,int j);void map_border(int i,int j);void map_base(int i,int j);void end();/*定义游戏结束函数*/main()int driver=VGA,mode=VGAHI;/*初始化图形模式*/initgraph(&driver,&mode,);/*主函数中函数的调用*/firsthappy();setbkcolor(7);play();end();void play()/*游戏过程主函数*/int key;int i;int num=0;int map1515=8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,/*初始化地图数组*/ 8 ,44,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,8 , 8 ,45,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,8 , 8 ,46,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,8 , 8 ,5 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,5 ,5 ,5 ,8 , 8 ,5 ,0 ,0 ,7 ,7 ,7 ,6 ,7 ,7 ,7 ,5 ,5 ,5 ,8 , 8 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,5 ,5 ,5 ,8 , 8 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,8 , 8 ,0 ,0 ,0 ,0 ,0 ,0 ,6 ,0 ,0 ,0 ,6 ,0 ,0 ,8 , 8 ,5 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,5 ,5 ,5 ,8 , 8 ,5 ,0 ,0 ,5 ,5 ,5 ,5 ,5 ,5 ,0 ,5 ,5 ,5 ,8 , 8 ,5 ,0 ,0 ,5 ,5 ,5 ,5 ,5 ,5 ,0 ,5 ,5 ,5 ,8 , 8 ,0 ,0 ,0 ,0 ,5 ,5 ,5 ,5 ,5 ,0 ,0 ,0 ,0 ,8 , 8 ,0 ,0 ,1 ,0 ,5 ,5 ,9 ,5 ,5 ,2 ,0 ,0 ,0 ,8 , 8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ;map_all(map);/*初始化地图*/while(1) while(!kbhit()/*判断炮弹*/ if(enemynum=0|player_life=0)/*如果敌人数量为0,游戏结束。*/ goto aaa; for(i=0;i5;i+)/*循环判断每发炮弹*/ if(shooti.life=1)/*如果炮弹状态为活*/ judge_moveshootway(map,i);/*炮弹运动时判断炮弹方向函数*/delay(1500);num+;if(num=30)enemy_control(map);/*控制敌人运动*/num=0; key=bioskey(0);judge_tank_my(map,key);/*判断己方坦克运动函数*/ aaa: ;void map_all(int map1515)/*初始化地图函数*/int i,j;for(i=0;i15;i+)for(j=0;j15;j+)switch(mapji)case 0: break;case 5:map_wall(i,j);break;/*地形*/case 6:map_steel(i,j);break;case 7:map_water(i,j);break;case 8:map_border(i,j);break;case 9:map_base(i,j);break;uptank(3,13,1);uptank(10,13,GREEN);void allcircle(int i,int j)/*画坦克中圆圈的函数*/int x,y;x=30*i+15,y=30*j+15;arc(x+15,y+15, 90,180,8);arc(x+16,y+15, 0, 90,8);arc(x+15,y+16,180,270,8);arc(x+16,y+16,270,360,8);arc(x+15,y+15, 90,180,4);arc(x+16,y+15, 0, 90,4);arc(x+15,y+16,180,270,4);arc(x+16,y+16,270,360,4);void uptank(int i,int j,int color)/*画向上的坦克*/int x,y;x=30*i+15,y=30*j+15;setcolor(color);line(x+1,y+4,x+1,y+27);line(x+7,y+4,x+7,y+27);line(x+24,y+4,x+24,y+27);line(x+30,y+4,x+30,y+27);arc(x+4,y+4,0,180,3);arc(x+4,y+27,180,360,3);arc(x+27,y+4,0,180,3);arc(x+27,y+27,180,360,3);allcircle(i,j);setfillstyle(1,color);bar(x+14,y+1,x+17,y+15);void downtank(int i,int j,int color)/*画向下的坦克*/int x,y;x=30*i+15,y=30*j+15;setcolor(color);line(x+1,y+4,x+1,y+27);line(x+7,y+4,x+7,y+27);line(x+24,y+4,x+24,y+27);line(x+30,y+4,x+30,y+27);arc(x+4,y+4,0,180,3);arc(x+4,y+27,180,360,3);arc(x+27,y+4,0,180,3);arc(x+27,y+27,180,360,3);allcircle(i,j);line(x+14,y+16,x+14,y+30);line(x+15,y+16,x+15,y+30);line(x+16,y+16,x+16,y+30);line(x+17,y+16,x+17,y+30);void lef
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号