xuanyu an / Mbed 2 deprecated tankworld

Dependencies:   mbed N5110

Revision:
2:ce24c50fc0a6
Parent:
0:a9ef8a5c769a
diff -r 47967167a3a6 -r ce24c50fc0a6 main3.cpp
--- a/main3.cpp	Tue May 04 05:03:18 2021 +0000
+++ b/main3.cpp	Tue May 04 09:02:33 2021 +0000
@@ -1,327 +1,376 @@
 #include "mbed.h"
 #include "N5110.h"
-#include "main2.h"
 #include "main.h"
+#ifndef bullet_v
+#define bullet_v 3//炮弹的速度为坦克三倍
+#endif
+#ifndef tank_num
+#define tank_num 4//坦克数量
+#endif
 
-DigitalIn button_A4(p29);
-DigitalIn button_B4(p28);
-DigitalIn button_C4(p27);
-DigitalIn button_D4(p26);
-AnalogIn joy_v4(p20);
-AnalogIn joy_h4(p19);
-AnalogIn joy_button4(p17); // could be DigitalIn, but use AnalogIn so pot can also be used
-// JP1 must be in 2/3 position
-N5110 lcd4(p8,p9,p10,p11,p13,p21);
+DigitalIn button_A3(p29);
+DigitalIn button_B3(p28);
+DigitalIn button_C3(p27);
+DigitalIn button_D3(p26);
+
+AnalogIn joy_button3(p17); // could be DigitalIn, but use AnalogIn so pot can also be used
 
