C-language simple version tank war (allenenemytrank file)

Source: Internet
Author: User

AllenEnemyTrank.h

typedef struct enemytrank{int x, y;//my tank Center coordinates int m, n;//my tank bullets coordinates int state;//my Tank direction (1, 2, 3 left, 4 right) int dir;/  /My tank bullets fired at int life;//life int skin;//Skin int weapons;//weapon int lv;//level int speed;//speed//color char    Color Do you want to clear int clear;} Enemytrank, *penemytrank;void init_enemy_tank (Penemytrank myenemytrank,int x, int y);//print tank void Print_enemy_tank ( Enemytrank myenemytrank);//clear tank void Clear_enemy_tank (Enemytrank myenemytrank); void Enemytankmove (Penemytrank Myenemytrank); int Enemychangedir (Penemytrank myenemytrank,char cdir);//whether near home int canenemymove (Penemytrank Myenemytrank); extern enemytrank Myenemytrank;extern enemytrank myenemytrank1;extern enemytrank MyEnemyTrank2;extern Enemytrank myenemytrank3;extern enemytrank myenemytrank4;extern enemytrank myenemytrank5;extern EnemyTrank Myenemytrank6;extern enemytrank myenemytrank7;extern enemytrank myenemytrank8;extern EnemyTrank MyEnemyTrank9;extern Enemytrank myenemytrank10;//detects if the user has encountered a tank or bullet void ENEMYTRanklife (Penemytrank Myusertrank); 

Allenenemytrank.c

#include "AllenUserTrank.h" #include "AllenEnemyTrank.h" #include "Allendraw.h" #include <stdio.h> #include <  windows.h> #include <conio.h>void init_enemy_tank (penemytrank myenemytrank,int x, int y) {myenemytrank->x =    X    Myenemytrank->y = y;    Myenemytrank->dir = Tank_dir_dw;    Myenemytrank->life = 20;    Myenemytrank->color = 0x5;    Set Tank Center G_map[x][y] = enetankmap in geographical coordinates; Print_enemy_tank (*myenemytrank);} void Print_enemy_tank (Enemytrank myuse) {switch (myuse.dir) {case Tank_dir_lf:if ((myuse.x + 1) = = 18        ) break;            if (g_map[myuse.x][myuse.y] = = Caomap) {} else {Printchar (myuse.x, Myuse.y, Usertank, 0x5);        G_MAP[MYUSE.X][MYUSE.Y] = Enetankmap;        }///////////////////////////////////////////////////////////if (g_map[myuse.x][myuse.y-1] = = CAOMAP) {}            else {Printchar (myuse.x, Myuse.y-1, Usertank, 0x5); G_MAP[MYUSE.X][MYUSE.Y-1] = EnetankMAP;        }///////////////////////////////////////////////////////////if (g_map[myuse.x-1][myuse.y] = = CAOMAP) {}            else {Printchar (myuse.x-1, Myuse.y, Usertank, 0x5);        G_MAP[MYUSE.X-1][MYUSE.Y] = Enetankmap;        }///////////////////////////////////////////////////////////if (g_map[myuse.x][myuse.y + 1] = = CAOMAP) {}            else {Printchar (myuse.x, Myuse.y + 1, Usertank, 0x5);        G_map[myuse.x][myuse.y + 1] = Enetankmap;  }///////////////////////////////////////////////////////////if (g_map[myuse.x + 1][myuse.y-1] = = CAOMAP)            {} else {Printchar (myuse.x + 1, myuse.y-1, Usertank, 0x5);        G_map[myuse.x + 1][myuse.y-1] = Enetankmap;  }///////////////////////////////////////////////////////////if (g_map[myuse.x + 1][myuse.y + 1] = = CAOMAP)         {} else {Printchar (myuse.x + 1, myuse.y + 1, Usertank, 0x5);   g_map[myuse.x + 1][myuse.y + 1] = Enetankmap;        }///////////////////////////////////////////////////////////if (g_map[myuse.x + 1][myuse.y] = = CAOMAP) {}            else {Printchar (myuse.x + 1, myuse.y, TANKLF, 0x5);        G_map[myuse.x + 1][myuse.y] = Enetankmap;    }///////////////////////////////////////////////////////////break;        Case Tank_dir_rh:if ((myuse.x + 1) = =) break;            if (g_map[myuse.x][myuse.y] = = Caomap) {} else {Printchar (myuse.x, Myuse.y, Usertank, 0x5);        G_MAP[MYUSE.X][MYUSE.Y] = Enetankmap;        }///////////////////////////////////////////////////////////if (g_map[myuse.x + 1][myuse.y] = = CAOMAP) {}            else {Printchar (myuse.x + 1, myuse.y, Usertank, 0x5);        G_map[myuse.x + 1][myuse.y] = Enetankmap; }///////////////////////////////////////////////////////////if (g_map[myuse.x][myuse.y-1] = = CAOMAP){} else {Printchar (myuse.x, Myuse.y-1, Usertank, 0x5);        G_map[myuse.x][myuse.y-1] = Enetankmap;        }///////////////////////////////////////////////////////////if (g_map[myuse.x][myuse.y + 1] = = CAOMAP) {}            else {Printchar (myuse.x, Myuse.y + 1, Usertank, 0x5);        G_map[myuse.x][myuse.y + 1] = Enetankmap;  }///////////////////////////////////////////////////////////if (g_map[myuse.x-1][myuse.y-1] = = CAOMAP)            {} else {Printchar (myuse.x-1, Myuse.y-1, Usertank, 0x5);        G_map[myuse.x-1][myuse.y-1] = Enetankmap;  }///////////////////////////////////////////////////////////if (g_map[myuse.x-1][myuse.y + 1] = = CAOMAP)            {} else {Printchar (myuse.x-1, Myuse.y + 1, Usertank, 0x5);        G_map[myuse.x-1][myuse.y + 1] = Enetankmap;       }        /////////////////////////////////////////////////////////// if (g_map[myuse.x-1][myuse.y] = = Caomap) {} else {Printchar (myuse.x-1, Myuse.y, TANKRH, 0x5);        G_MAP[MYUSE.X-1][MYUSE.Y] = Enetankmap;    } break; Case Tank_dir_up:if (g_map[myuse.x][myuse.y] = = Caomap) {} else {Printchar (myuse.x, Myuse.y, US            Ertank, 0x5);        G_MAP[MYUSE.X][MYUSE.Y] = Enetankmap;        }//////////////////////////////////////////////////////////if (g_map[myuse.x][myuse.y-1] = = CAOMAP) {            } else {Printchar (myuse.x, Myuse.y-1, Usertank, 0x5);        G_map[myuse.x][myuse.y-1] = Enetankmap; }/////////////////////////////////////////////////////////////if (g_map[myuse.x + 1][myuse.y + 1] = = CAOMA            P) {} else {Printchar (myuse.x + 1, myuse.y + 1, Usertank, 0x5);        g_map[myuse.x + 1][myuse.y + 1] = Enetankmap; }/////////////////////////////////////////////////////////////If (g_map[myuse.x + 1][myuse.y] = = Caomap)            {} else {Printchar (myuse.x + 1, myuse.y, Usertank, 0x5);        G_map[myuse.x + 1][myuse.y] = Enetankmap; }/////////////////////////////////////////////////////////////if (g_map[myuse.x][myuse.y-1] = = CAOMAP) {            } else {Printchar (myuse.x, Myuse.y-1, Usertank, 0x5);        G_map[myuse.x][myuse.y-1] = Enetankmap;        }///////////////////////////////////////////////////////////if (g_map[myuse.x-1][myuse.y] = = CAOMAP) {}            else {Printchar (myuse.x-1, Myuse.y, Usertank, 0x5);        G_MAP[MYUSE.X-1][MYUSE.Y] = Enetankmap;  }///////////////////////////////////////////////////////////if (g_map[myuse.x-1][myuse.y + 1] = = CAOMAP)            {} else {Printchar (myuse.x-1, Myuse.y + 1, Usertank, 0x5);        G_map[myuse.x-1][myuse.y + 1] = Enetankmap; }        ///////////////////////////////////if (g_map[myuse.x][myuse.y + 1] = = Caomap) {} else {Printchar (myuse.x,            Myuse.y + 1, tankup, 0x5);        G_map[myuse.x][myuse.y + 1] = Enetankmap;    } break;        Case Tank_dir_dw:if ((myuse.y + 1) = =) break;            if (g_map[myuse.x][myuse.y] = = Caomap) {} else {Printchar (myuse.x, Myuse.y, Usertank, 0x5);        G_MAP[MYUSE.X][MYUSE.Y] = Enetankmap;        }///////////////////////////////////////////////////////////if (g_map[myuse.x-1][myuse.y] = = CAOMAP) {}            else {Printchar (myuse.x-1, Myuse.y, Usertank, 0x5);        G_MAP[MYUSE.X-1][MYUSE.Y] = Enetankmap;  }///////////////////////////////////////////////////////////if (g_map[myuse.x-1][myuse.y-1] = = CAOMAP)            {} else {Printchar (myuse.x-1, Myuse.y-1, Usertank, 0x5);        G_map[myuse.x-1][myuse.y-1] = Enetankmap; }        //////////if (g_map[myuse.x][myuse.y + 1] = = Caomap) {} else {            Printchar (myuse.x, Myuse.y + 1, Usertank, 0x5);        G_map[myuse.x][myuse.y + 1] = Enetankmap;        }///////////////////////////////////////////////////////////if (g_map[myuse.x + 1][myuse.y] = = CAOMAP) {}            else {Printchar (myuse.x + 1, myuse.y, Usertank, 0x5);        G_map[myuse.x + 1][myuse.y] = Enetankmap;  }///////////////////////////////////////////////////////////if (g_map[myuse.x + 1][myuse.y-1] = = CAOMAP)            {} else {Printchar (myuse.x + 1, myuse.y-1, Usertank, 0x5);        G_map[myuse.x + 1][myuse.y-1] = Enetankmap;         }/////////////////////////////////////////////////////////////if (g_map[myuse.x][myuse.y-1] = = CAOMAP) {            } else {Printchar (myuse.x, Myuse.y-1, TANKDW, 0x5); G_MAP[MYUSE.X][MYUSE.Y-1]= Enetankmap;    } break;    Default:break; }}//Clear tank void Clear_enemy_tank (Enemytrank myenemytrank) {for (int i = myenemytrank.x-1; I <= myenemytrank.x + 1; i  + +) {for (int j = myenemytrank.y-1; J <= myenemytrank.y + 1; j + +) {if (g_map[i][j] = = Enetankmap)                {Printchar (I, J, "", 0x00);            G_MAP[I][J] = = KONG;    }}}}void Enemytankmove (Penemytrank myenemytrank) {enemytranklife (Myenemytrank);    if (Canenemymove (Myenemytrank)) return; if ((myenemytrank->x) > 2 && (myenemytrank->x) <=36 && (myenemytrank->y) >=3 & & (Myenemytrank->y) <=36&& myenemytrank->life >0) {//Clean all Clear_enemy_tank (*myene        Mytrank);        Regenerate//g_map[myenemytrank->x][myenemytrank->y] = Enetankmap;            Switch (myenemytrank->dir) {case tank_dir_up:myenemytrank->y--;        Break Case Tank_dir_dw:myenemytrank->y++;        Break            Case tank_dir_lf:myenemytrank->x--;        Break            Case tank_dir_rh:myenemytrank->x++;        Break        }//give tank a new direction Myenemytrank->dir = myenemytrank->dir;        Print_enemy_tank (*myenemytrank);    Return        } else if ((myenemytrank->x) <= 2) {//Clean up all Clear_enemy_tank (*myenemytrank);        Give the tank a new direction myenemytrank->x++;        Enemychangedir (Myenemytrank, ' d ');        Print_enemy_tank (*myenemytrank);    Return        } else if ((myenemytrank->y) <= 2) {//Clean up all Clear_enemy_tank (*myenemytrank);        Give the tank a new direction myenemytrank->y++;        Enemychangedir (Myenemytrank, ' s ');        Print_enemy_tank (*myenemytrank);    Return        } else if ((myenemytrank->x) >= 37) {//Clean up all Clear_enemy_tank (*myenemytrank);        Give the tank a new direction myenemytrank->x--; EnemychanGedir (Myenemytrank, ' a ');        Print_enemy_tank (*myenemytrank);    Return        } else if ((myenemytrank->y) >= 37) {//Clean up all Clear_enemy_tank (*myenemytrank);        Give the tank a new direction myenemytrank->y--;        Enemychangedir (Myenemytrank, ' w ');        Print_enemy_tank (*myenemytrank);    Return    }}int Enemychangedir (Penemytrank Myenemytrank,char cdir) {int nnewdir =-1;        Switch (cdir) {case ' W ': Case ' W ': Nnewdir = tank_dir_up;    Break        Case ' s ': Case ' s ': Nnewdir = tank_dir_dw;    Break        Case ' A ': Case ' a ': Nnewdir = TANK_DIR_LF;    Break        Case ' d ': Case ' d ': Nnewdir = TANK_DIR_RH;    Break        Case ' Q ': Case ' Q ': Exit (0);    Break        Case ' E ': Case ' E ': _getch ();    Break    Default:break;    } Myenemytrank->dir = Nnewdir; return 1;} int Canenemymove (Penemytrank myusertrank) {if (myusertrank->life <= 0) {clear_enEmy_tank (*myusertrank);    return 1; } if (((g_map[2 + myusertrank->x][myusertrank->y] = = Zhangaimap | | g_map[1 + myusertrank->x][-1 + myUserTrank- >y] = = Zhangaimap | |        G_map[1 + myusertrank->x][1 + myusertrank->y] = = zhangaimap) && Myusertrank->dir = = tank_dir_rh) | | ((g_map[-2 + myusertrank->x][myusertrank->y] = = Zhangaimap | | g_map[-1 + myusertrank->x][-1 + myUserTrank-> Y] = = Zhangaimap | |        G_map[-1 + myusertrank->x][1 + myusertrank->y] = = zhangaimap) && Myusertrank->dir = = TANK_DIR_LF) | |  ((g_map[myusertrank->x][2 + myusertrank->y] = = Zhangaimap | | g_map[1 + myusertrank->x][1 + myUserTrank->y] = = Zhangaimap | |        G_map[-1 + myusertrank->x][1 + myusertrank->y] = = zhangaimap) && Myusertrank->dir = = tank_dir_dw) | | ((g_map[myusertrank->x][-2 + myusertrank->y] = = Zhangaimap | | g_map[-1 + myusertrank->x][-1 + myUserTrank-&gt ; y] = = Zhangaimap | | G_map[1 + Myusertrank->x][-1 + myusertrank->y] = = zhangaimap) && Myusertrank->dir = = tank_dir_up)) {switch (my            Usertrank->dir) {case Tank_dir_up:clear_enemy_tank (*myusertrank);            Changedir (Myusertrank, ' s ');            Clear_enemy_tank (*myusertrank);            Myusertrank->y + = 1;            Print_enemy_tank (*myusertrank);        Break            Case Tank_dir_dw:clear_enemy_tank (*myusertrank);            /* Clear_enemy_tank (*myusertrank);            Myusertrank->y + =-1;            Print_enemy_tank (*myusertrank); */Changedir (Myusertrank, ' w ');        Break            Case Tank_dir_lf:clear_enemy_tank (*myusertrank);            /* myusertrank->x + = 1;            Print_enemy_tank (*myusertrank); */Changedir (Myusertrank, ' d ');        Break            Case Tank_dir_rh:clear_enemy_tank (*myusertrank);            /*myusertrank->x + =-1; Print_Enemy_tank (*myusertrank); */Changedir (Myusertrank, ' a ');        Break        Default:break;    } return 1; } if ((myusertrank->x) >= && (myusertrank->x) <= && (myusertrank->y) >= ;& (Myusertrank->dir! = tank_dir_up)) {if ((myusertrank->x) <=) {Clear_enemy_tank (*            Myusertrank);            Myusertrank->x-= 1;            Print_enemy_tank (*myusertrank);        return 1;            } if ((myusertrank->x) >=) {Clear_enemy_tank (*myusertrank);            Myusertrank->x + = 1;            Print_enemy_tank (*myusertrank);        return 1;            } if ((Myusertrank->y) <=) {Clear_enemy_tank (*myusertrank);            Myusertrank->y-= 1;            Print_enemy_tank (*myusertrank);        return 1; }} return 0;} void Enemytranklife (Penemytrank myusertrank) {//detects if the map is a user tank if ((G_map[2 + myusertrank->x] [Myusertrank->y] = = Usertankmap | | G_map[1 + myusertrank->x][-1 + myusertrank->y] = = Usertankmap | |        G_map[1 + myusertrank->x][1 + myusertrank->y] = = usertankmap) && Myusertrank->dir = = tank_dir_rh) | | ((g_map[-2 + myusertrank->x][myusertrank->y] = = Usertankmap | | g_map[-1 + myusertrank->x][-1 + MYUSERTRANK-&G T;y] = = Usertankmap | |        G_map[-1 + myusertrank->x][1 + myusertrank->y] = = usertankmap) && Myusertrank->dir = = TANK_DIR_LF) | | ((g_map[myusertrank->x][2 + myusertrank->y] = = Usertankmap | | g_map[1 + myusertrank->x][1 + myUserTrank-> Y] = = Usertankmap | |        G_map[-1 + myusertrank->x][1 + myusertrank->y] = = usertankmap) && Myusertrank->dir = = TANK_DIR_DW) | | ((g_map[myusertrank->x][-2 + myusertrank->y] = = Usertankmap | | g_map[-1 + myusertrank->x][-1 + myUserTrank-& Gt;y] = = Usertankmap | | G_map[1 + myusertrank->x][-1 + myusertrank->y] = = Usertankmap) &Amp;& Myusertrank->dir = = tank_dir_up) | |  Detection is whether the user bullet ((g_map[2 + myusertrank->x][myusertrank->y] = = Userbulletmap | | g_map[1 + myusertrank->x][-1 + Myusertrank->y] = = Userbulletmap | |        G_map[1 + myusertrank->x][1 + myusertrank->y] = = userbulletmap) && Myusertrank->dir = = TANK_DIR_RH) | | ((g_map[-2 + myusertrank->x][myusertrank->y] = = Userbulletmap | | g_map[-1 + myusertrank->x][-1 + MyUserTran K->y] = = Userbulletmap | |        G_map[-1 + myusertrank->x][1 + myusertrank->y] = = userbulletmap) && Myusertrank->dir = = TANK_DIR_LF) | | ((g_map[myusertrank->x][2 + myusertrank->y] = = Userbulletmap | | g_map[1 + myusertrank->x][1 + myUserTrank- >y] = = Userbulletmap | |        G_map[-1 + myusertrank->x][1 + myusertrank->y] = = userbulletmap) && Myusertrank->dir = = TANK_DIR_DW) | | ((g_map[myusertrank->x][-2 + myusertrank->y] = = Userbulletmap | | g_map[-1 + myusertrank->x][-1 +Myusertrank->y] = = Userbulletmap | |        G_map[1 + myusertrank->x][-1 + myusertrank->y] = = userbulletmap) && Myusertrank->dir = = TANK_DIR_UP)    ) {Myusertrank->life-= 10; }}

C language Simple version tank war (allenenemytrank file)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.