AllenUserTrank.h
typedef struct USERTRANK2{ int x, y;//我的坦克中心坐标 int m, n;//我的坦克子弹的坐标 int state; //我的坦克方向(1上,2下,3左,4右) int dir;//我的坦克子弹射向 int life;//生命 int skin;//皮肤 int weapons;//武器 int lv;//等级 int speed;//速度 //颜色 char color; //是否要清理 int clear;}UserTrank, *PUserTrank;void init_my_tank(PUserTrank myuse,int x, int y);//打印坦克void print_my_tank(UserTrank myuse);//清除坦克void clear_my_tank(UserTrank myuse);void TankMove(PUserTrank myUserTrank);int ChangeDir(PUserTrank myUserTrank,char cDir);int ChangeDir2(PUserTrank myUserTrank, char cDir);int canusermove(PUserTrank myUserTrank);extern UserTrank myuser;extern UserTrank myuser2;void usetranklife(PUserTrank myUserTrank);
Allenusertrank.c
#include "AllenUserTrank.h" #include "Allendraw.h" #include <stdio.h> #include <windows.h> #include < Conio.h>int Olddir = 0;void Init_my_tank (pusertrank myuse,int x, int y) {myuse->x = x; Myuse->y = y; Myuse->dir = tank_dir_up; Myuse->life = 100; Myuse->color = 0x4; for (int i = (*myuse). X-1, I <= (*myuse). x + 1; i++) {for (int j = (*myuse). Y-1; J <= (*myuse). Y + 1; j+ +) {//build tank when not print that point on the grass if (g_map[i][j]! = Caomap) {G_map[i][j] = Usertankmap; }}} Print_my_tank (*myuse);} Usertrank myuser;void Print_my_tank (usertrank myuse) {switch (myuse.dir) {case Tank_dir_lf:if (myuse.x + 1) = = () break; if (g_map[myuse.x][myuse.y] = = Caomap) {} else {Printchar (myuse.x, MYUSE.Y, Usertank, rand ()% 0xf + 0x0); G_MAP[MYUSE.X][MYUSE.Y] = Usertankmap; } ///////////////////////////////////////////////////if (g_map[myuse.x][myuse.y-1] = = Caomap) {} else {Printchar (myuse.x, Myuse.y-1, Usert ANK, rand ()% 0xf + 0x0); G_map[myuse.x][myuse.y-1] = Usertankmap; }///////////////////////////////////////////////////////////if (g_map[myuse.x-1][myuse.y] = = CAOMAP) {} else {Printchar (myuse.x-1, MYUSE.Y, Usertank, rand ()% 0xf + 0x0); G_MAP[MYUSE.X-1][MYUSE.Y] = Usertankmap; }///////////////////////////////////////////////////////////if (g_map[myuse.x][myuse.y+1] = = CAOMAP) {} else {Printchar (myuse.x, Myuse.y + 1, Usertank, rand ()% 0xf + 0x0); G_map[myuse.x][myuse.y + 1] = Usertankmap; }///////////////////////////////////////////////////////////if (g_map[myuse.x+1][myuse.y-1] = = CAOMAP) { } else {Printchar (myuse.x + 1, myuse.y-1, Usertank, rand ()% 0xf + 0x0); G_map[myuse.x + 1][myuse.Y-1] = Usertankmap; }///////////////////////////////////////////////////////////if (g_map[myuse.x + 1][myuse.y + 1] = = CAOMAP) {} else {Printchar (myuse.x + 1, myuse.y + 1, Usertank, rand ()% 0xf + 0x0); g_map[myuse.x + 1][myuse.y + 1] = Usertankmap; }///////////////////////////////////////////////////////////if (g_map[myuse.x + 1][myuse.y] = = CAOMAP) {} else {Printchar (myuse.x + 1, myuse.y, TANKLF, rand ()% 0xf + 0x0); G_MAP[MYUSE.X+1][MYUSE.Y] = Usertankmap; }///////////////////////////////////////////////////////////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, rand ()% 0xf + 0x 0); G_MAP[MYUSE.X][MYUSE.Y] = Usertankmap; }///////////////////////////////////////////////////////////if (g_map[myUSE.X+1][MYUSE.Y] = = Caomap) {} else {Printchar (myuse.x + 1, myuse.y, Usertank, rand ()% 0xf + 0x0); G_map[myuse.x + 1][myuse.y] = Usertankmap; }///////////////////////////////////////////////////////////if (g_map[myuse.x][myuse.y-1] = = CAOMAP) {} else {Printchar (myuse.x, Myuse.y-1, Usertank, rand ()% 0xf + 0x0); G_map[myuse.x][myuse.y-1] = Usertankmap; }///////////////////////////////////////////////////////////if (g_map[myuse.x][myuse.y + 1] = = CAOMAP) {} else {Printchar (myuse.x, Myuse.y + 1, Usertank, rand ()% 0xf + 0x0); G_map[myuse.x][myuse.y + 1] = Usertankmap; }///////////////////////////////////////////////////////////if (g_map[myuse.x-1][myuse.y-1] = = CAOMAP) { } else {Printchar (myuse.x-1, Myuse.y-1, Usertank, rand ()% 0xf + 0x0); G_map[myuse.x-1][myuse.y-1] = Usertankmap; }///////////////////////////////////////////////////////////if (g_map[myuse.x-1][myuse.y + 1] = = CAOM AP) {} else {Printchar (myuse.x-1, Myuse.y + 1, Usertank, rand ()% 0xf + 0x0); G_map[myuse.x-1][myuse.y + 1] = Usertankmap; }///////////////////////////////////////////////////////////if (g_map[myuse.x-1][myuse.y] = = CAOMAP) {} else {Printchar (myuse.x-1, MYUSE.Y, TANKRH, rand ()% 0xf + 0x0); G_MAP[MYUSE.X-1][MYUSE.Y] = Usertankmap; } break; Case Tank_dir_up:if (g_map[myuse.x][myuse.y] = = Caomap) {} else {Printchar (myuse.x, Myuse.y, U Sertank, rand ()% 0xf + 0x0); G_MAP[MYUSE.X][MYUSE.Y] = Usertankmap; }//////////////////////////////////////////////////////////if (g_map[myuse.x][myuse.y-1] = = CAOMAP) { } else {Printchar (myuse.x, Myuse.y-1, Usertank, rand ()% 0xf + 0x0); G_map[myuse.x][myuse.y-1] = Usertankmap; }/////////////////////////////////////////////////////////////if (g_map[myuse.x+1][myuse.y + 1] = = CAOMAP) {} else {Printchar (myuse.x + 1, myuse.y + 1, Usertank, rand ()% 0xf + 0x0); g_map[myuse.x + 1][myuse.y + 1] = Usertankmap; }/////////////////////////////////////////////////////////////if (g_map[myuse.x + 1][myuse.y] = = CAOMAP) { } else {Printchar (myuse.x + 1, myuse.y, Usertank, rand ()% 0xf + 0x0); G_map[myuse.x + 1][myuse.y] = Usertankmap; }/////////////////////////////////////////////////////////////if (g_map[myuse.x][myuse.y-1] = = CAOMAP) {} else {Printchar (myuse.x, Myuse.y-1, Usertank, rand ()% 0xf + 0x0); G_map[myuse.x][myuse.y-1] = Usertankmap; }///////////////////////////////////////////////////////////if (g_map[myuse.x-1][myuse.y] = = CAOMAP) {} else {Printchar (myuse.x-1, MYUSE.Y, Usertank, rand ()% 0xf + 0x0); G_MAP[MYUSE.X-1][MYUSE.Y] = Usertankmap; }///////////////////////////////////////////////////////////if (g_map[myuse.x-1][myuse.y+1] = = CAOMAP) { } else {Printchar (myuse.x-1, Myuse.y + 1, Usertank, rand ()% 0xf + 0x0); G_map[myuse.x-1][myuse.y + 1] = Usertankmap; }///////////////////////////////////////////////////////////if (g_map[myuse.x][myuse.y + 1] = = CAOMAP) {} else {Printchar (myuse.x, Myuse.y + 1, Tankup, rand ()% 0xf + 0x0); G_map[myuse.x][myuse.y + 1] = Usertankmap; } 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, rand ()% 0xf + 0x 0); G_MAP[MYUSE.X][MYUSE.Y] = Usertankmap; } /////////////////if (g_map[myuse.x-1][myuse.y] = = Caomap) {} else {Pri Ntchar (Myuse.x-1, MYUSE.Y, Usertank, rand ()% 0xf + 0x0); G_MAP[MYUSE.X-1][MYUSE.Y] = Usertankmap; }///////////////////////////////////////////////////////////if (g_map[myuse.x-1][myuse.y-1] = = CAOMAP) { } else {Printchar (myuse.x-1, Myuse.y-1, Usertank, rand ()% 0xf + 0x0); G_map[myuse.x-1][myuse.y-1] = Usertankmap; }///////////////////////////////////////////////////////////if (g_map[myuse.x][myuse.y +1] = = CAOMAP) {} else {Printchar (myuse.x, Myuse.y + 1, Usertank, rand ()% 0xf + 0x0); G_map[myuse.x][myuse.y + 1] = Usertankmap; }///////////////////////////////////////////////////////////if (g_map[myuse.x+1][myuse.y] = = CAOMAP) {} else {Printchar (myuse.x + 1, myuse.y, Usertank, rand ()% 0xf + 0x0); G_map[myuse.x + 1][myuse.y] = Usertankmap; }///////////////////////////////////////////////////////////if (g_map[myuse.x + 1][myuse.y-1] = = CAOMAP) { } else {Printchar (myuse.x + 1, myuse.y-1, Usertank, rand ()% 0xf + 0x0); G_map[myuse.x + 1][myuse.y-1] = Usertankmap; }/////////////////////////////////////////////////////////////if (g_map[myuse.x][myuse.y-1] = = CAOMAP) {} else {Printchar (myuse.x, Myuse.y-1, TANKDW, rand ()% 0xf + 0x0); G_map[myuse.x][myuse.y-1] = Usertankmap; } break; Default:break; }}//Clear tank void Clear_my_tank (Usertrank myuse) {for (int i = myuse.x-1; I <= myuse.x + 1; i++) {for (int j = Myuse.y-1; J <= Myuse.y + 1; J + +) {if (g_map[i][j] = = Usertankmap) {Printchar (I, J, "", 0x00); G_MAP[I][J] = = KONG; }}}}void Tankmove (PUsertrank Myusertrank) {usetranklife (Myusertrank); if (Canusermove (Myusertrank)) return; if ((myusertrank->x) > 2 && (myusertrank->x) <=36 && (myusertrank->y) >=3 && ( Myusertrank->y) <=36) {//Clean up all Clear_my_tank (*myusertrank); Switch (myusertrank->dir) {case tank_dir_up:myusertrank->y--; Break Case tank_dir_dw:myusertrank->y++; Break Case tank_dir_lf:myusertrank->x--; Break Case tank_dir_rh:myusertrank->x++; Break }//give tank a new direction Myusertrank->dir = myusertrank->dir; Print_my_tank (*myusertrank); Return } else if (myusertrank->x <=2) {//Clean up all Clear_my_tank (*myusertrank); Give the tank a new direction myusertrank->x++; Changedir (Myusertrank, ' d '); Print_my_tank (*myusertrank); Return } else if (myusertrank->y <= 2) {//Clean up all Clear_my_tank (*myusertrank); myusertrank->y++; Give the tank a new Direction changedir (Myusertrank, ' s '); Print_my_tank (*myusertrank); Return } else if (myusertrank->x >= 37) {//Clean up all Clear_my_tank (*myusertrank); Give the tank a new direction myusertrank->x--; Changedir (Myusertrank, ' a '); Print_my_tank (*myusertrank); Return } else if (Myusertrank->y >= 37) {//Clean up all Clear_my_tank (*myusertrank); Give the tank a new direction myusertrank->y--; Changedir (Myusertrank, ' w '); Print_my_tank (*myusertrank); Return }}int Changedir (Pusertrank Myusertrank,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; }//if (Myusertrank->dir = = Cdir) tankmove (Myusertrank); Myusertrank->dir = Nnewdir; return 1;} int ChangeDir2 (Pusertrank myusertrank, char cdir) {int nnewdir =-1; Switch (cdir) {case ' I ': Case ' i ': Nnewdir = tank_dir_up; Break Case ' K ': Case ' k ': Nnewdir = tank_dir_dw; Break Case ' J ': Case ' j ': Nnewdir = TANK_DIR_LF; Break Case ' l ': Case ' l ': nnewdir = TANK_DIR_RH; Break Default:break; } if (Myusertrank->dir = = Cdir) tankmove (Myusertrank); Myusertrank->dir = Nnewdir; return 1;} int Canusermove (Pusertrank myusertrank) {if ((g_map[2 + myusertrank->x][myusertrank->y] = = ZHANGAIMAP | | g_ma P[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-> ; y] = = Zhangaimap | | G_map[1 + myusertrank->x][-1 + myusertrank->y] = = zhangaimap) && Myusertrank->dir = = tank_dir_up) ) {switch (myusertrank->dir) {case tank_dir_up:clear_enemy_tAnk (*myusertrank); Changedir (Myusertrank, ' s '); Break Case Tank_dir_dw:clear_enemy_tank (*myusertrank); Changedir (Myusertrank, ' w '); Break Case Tank_dir_lf:clear_enemy_tank (*myusertrank); Changedir (Myusertrank, ' d '); Break Case Tank_dir_rh:clear_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_my_tank (*myu Sertrank); Myusertrank->x-= 1; Print_my_tank (*myusertrank); return 1; } if ((myusertrank->x) >=) {Clear_my_tank (*myusertrank); Myusertrank->x + = 1; Print_my_tank (*myusertrank); return 1; } if ((Myusertrank->y) <=) {Clear_my_tank (*myusertrank); Myusertrank->y-= 1; Print_my_tank (*myusertrank); return 1; }} return 0;} void Usetranklife (Pusertrank myusertrank) {//detects if the enemy tank if ((g_map[2 + myusertrank->x][myusertrank->y] = = EN Etankmap | | G_map[1 + myusertrank->x][-1 + myusertrank->y] = = Enetankmap | | G_map[1 + myusertrank->x][1 + myusertrank->y] = = enetankmap) && Myusertrank->dir = = tank_dir_rh) | | ((g_map[-2 + myusertrank->x][myusertrank->y] = = Enetankmap | | g_map[-1 + myusertrank->x][-1 + myUserTrank-> Y] = = Enetankmap | | G_map[-1 + myusertrank->x][1 + myusertrank->y] = = enetankmap) && Myusertrank->dir = = TANK_DIR_LF) | | ((g_map[myusertrank->x][2 + myusertrank->y] = = Enetankmap | | g_map[1 + myusertrank->x][1 + myUserTrank->y] = = Enetankmap | |G_map[-1 + myusertrank->x][1 + myusertrank->y] = = enetankmap) && Myusertrank->dir = = tank_dir_dw) | | ((g_map[myusertrank->x][-2 + myusertrank->y] = = Enetankmap | | g_map[-1 + myusertrank->x][-1 + myUserTrank-> ; y] = = Enetankmap | | G_map[1 + myusertrank->x][-1 + myusertrank->y] = = enetankmap) && Myusertrank->dir = = tank_dir_up) || Detection is whether the enemy bullets ((g_map[2 + myusertrank->x][myusertrank->y] = = Enetbulletmap | | g_map[1 + myusertrank->x][-1 + Myusertrank->y] = = Enetbulletmap | | G_map[1 + myusertrank->x][1 + myusertrank->y] = = enetbulletmap) && Myusertrank->dir = = TANK_DIR_RH) | | ((g_map[-2 + myusertrank->x][myusertrank->y] = = Enetbulletmap | | g_map[-1 + myusertrank->x][-1 + MyUserTran K->y] = = Enetbulletmap | | G_map[-1 + myusertrank->x][1 + myusertrank->y] = = enetbulletmap) && Myusertrank->dir = = TANK_DIR_LF) | | ((g_map[myusertrank->x][2 + Myusertrank->y] = = Enetbulletmap | | G_map[1 + myusertrank->x][1 + myusertrank->y] = = Enetbulletmap | | G_map[-1 + myusertrank->x][1 + myusertrank->y] = = enetbulletmap) && Myusertrank->dir = = TANK_DIR_DW) | | ((g_map[myusertrank->x][-2 + myusertrank->y] = = Enetbulletmap | | g_map[-1 + myusertrank->x][-1 + MyUserTra Nk->y] = = Enetbulletmap | | G_map[1 + myusertrank->x][-1 + myusertrank->y] = = enetbulletmap) && Myusertrank->dir = = TANK_DIR_UP) ) {Myusertrank->life-= 10; }}
C language Simple version tank war (allenusertrank file)