C语言的坦克大战源码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
if(shoot[i].life!=0) { setfillstyle(1,1); bar(shoot[i].x+
35,shoot[i].y+14,shoot[i].x+32,shoot[i].y+17);setcolor(7); line(shoot[i].x+
31,shoot[i].y+14,shoot[i].x+31,shoot[i].y+17); shoot[i].x++;
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 blank(int i,int j);
} else
{ setfillstyle(1,get
pixel(shoot[i].x+14,shoot[i].y-6)); bar(shoot[i].x+
14,shoot[i].y-5,shoot[i].x+17,shoot[i].y-1); }
break; case DOWNWAY:
if((shoot[i].y-15)%30==0) if(map[(shoot[i].y-15)/
} else
{ setfillstyle(1,get
pixel(shoot[i].x+14,shoot[i].y+36)); bar(shoot[i].x+
14,shoot[i].y+35,shoot[i].x+17,shoot[i].y+31); }
break; case LEFTWAY:
if((shoot[i].x-15)%30==0) if(map[(shoot[i].y-15)/
struct ENEMY /*定义敌人结构体*/ {
int life; int x,y; int i,j;
int way; int control; }enemy[5]={{1,0,0,1,1,DOWNWAY,0},{1,0,0,1,2,DOWNWAY,0},{1,0,0,1,3,DOWNWAY,0}, {1,0,0,1,4,DOWNWAY,0},{1,0,0,1,5,DOWNWAY,0}};
} else
{ setfillstyle(1,get
pixel(shoot[i].x-6,shoot[i].y+14)); bar(shoot[i].x-5,
shoot[i].y+14,shoot[i].x-1,shoot[i].y+17); }
break; case RIGHTWAY:
if((shoot[i].x-15)%30==0) if(map[(shoot[i].y-15)/
if(shoot[i].life!=0) { setfillstyle(1,1); bar(shoot[i].x+
14,shoot[i].y-5,shoot[i].x+17,shoot[i].y-2); setcolor(7); line(shoot[i].x+
14,shoot[i].y-1,shoot[i].x+17,shoot[i].y-1); shoot[i].y--;
void end();
main() {
start(); play(); end(); } void start() {
int i; int driver=VGA,mode=VGAHI;/*初始化图形模式*/ initgraph(&driver,&mode,"");
setbkcolor(7);/*设定背景*/ settextstyle(4,0,0); outtextxy(500,300,"made"); outtextxy(540,300,"by"); outtextxy(562,300,"lihaifei"); while(!kbhit()) { setcolor(i); settextstyle(0,0,10); outtextxy(150,100,"TANK"); i++; }
30-1][(shoot[i].x-15)/30]!=0) { shoot[i].
life=0; control_
shoot(map[(shoot[i].y-15)/30-1][(shoot[i].x-15)/30],map,i); }
if(shoot[i].y<47) shoot[i].life=0;
struct SHOOT /*定义炮弹结构体*/ {
int life; int x,y; int way; }shoot[2]={{0,0,0,UPWAY},{0,0,0,UPWAY}};
struct PLAYER /*定义玩家结构体*/ {
int life; int x,y; int i,j; int way; }player[2]={{3,0,0,3,13,UPWAY},{3,0,0,10,13,UPWAY}};
{8 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,8 }, {8 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,8 }, {8 ,0 ,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 }};
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);
{ setfillstyle(1,1); bar(shoot[i].x+
14,shoot[i].y+35,shoot[i].x+17,shoot[i].y+32);setcolor(7); line(shoot[i].x+
14,shoot[i].y+31,shoot[i].x+17,shoot[i].y+31); shoot[i].y++;
30][(shoot[i].x-15)/30+1]!=0) { shoot[i].
life=0; control_
shoot(map[(shoot[i].y-15)/30][(shoot[i].x-15)/30+1],map,i); }
if(shoot[i].x>405) shoot[i].life=0;
/*声明区*/ void allcircle(int i,int j); vቤተ መጻሕፍቲ ባይዱid start(); void play();
void map_all(int map[15][15]); void control_shoot(int m,int map[15][15],int i); void enemy_control(int map[15][15]);
getch(); cleardevice(); getch();
} void play() {
int key;int i;int num=0; int map[15][15]={ 数组*/
map_all(map); while(1) {
{8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 },/*初始化地图
while(!kbhit())/*判断炮弹*/ {
if(enemynum==0) goto aaa;
for(i=0;i<2;i++) if(shoot[i].life==1) switch(shoot[i].way) { case UPWAY : if((shoot[i].y-15)%30==0) if(map[(shoot[i].y-15)/
enemy_control(map);/*敌人坦克运动*/ num=0; } }
key=bioskey(0); switch(key)/*判断坦克*/ { case a_UP: if(map[player[0].j-1][player[0].i]==0) { if(player[0].way==UPWAY) { map[player[0].j][playe
30][(shoot[i].x-15)/30-1]!=0) { shoot[i].
life=0; control_
shoot(map[(shoot[i].y-15)/30][(shoot[i].x-15)/30-1],map,i); }
if(shoot[i].x<47) shoot[i].life=0;
#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 4 int enemynum=3;
} else
{ setfillstyle(1,get
pixel(shoot[i].x+36,shoot[i].y+14)); bar(shoot[i].x+
35,shoot[i].y+14,shoot[i].x+31,shoot[i].y+17); }
break; } delay(1500);num++; if(num==30) {
if(shoot[i].life!=0) { setfillstyle(1,1); bar(shoot[i].x-5,
shoot[i].y+14,shoot[i].x-2,shoot[i].y+17);setcolor(7); line(shoot[i].x-1,
shoot[i].y+14,shoot[i].x-1,shoot[i].y+17); shoot[i].x--;
30+1][(shoot[i].x-15)/30]!=0) { shoot[i].
life=0;
control_ shoot(map[(shoot[i].y-15)/30+1][(shoot[i].x-15)/30],map,i);
} if(shoot[i].y>405)
shoot[i].life=0; if(shoot[i].life!=0)
/* 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
相关文档
最新文档