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,0 ,0 ,8 }, {8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 ,8 }};
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)
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 },/*初始化地图
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;
} 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)/
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);
{ setfilshoot[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++;
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++; }
} 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)/
} 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) {
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}};
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--;
#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;
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 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);
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].
相关主题