-const int map[9][11] = {
-{ 0,0,0,0,0,0,0,0,0,0,0},
-{ 0,1,0,2,1,1,1,2,0,1,0},
-{ 0,1,0,2,0,1,0,2,0,1,0},
-{ 0,0,0,0,0,0,0,0,0,0,0},
-{ 2,2,0,1,2,2,2,1,0,2,2},
-{ 0,0,0,0,0,0,0,0,0,0,0},
-{ 0,1,0,2,0,1,0,2,0,1,0},
-{ 0,1,0,2,1,1,1,2,0,1,0},
-{ 0,0,0,0,0,0,0,0,0,0,0},
-};//9*11⼤⼩的地图,1是墙,2是灌⽊
-const int wall[5][7] = {
-{ 1,1,1,1,1,1,1},
-{ 1,1,0,0,0,1,1},
-{ 1,1,0,0,0,1,1},
-{ 1,1,0,0,0,1,1},
-{ 1,1,1,1,1,1,1},
+// JP1 must be in 2/3 position
+N5110 lcd3(p8,p9,p10,p11,p13,p21);
+const int map[9][11] =   {
+    { 0,0,0,0,0,0,0,0,0,0,0},
+    { 0,1,0,2,1,1,1,2,0,1,0},
+    { 2,1,2,2,2,2,2,2,2,1,2},
+    { 0,0,0,0,0,0,0,0,0,0,0},
+    { 2,2,2,1,2,2,2,1,2,2,2},
+    { 0,0,1,1,1,1,1,1,1,0,0},
+    { 0,1,0,4,0,1,0,5,0,1,0},
+    { 0,1,2,2,1,1,1,2,2,1,0},
+    { 0,0,0,0,0,6,0,0,0,0,0},
+};//9*11大小的地图,1是墙,2是灌木
+const int wall[5][7] =   {
+    { 1,1,1,1,1,1,1},
+    { 1,1,0,0,0,1,1},
+    { 1,1,0,0,0,1,1},
+    { 1,1,0,0,0,1,1},
+    { 1,1,1,1,1,1,1},
 };//5*7的墙,不可破坏
-const int bush[5][7] = {
-{ 1,0,1,0,1,0,1},
-{ 0,1,0,1,0,1,0},
-{ 1,0,1,0,1,0,1},
-{ 0,1,0,1,0,1,0},
-{ 1,0,1,0,1,0,1},
-};//5*7的g灌⽊,可破坏
-const int destroyed_bush[5][7] = {
-{ 1,0,0,1,0,0,1},
-{ 0,0,1,0,0,1,0},
-{ 0,1,0,0,1,0,0},
-{ 1,0,0,1,0,0,1},
-{ 0,0,1,0,0,1,0},
-};//被击中的灌⽊
-const int tank1[4][5][7] =
-{
- {
-{ 0,1,0,1,0,1,0},
-{ 0,1,1,1,1,1,0},
-{ 0,1,1,0,1,1,0},
-{ 0,1,1,0,1,1,0},
-{ 0,1,0,0,0,1,0}
-},
-{
-{ 0,1,0,0,0,1,0},
-{ 0,1,1,0,1,1,0},
-{ 0,1,1,0,1,1,0},
-{ 0,1,1,1,1,1,0},
-{ 0,1,0,1,0,1,0}
-},
-{
-{ 0,1,1,1,1,1,0},
-{ 0,0,1,1,1,0,0},
-{ 0,1,1,0,0,0,0},
-{ 0,0,1,1,1,0,0},
-{ 0,1,1,1,1,1,0}},
-{
-{ 0,1,1,1,1,1,0},
-{ 0,0,1,1,1,0,0},
-{ 0,0,0,0,1,1,0},
-{ 0,0,1,1,1,0,0},
-{ 0,1,1,1,1,1,0}
-}
+const int bush[5][7] =   {
+    { 1,0,1,0,1,0,1},
+    { 0,1,0,1,0,1,0},
+    { 1,0,1,0,1,0,1},
+    { 0,1,0,1,0,1,0},
+    { 1,0,1,0,1,0,1},
+
+};//5*7的g灌木,可破坏
+const int destroyed_bush[5][7] =   {
+    { 1,0,0,1,0,0,1},
+    { 0,0,1,0,0,1,0},
+    { 0,1,0,0,1,0,0},
+    { 1,0,0,1,0,0,1},
+    { 0,0,1,0,0,1,0},
+
+};//被击中的灌木
+const int tank[tank_num][4][5][7] = {
+    {
+        {
+            { 0,1,0,1,0,1,0},
+            { 0,1,1,1,1,1,0},
+            { 0,1,1,0,1,1,0},
+            { 0,1,1,0,1,1,0},
+            { 0,1,0,0,0,1,0}
+        },
+        {
+            { 0,1,0,0,0,1,0},
+            { 0,1,1,0,1,1,0},
+            { 0,1,1,0,1,1,0},
+            { 0,1,1,1,1,1,0},
+            { 0,1,0,1,0,1,0}
+        },
+        {
+            { 0,1,1,1,1,1,0},
+            { 0,0,1,1,1,0,0},
+            { 0,1,1,0,0,0,0},
+            { 0,0,1,1,1,0,0},
+            { 0,1,1,1,1,1,0}
+        },
+        {
+            { 0,1,1,1,1,1,0},
+            { 0,0,1,1,1,0,0},
+            { 0,0,0,0,1,1,0},
+            { 0,0,1,1,1,0,0},
+            { 0,1,1,1,1,1,0}
+        }
+    },//tank1
+    {
+        {
+            { 0,1,0,1,0,1,0},
+            { 0,1,0,1,0,1,0},
+            { 0,1,1,1,1,1,0},
+            { 0,1,1,0,0,1,0},
+            { 0,1,0,0,0,1,0}
+
+        },
+        {
+            { 0,1,0,0,0,1,0},
+            { 0,1,0,0,1,1,0},
+            { 0,1,1,1,1,1,0},
+            { 0,1,0,1,0,1,0},
+            { 0,1,0,1,0,1,0}
+        },
+        {
+            { 0,1,1,1,1,1,0},
+            { 0,0,0,1,0,0,0},
+            { 0,1,1,1,0,0,0},
+            { 0,0,0,1,1,0,0},
+            { 0,1,1,1,1,1,0}
+        },
+        {
+            { 0,1,1,1,1,1,0},
+            { 0,0,1,1,0,0,0},
+            { 0,0,0,1,1,1,0},
+            { 0,0,0,1,0,0,0},
+            { 0,1,1,1,1,1,0}
+        }
+    },//tank2
+    {
+        {
+            { 0,1,0,1,0,1,0},
+            { 0,1,0,1,0,1,0},
+            { 0,1,1,1,1,1,0},
+            { 0,1,0,1,0,1,0},
+            { 0,1,0,0,0,1,0}
+
+        },
+        {
+            { 0,1,0,0,0,1,0},
+            { 0,1,0,1,0,1,0},
+            { 0,1,1,1,1,1,0},
+            { 0,1,0,1,0,1,0},
+            { 0,1,0,1,0,1,0}
+        },
+        {
+            { 0,1,1,1,1,1,0},
+            { 0,0,0,1,0,0,0},
+            { 0,1,1,1,1,0,0},
+            { 0,0,0,1,0,0,0},
+            { 0,1,1,1,1,1,0}
+        },
+        {
+            { 0,1,1,1,1,1,0},
+            { 0,0,0,1,0,0,0},
+            { 0,0,1,1,1,1,0},
+            { 0,0,0,1,0,0,0},
+            { 0,1,1,1,1,1,0}
+        }
+    }, //tank3
+    {
+        {
+            { 0,1,0,1,0,1,0},
+            { 0,1,0,1,0,1,0},
+            { 0,1,1,1,1,1,0},
+            { 0,1,0,0,1,1,0},
+            { 0,1,0,0,0,1,0}
+
+        },
+        {
+            { 0,1,0,0,0,1,0},
+            { 0,1,1,0,0,1,0},
+            { 0,1,1,1,1,1,0},
+            { 0,1,0,1,0,1,0},
+            { 0,1,0,1,0,1,0}
+        },
+        {
+            { 0,1,1,1,1,1,0},
+            { 0,0,0,1,1,0,0},
+            { 0,1,1,1,0,0,0},
+            { 0,0,0,1,0,0,0},
+            { 0,1,1,1,1,1,0}
+        },
+        {
+            { 0,1,1,1,1,1,0},
+            { 0,0,0,1,0,0,0},
+            { 0,0,0,1,1,1,0},
+            { 0,0,1,1,0,0,0},
+            { 0,1,1,1,1,1,0}
+        }
+    }//tank4
 };
-//四个⽅向的坦克1
-const int tank2[4][5][7] =
-{
+const int tank_exp[5][7] =   {
+    { 0,1,0,1,0,1,0},
+    { 0,0,1,0,1,0,0},
+    { 1,1,0,0,0,1,1},
+    { 0,0,1,0,1,0,0},
+    { 0,1,0,1,0,1,0},
+};//击毁的坦克
+const int bullet[5][7] =   {
+    { 0,0,0,0,0,0,0},
+    { 0,0,1,1,0,0,0},
+    { 0,0,1,1,0,0,0},
+    { 0,0,0,0,0,0,0},
+    { 0,0,0,0,0,0,0},
+};//炮弹
+const int hp_ai[5][7] =   {
+    { 0,1,1,0,1,1,0},
+    { 1,1,1,1,1,1,1},
+    { 0,1,1,1,1,1,0},
+    { 1,0,1,1,1,0,1},
+    { 1,1,0,1,0,1,1},
+};//炮弹
+const int t_start[tank_num][2] = {{0,5},{6,3},{6,7},{8,5}}; //坦克初始坐标
+void map_scan3(int map_adj[9][11]) //扫描地图函数
 {
-{ 0,1,0,1,0,1,0},
-{ 0,1,0,1,0,1,0},
-{ 0,1,1,1,1,1,0},
-{ 0,1,0,0,0,1,0},
-{ 0,1,0,0,0,1,0}
-},
-{
-{ 0,1,0,0,0,1,0},
-{ 0,1,0,0,0,1,0},
-{ 0,1,1,1,1,1,0},
-{ 0,1,0,1,0,1,0},
-{ 0,1,0,1,0,1,0}
-},
-{
-{ 0,1,1,1,1,1,0},
-{ 0,0,0,1,0,0,0},
-{ 0,1,1,1,0,0,0},
-{ 0,0,0,1,0,0,0},
-{ 0,1,1,1,1,1,0}
-},
- {
-{ 0,1,1,1,1,1,0},
-{ 0,0,0,1,0,0,0},
-{ 0,0,0,1,1,1,0},
-{ 0,0,0,1,0,0,0},
-{ 0,1,1,1,1,1,0}
+    int x = 0;
+    int y = 0; //地图扫描坐标
+    lcd3.drawRect(0,0,84,1,FILL_BLACK);
+    lcd3.drawRect(0,46,84,2,FILL_BLACK);
+    lcd3.drawRect(0,0,3,48,FILL_BLACK);
+    lcd3.drawRect(80,0,4,48,FILL_BLACK);//边框
+
+    for (x=0; x<11; x++) {
+        for (y=0; y<9; y++) {
+            if(map_adj[y][x]==1) {
+                lcd3.drawSprite(x*7+3,y*5+1,5,7,(int *)wall);
+            } else if(map_adj[y][x]==2) {
+                lcd3.drawSprite(x*7+3,y*5+1,5,7,(int *)bush);
+            }
+        }
+    }
 }
-};//四个⽅向的坦克2
-const int tank_exp[5][7] = {
-{ 0,1,0,1,0,1,0},
-{ 0,0,1,0,1,0,0},
-{ 1,1,0,0,0,1,1},
-{ 0,0,1,0,1,0,0},
-{ 0,1,0,1,0,1,0},
-};//击毁的坦克
-const int heart[5][7] = {
-{ 0,1,1,0,1,1,0},
-{ 1,1,1,1,1,1,1},
-{ 0,1,1,1,1,1,0},
-{ 1,0,1,1,1,0,1},
-{ 1,1,0,1,0,1,1},
-};//⾎量的⼼形
-const int bullet[5][7] = {
-{ 0,0,0,0,0,0,0},
-{ 0,0,1,1,0,0,0},
-{ 0,0,1,1,0,0,0},
-{ 0,0,0,0,0,0,0},
-{ 0,0,0,0,0,0,0},
-};//炮弹
-const int bullet_v=3;//炮弹的速度为坦克三倍
-const int tank_num=2;//坦克数量
-const int t_start[2][2] = {{0,5},{8,5}}; //坦克初始坐标
-void map_scan4(int map_adj[9][11]){//扫描地图函数
-int x = 0;
-int y = 0; //地图扫描坐标
-lcd4.drawRect(0,0,84,1,FILL_BLACK);
-lcd4.drawRect(0,46,84,2,FILL_BLACK);
-lcd4.drawRect(0,0,3,48,FILL_BLACK);
-lcd4.drawRect(80,0,4,48,FILL_BLACK);//边框
-for (x=0;x<11;x++){
-for (y=0;y<9;y++){
-if(map_adj[y][x]==1){
-lcd4.drawSprite(x*7+3,y*5+1,5,7,(int *)wall);
+
+void hp_show3(int hp[4])  //显示血量函数
+{
+    int i;
+    for(i=1; i<tank_num; i++) {
+        if(hp[i]==1) {
+            lcd3.drawSprite(4*7+(i-1)*7+3,7*5+1,5,7,(int *)hp_ai);
+        }
+
+    }
 }
-else if(map_adj[y][x]==2){
-lcd4.drawSprite(x*7+3,y*5+1,5,7,(int *)bush);
-}
-}
-}
- }
-void hp_show4(int hp1,int hp2){//显示⾎量函数
-int heart_num=0;
-for (heart_num=0;heart_num<3;heart_num++){
-if(heart_num<hp1){
-lcd4.drawSprite(4*7+heart_num*7+3,5*1+1,5,7,(int *)heart);
+void tank_show3(int tank_state[4],int t[4][2],int hp[4])   //显示坦克函数
+{
+    int i;
+    for(i=0; i<tank_num; i++) {
+        if(hp[i]!=0) {
+            lcd3.drawSprite(t[i][1]*7+3,t[i][0]*5+1,5,7,(int *)tank[i][tank_state[i]]);
+        }
+    }
 }
-if(heart_num<hp2){
-lcd4.drawSprite(4*7+heart_num*7+3,7*5+1,5,7,(int *)heart);
-}
-}
-}
-void tank_show4(int tank1_state,int tank2_state,int t1[2],int t2[2]){//显示坦克函数
-lcd4.drawSprite(t1[1]*7+3,t1[0]*5+1,5,7,(int *)tank1[tank1_state]);
-lcd4.drawSprite(t2[1]*7+3,t2[0]*5+1,5,7,(int *)tank2[tank2_state]);
-}
-void init_buttons4();
-
 void main3()
 {
-// need to initialise the lcd first, do this once outside of the loop
-lcd4.init();
-int command[2][4]={{0,0,0,0},{0,0,0,0}};//处理后的指令
-int i = 0;
-int j = 0; //地图复制计数
-int ii = 0;
-int ji = 0;//坦克初始坐标复制计数
-int n = 0; //炮弹刷新计数
-int shoot = 0;//开⽕计数
-int t[tank_num][2]; //坦克坐标
-int b[tank_num][3][2]; //炮弹坐标
-int bullet_cont=0;//发射炮弹计数
-int bullet_direct[tank_num][3];//炮弹的⽅向
-int bullet_val[tank_num][3];//炮弹是否被阻挡
-int tank_state[tank_num]={0,0}; //坦克的f⽅向
-int hp[tank_num] ={3,3}; //坦克⾎量
-int tank_count;//坦克单位的计数
-int map_adj[9][11];
-for (i=0;i<11;i++){
-for (j=0;j<9;j++){
-map_adj[j][i]=map[j][i];
-}
-}//复制地图
-for (ii=0;ii<2;ii++){
-for (ji=0;ji<2;ji++){
-t[ji][ii]=t_start[ji][ii];
-}
-} //复制指令
-//welcome();
-while(1) {
-lcd4.clear();
-map_scan4(map_adj);//地图显示
-hp_show4(hp[0],hp[1]);//⾎量显示
-tank_show4(tank_state[0],tank_state[1],t[0],t[1]);//坦克显示
-if(shoot==0){
-command[0][3] = button_A4.read();
-command[0][0] = button_B4.read();
-command[0][2] = button_C4.read();
-command[0][1] = button_D4.read(); //复制指令
-if(joy_h4.read()<0.3){
-command[1][0] = 0;
-command[1][1] = 0;
-command[1][2] = 0;
-command[1][3] = 1;
-}
-else if(joy_h4.read()>0.7){
-command[1][0] = 0;
-command[1][1] = 0;
-command[1][2] = 1;
-command[1][3] = 0;
-}
-else if(joy_v4.read()<0.3){
-command[1][0] = 0;
-command[1][1] = 1;
-command[1][2] = 0;
-command[1][3] = 0;
-}
-else if(joy_v4.read()>0.7){
-command[1][0] = 1;
-command[1][1] = 0;
-command[1][2] = 0;
-command[1][3] = 0;
-}
- else{
-command[1][0] = 0;
-command[1][1] = 0;
-command[1][2] = 0;
-command[1][3] = 0;
-}
-bullet_cont++;
-if(bullet_cont==3){
-bullet_cont=0;
+    // need to initialise the lcd3 first, do this once outside of the loop
+    lcd3.init();
+    //int command[2][4]={{0,0,0,0},{0,0,0,0}};//处理后的指令
+    int command[4]= {0,0,0,0};
+    int i;
+    int j; //地图复制计数
+    int ii;
+    int k;
+    int l;
+    int n; //炮弹刷新计数
+    int shoot;//开火计数
+    int t[tank_num][2]; //坦克坐标
+    int b[3][2]; //炮弹坐标
+    int bullet_cont=0;//发射炮弹计数
+    int bullet_direct[3];//炮弹的方向
+    int bullet_val[3];//炮弹是否被阻挡
+    int tank_state[tank_num]; //坦克的f方向
+    int hp_set[tank_num]= {3,1,1,1}; //坦克血量预设
+    int hp[tank_num]= {0,0,0,0}; //坦克血量
+    int map_adj[9][11];
+    int tank_des;//serial number of destoried tank destroy
+    int obj_kind;
+    for (k=0; k<tank_num; k++) {
+        hp[k]=hp_set[k];
+        tank_state[k]=0;
+        map_adj[t_start[k][0]][t_start[k][1]]=k+3;
+        for (l=0; l<bullet_v; l++) {
+            bullet_val[l]=0;
+        }
+        for (ii=0; ii<2; ii++) {
+            t[k][ii]=t_start[k][ii];
+        } //复制坦克坐标
+    }
+
+    for (i=0; i<11; i++) {
+        for (j=0; j<9; j++) {
+            map_adj[j][i]=map[j][i];
+        }
+    }//复制地图
+    shoot=0;
+    while(1) {
+        lcd3.clear();
+        map_scan3(map_adj);//地图显示
+        hp_show3(hp);//血量显示
+        tank_show3(tank_state,t,hp);//坦克显示
+
+        if(shoot==0) {
+            command[3] = button_A3.read();
+            command[0] = button_B3.read();
+            command[2] = button_C3.read();
+            command[1] = button_D3.read(); //复制指令
+            bullet_cont++;
+            if(bullet_cont==3) {
+                bullet_cont=0;
+            }
+
+
+            command[3]=(~command[0])&(~command[1])&(~command[2])&command[3];
+            command[2]=(~command[0])&(~command[1])&command[2];
+            command[1]=(~command[0])&command[1];
+            command[0]=command[0];
+
+            map_adj[t[0][0]][t[0][1]]=0;
+            t[0][0]=t[0][0]-command[0]+command[1];
+            t[0][1]=t[0][1]-command[2]+command[3];//指令控制坦克
+
+            if(map_adj[t[0][0]][t[0][1]]!=0||t[0][1]<0||t[0][1]>10||t[0][0]<0||t[0][0]>8) {
+                t[0][0]=t[0][0]+command[0]-command[1];
+                t[0][1]=t[0][1]+command[2]-command[3];
+            }//障碍物判断,前方有障碍物时指令无效
+            map_adj[t[0][0]][t[0][1]]=3;
+            if(command[0]||command[1]||command[2]||command[3]) {
+                tank_state[0]=command[1]*1+command[2]*2+command[3]*3;
+            } //坦克方向计算
+            if (joy_button3.read()==0) {
+                bullet_val[bullet_cont]=1; //坦克发射炮弹技炮弹坐标方向计算
+                bullet_direct[bullet_cont]=tank_state[0];
+                b[bullet_cont][0]=t[0][0];
+                b[bullet_cont][1]=t[0][1];
+            }
+        }
+
+        for(n=0; n<bullet_v; n++) { //炮弹比坦克快三倍运算也快三倍
+            b[n][0]=b[n][0]+(!(bullet_direct[n]>>1))*(-1+2*(bullet_direct[n]%2));
+            b[n][1]=b[n][1]+(bullet_direct[n]>>1)*(-1+2*(bullet_direct[n]%2));//炮弹坐标刷新
+            if(b[n][1]>=0&&b[n][1]<=10&&b[n][0]>=0&&b[n][0]<=8&&bullet_val[n]==1) {
+                //炮弹有效且未出界
+                obj_kind=map_adj[b[n][0]][b[n][1]];
+                if(obj_kind==0) { //炮弹无障碍飞行的情况
+                    lcd3.drawSprite(b[n][1]*7+3,b[n][0]*5+1,5,7,(int *)bullet);
+                } else if (obj_kind==2) { //炮弹打到灌木的情况
+                    lcd3.drawSprite(b[n][1]*7+3,b[n][0]*5+1,5,7,(int *)destroyed_bush);
+                    map_adj[b[n][0]][b[n][1]]=0;
+                    bullet_val[n]=0;
+                } else if (obj_kind==1) { //炮弹打墙的情况
+                    bullet_val[n]=0;
+                } else if(obj_kind>3) { //炮弹击杀坦克的情况
+                    lcd3.printString("1", 0, 0);
+                    tank_des=map_adj[b[n][0]][b[n][1]]-3;
+                    map_adj[b[n][0]][b[n][1]]=0;
+                    lcd3.drawSprite(t[tank_des][1]*7+3,t[tank_des][0]*5+1,5,7,(int *)tank_exp);
+                    hp[tank_des]=hp[tank_des]-1;//血量减一
+                    bullet_val[n]=0;//炮弹失效
+                    if((hp[1]+hp[2]+hp[3])==0) {
+                        lcd3.clear();
+                        lcd3.printString("Exercise", 20, 1);
+                        lcd3.printString("Completed", 18, 3);
+                        lcd3.refresh();
+                        wait(1);
+                        while(1) {
+                            if (button_C3.read() == 1) {
+                                main();
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        shoot=shoot+1;
+        if(shoot==bullet_v) {
+            shoot=0;
+        }
+        lcd3.refresh(); // refresh the lcd3 so the pixels appear
+        wait_ms(600/bullet_v); // 画面按炮弹移动s时间刷新,600为坦克移动时间
+    }
 }
-/* turn=turn+1;
-if(turn==15){
-turn=0;
-}//各种计数*/
-for(tank_count=0;tank_count<tank_num;tank_count++) {
-t[tank_count][0]=t[tank_count][0]-command[tank_count][0]+command[tank_count][1];
-t[tank_count][1]=t[tank_count][1]-command[tank_count][2]+command[tank_count][3];
-//指令控制坦克
-if(map_adj[t[tank_count][0]][t[tank_count][1]]!=0||t[tank_count][1]<0||t[tank_count][1]>10||
-t[tank_count][0]<0||t[tank_count][0]>8){
-t[tank_count][0]=t[tank_count][0]+command[tank_count][0]-command[tank_count][1];
-t[tank_count][1]=t[tank_count][1]+command[tank_count][2]-command[tank_count][3];
-}//障碍物判断,前⽅有障碍物时指令⽆效
-if(command[tank_count][0]||command[tank_count][1]||command[tank_count][2]||
-command[tank_count][3]){
-tank_state[tank_count]=command[tank_count][1]*1+command[tank_count]
-[2]*2+command[tank_count][3]*3;
-} //坦克⽅向计算
-bullet_direct[tank_count][bullet_cont]=tank_state[tank_count];
-if (joy_button4.read()==0 && tank_count ==1 ){
-//pot_val = pot0.read();
-b[tank_count][bullet_cont][0]=t[tank_count][0];
-b[tank_count][bullet_cont][1]=t[tank_count][1];}
-bullet_val[tank_count][bullet_cont]=1; //坦克发射炮弹技炮弹坐标⽅向计算
-}
+void init_buttons3()
+{
+    // PCB has external pull-down resistors so turn the internal ones off
+    // (default for DigitalIn)
+    button_A3.mode(PullNone);
+    button_B3.mode(PullNone);
+    button_C3.mode(PullNone);
+    button_D3.mode(PullNone);
 }
-for(tank_count=0;tank_count<tank_num;tank_count++) {//游戏⾥坦克依次进⾏运算
-for(n=0;n<bullet_v;n++){//炮弹⽐坦克快三倍运算也快三倍
-b[tank_count][n][0]=b[tank_count][n][0]+(!(bullet_direct[tank_count]
-[n]>>1))*(-1+2*(bullet_direct[tank_count][n]%2));
-b[tank_count][n][1]=b[tank_count][n][1]+(bullet_direct[tank_count]
-[n]>>1)*(-1+2*(bullet_direct[tank_count][n]%2));//炮弹坐标刷新
-if(b[tank_count][n][1]>=0&&b[tank_count][n][1]<=10&&b[tank_count][n]
-[0]>=0&&b[tank_count][n][0]<=8&&bullet_val[tank_count][n]==1){
- //炮弹有效且未出界
-if(b[tank_count][n][1]==t[!tank_count][1]&&b[tank_count][n][0]==t[!tank_count][0]){//炮弹击杀坦克的情况
-lcd4.drawSprite(t[!tank_count][1]*7+3,t[!tank_count][0]*5+1,5,7,(int *)tank_exp);
-t[!tank_count][0]=t_start[!tank_count][0];
-t[!tank_count][1]=t_start[!tank_count][1];//坦克回出⽣点
-hp[!tank_count]=hp[!tank_count]-1;//⾎量减⼀
-if (hp[!tank_count]==0){
-lcd4.clear();
-lcd4.printString("Game Over", 15, 2);
-lcd4.refresh();
-while(1){
-if (button_C4.read() == 1) {
-main();
-}
-}
-}
-bullet_val[tank_count][n]=0;//炮弹失效
-}
-else if(map_adj[b[tank_count][n][0]][b[tank_count][n][1]]==0){//炮弹⽆障碍⻜⾏的情况
-lcd4.drawSprite(b[tank_count][n][1]*7+3,b[tank_count][n][0]*5+1,5,7,(int *)bullet);
-}
-else if (map_adj[b[tank_count][n][0]][b[tank_count][n][1]]==2){//炮弹打到灌⽊的情况
-lcd4.drawSprite(b[tank_count][n][1]*7+3,b[tank_count][n][0]*5+1,5,7,(int
-*)destroyed_bush);
-map_adj[b[tank_count][n][0]][b[tank_count][n][1]]=0;
-bullet_val[tank_count][n]=0;
-}
-else if (map_adj[b[tank_count][n][0]][b[tank_count][n][1]]==1){//炮弹打墙的情况
-bullet_val[tank_count][n]=0;
-}
-}
-}
-}
-shoot=shoot+1;
-if(shoot==bullet_v){
-shoot=0;
-}
-lcd4.refresh(); // refresh the LCD so the pixels appear
-wait_ms(600/bullet_v); // 画⾯按炮弹移动时间刷新,600为坦克移动时间
-}
-}
-void init_buttons4()
-{
-// PCB has external pull-down resistors so turn the internal ones off
-// (default for DigitalIn)
-button_A4.mode(PullNone);
-button_B4.mode(PullNone);
-button_C4.mode(PullNone);
-button_D4.mode(PullNone);
-}
\ No newline at end of file