AllenBullet.h
#include "AllenUserTrank.h" #include "AllenEnemyTrank.h" typedef struct pbullet{int x; int y; int dir; int life;} Bullet, *pbullet;//Initialize bullets void Init_user_bullet (Usertrank usertrank,pbullet userbullet);//Create bullets void Create_user_bullet (Usertrank Usertrank, Pbullet userbullet);//Print bullets void Print_user_bullet (Bullet userbullet);//Clear bullets void clear_user_ Bullet (Bullet userbullet);//Move all void User_bullet_move (Pbullet userbullet);//Determine if the bullet is near home int user_bullet_home ( Pbullet userbullet);////////////////////////////////////////////////////////////////Initialize bullets void Init_Enemy_Bullet ( Enemytrank Enemytrank, Pbullet userbullet);//Create Bullets void Create_enemy_bullet (Enemytrank enemytrank, Pbullet userBullet) ;//Print bullets void Print_enemy_bullet (Bullet userbullet);//Clear bullets void Clear_enemy_bullet (Bullet userbullet);//move all void Enemy _bullet_move (Pbullet pbullet);//Determine if the bullet is near home int enemy_bullet_home (Pbullet pbullet);//user extern Bullet userbullet[ 100];//enemy extern Bullet enemybullet[100];////enemy 2//extern Bullet enemybullet1[100];//Enemy 3//extern Bullet Enemybullet2[100];//extern list<bullet> listbullet;
Allenbullet.c
#include "AllenBullet.h" #include "Allendraw.h" Bullet userbullet[100];//enemy Bullet enemybullet[100];//print void Print_ User_bullet (Bullet userbullet) {if (! ( Userbullet.life)) return; if (g_map[userbullet.x][userbullet.y] = = Caomap) {Printchar (Userbullet.x, Userbullet.y, CAO, 0x2); Return }//If the barrier if (g_map[userbullet.x][userbullet.y] = = zhangaimap) {userbullet.life = 0; Return } if (g_map[userbullet.x][userbullet.y] = = KONG) {Printchar (userbullet.x, Userbullet.y, "", 0x3); G_MAP[USERBULLET.X][USERBULLET.Y] = Userbulletmap; Return }}//Clear User bullets void Clear_user_bullet (Bullet userbullet) {//Determine if the obstruction is an obstacle if (g_map[userbullet.x][userbullet.y] = = Zhangaimap ) {userbullet.life = 0; Return } if (g_map[userbullet.x][userbullet.y] = = Userbulletmap) {Printchar (userbullet.x, Userbullet.y, "", 0x00); G_MAP[USERBULLET.X][USERBULLET.Y] = KONG; Return }}//move all health values to TurE bullet void User_bullet_move (Pbullet userbullet) {user_bullet_home (userbullet); for (int i = 0; i < i++) {//Remove Clear_user_bullet (Userbullet[i]) before moving; If the bullet life fails on an obstacle if (g_map[userbullet[i].x][userbullet[i].y] = = zhangaimap) {userbullet[i].life = 0; }//Determine if within range if (userbullet[i].x > 2 && userbullet[i].x <= PNS && userbullet[i].y& Gt;2 && userbullet[i].y <=37&& (userbullet[i].life==1)) {switch (USERBULLET[I].DIR) {Case tank_dir_up:userbullet[i].y--; Break Case tank_dir_dw:userbullet[i].y++; Break Case tank_dir_lf:userbullet[i].x--; Break Case tank_dir_rh:userbullet[i].x++; Break }//Print it out again//userbullet[i].life = 1; Print_user_bullet (userbullet[I]); }//If out of range this bullet is useless. else {userbullet[i].life = 0; }}}//generated bullets void Create_user_bullet (Usertrank usertrank, Pbullet userbullet) {if ((g_map[2 + Usertrank.x][usertrank. Y] = = Zhangaimap | | G_map[1 + usertrank.x][-1 + usertrank.y] = = Zhangaimap | | G_map[1 + usertrank.x][1 + usertrank.y] = = zhangaimap) && Usertrank.dir = = tank_dir_rh) | | ((g_map[-2 + usertrank.x][usertrank.y] = = Zhangaimap | | g_map[-1 + usertrank.x][-1 + usertrank.y] = = ZHANGAIMAP | | g_map[- 1 + usertrank.x][1 + usertrank.y] = = zhangaimap) && Usertrank.dir = = TANK_DIR_LF) | | ((g_map[usertrank.x][2 + usertrank.y] = = Zhangaimap | | g_map[1 + usertrank.x][1 + usertrank.y] = = Zhangaimap | | g_map[-1 + Usertrank.x][1 + usertrank.y] = = zhangaimap) && Usertrank.dir = = tank_dir_dw) | | ((g_map[usertrank.x][-2 + usertrank.y] = = Zhangaimap | | g_map[-1 + usertrank.x][-1 + usertrank.y] = = ZHANGAIMAP | | g_map[1 + usertrank.x][-1 + Usertrank. y] = = zhangaimap) && Usertrank.dir = = tank_dir_up)) {return; } if (usertrank.life <= 0) return; if (! ( usertrank.x > 3 && usertrank.x < approx && usertrank.y >3 && usertrank.y <=36)) { Return }//Do not generate bullets near home if ((usertrank.x >= && usertrank.x <=25 && usertrank.y >=32) && use Rtrank.dir!= tank_dir_up) {return; } if (usertrank.y = = && Usertrank.dir = = tank_dir_dw) return; Switch (usertrank.dir) {case tank_dir_up:for (int i = 0; i <; i++) {if (userbullet[i].life = = 0) {userbullet[i].life = 1; Userbullet[i].dir = Usertrank.dir; userbullet[i].x = usertrank.x; Userbullet[i].y = usertrank.y-3; Print_user_bullet (Userbullet[i]); Break } else {continue; }} BReak; Case tank_dir_dw:for (int i = 0; i <; i++) {if (Userbullet[i].life = = 0) {UserB Ullet[i].life = 1; Userbullet[i].dir = Usertrank.dir; userbullet[i].x = usertrank.x; USERBULLET[I].Y = usertrank.y + 3; Print_user_bullet (Userbullet[i]); Break } else {continue; }} break; Case tank_dir_lf:for (int i = 0; i <; i++) {if (Userbullet[i].life = = 0) {UserB Ullet[i].life = 1; Userbullet[i].dir = Usertrank.dir; userbullet[i].x = usertrank.x-3; Userbullet[i].y = usertrank.y; Print_user_bullet (Userbullet[i]); Break } else {continue; }} break; Case tank_dir_rh:for (int i = 0; i <; i++) {if (Userbullet[I].life = = 0) {userbullet[i].life = 1; Userbullet[i].dir = Usertrank.dir; userbullet[i].x = usertrank.x + 3; Userbullet[i].y = usertrank.y; Print_user_bullet (Userbullet[i]); Break } else {continue; }} break; }}//all bullets initialized to Flasevoid Init_user_bullet (Usertrank usertrank, Pbullet userbullet) {for (int i = 0; i <; i++) { userbullet[i].x = usertrank.x; Userbullet[i].y = usertrank.y; Userbullet[i].life = 0; }}//determine if the bullet is near home int user_bullet_home (Pbullet userbullet) {for (int i = 0; i <; i++) {if (Userbullet[i] . x >= && userbullet[i].x <= && userbullet[i].y >=) {userbullet[i].life = 0; Clear_user_bullet (Userbullet[i]); }}}///////////////////////////////////_enemy_/////////////////////////////////////////////////////////Print enemy bullets void Print_enemy_bullet (Bullet userbullet) {if (Userbullet.x = = 0 | | userbullet.x = = | | userbullet.y = 39 || Userbullet.y = = 0) return; if (! ( Userbullet.life)) return; If the grass is printed on the grass if (g_map[userbullet.x][userbullet.y] = = Caomap) {Printchar (Userbullet.x, Userbullet.y, CAO, 0x2); Return }//If the barrier if (g_map[userbullet.x][userbullet.y] = = zhangaimap) {userbullet.life = 0; Return } if (G_map[userbullet.x][userbullet.y]==kong) {Printchar (userbullet.x, Userbullet.y, "", 0x6); G_MAP[USERBULLET.X][USERBULLET.Y] = Enetbulletmap; Return }}//clear Enemy bullets void Clear_enemy_bullet (Bullet userbullet) {//To determine if it is an obstacle if (g_map[userbullet.x][userbullet.y] = = Zhangaima P) {userbullet.life = 0; Return } if (g_map[userbullet.x][userbullet.y] = = Enetbulletmap) {Printchar (userbullet.x, Userbullet.y, "", 0x00); G_MAP[USERBULLET.X][USERBULLET.Y] = KONG; Return }}//MobileSome health values are ture bullets void Enemy_bullet_move (Pbullet pbullet) {enemy_bullet_home (pbullet); for (int i = 0; i < i++) {//Remove Clear_enemy_bullet ((pbullet[i)) before moving; If the bullet life fails on an obstacle if (g_map[pbullet[i].x][pbullet[i].y] = = zhangaimap) {pbullet[i].life = 0; }//Determine if within range if ((pbullet[i].x) >=2 && (pbullet[i].x) <=37 && (pbullet[i].y) >=2 &am p;& (PBULLET[I].Y) <= 37&& (pbullet[i].life) = = 1) {switch (Pbullet[i].dir) { Case tank_dir_up:pbullet[i].y--; Break Case tank_dir_dw:pbullet[i].y++; Break Case tank_dir_lf:pbullet[i].x--; Break Case tank_dir_rh:pbullet[i].x++; Break }//Print out Print_enemy_bullet ((Pbullet[i])); }//If out of range this bullet is useless else { Pbullet[i].life = 0; }}}//generated bullets void Create_enemy_bullet (Enemytrank enemytrank, Pbullet enemybullet) {if ((g_map[2 + enemytrank.x][enemy TRANK.Y] = = Zhangaimap | | G_map[1 + enemytrank.x][-1 + enemytrank.y] = = Zhangaimap | | G_map[1 + enemytrank.x][1 + enemytrank.y] = = zhangaimap) && Enemytrank.dir = = tank_dir_rh) | | ((g_map[-2 + enemytrank.x][enemytrank.y] = = Zhangaimap | | g_map[-1 + enemytrank.x][-1 + enemytrank.y] = = ZHANGAIMAP | | g_m Ap[-1 + enemytrank.x][1 + enemytrank.y] = = zhangaimap) && Enemytrank.dir = = TANK_DIR_LF) | | ((g_map[enemytrank.x][2 + enemytrank.y] = = Zhangaimap | | g_map[1 + enemytrank.x][1 + enemytrank.y] = = ZHANGAIMAP | | g_map[ -1 + enemytrank.x][1 + enemytrank.y] = = zhangaimap) && Enemytrank.dir = = tank_dir_dw) | | ((g_map[enemytrank.x][-2 + enemytrank.y] = = Zhangaimap | | g_map[-1 + enemytrank.x][-1 + enemytrank.y] = = ZHANGAIMAP | | g_m Ap[1 + enemytrank.x][-1 + enemytrank.y] = = zhangaimap) && eneMytrank.dir = = tank_dir_up)) {return; } if (enemytrank.life <= 0) return; if (! ( enemytrank.x > 3 && enemytrank.x < $ && enemytrank.y >3 && enemytrank.y <=) &&A mp Enemytrank.dir!= tank_dir_up) {return; }//Do not generate bullets near home if ((enemytrank.x >= && enemytrank.x <= && enemytrank.y >= 32)) { Return } if (enemytrank.y = = 3 && Enemytrank.dir = = tank_dir_up) return; if (enemytrank.y = = && Enemytrank.dir = = tank_dir_dw) return; Switch (enemytrank.dir) {case tank_dir_up:for (int i = 0; i <; i++) {if (enemybullet[i].lif E = = 0) {enemybullet[i].life = 1; Enemybullet[i].dir = Enemytrank.dir; enemybullet[i].x = enemytrank.x; Enemybullet[i].y = enemytrank.y-3; Print_enemy_bullet (Enemybullet[i]); Break } else {continue; }} break; Case tank_dir_dw:for (int i = 0; i <; i++) {if (Enemybullet[i].life = = 0) {Enem Ybullet[i].life = 1; Enemybullet[i].dir = Enemytrank.dir; enemybullet[i].x = enemytrank.x; ENEMYBULLET[I].Y = enemytrank.y + 3; Print_enemy_bullet (Enemybullet[i]); Break } else {continue; }} break; Case tank_dir_lf:for (int i = 0; i <; i++) {if (Enemybullet[i].life = = 0) {Enem Ybullet[i].life = 1; Enemybullet[i].dir = Enemytrank.dir; enemybullet[i].x = enemytrank.x-3; Enemybullet[i].y = enemytrank.y; Print_enemy_bullet (Enemybullet[i]); Break } else {continue; }} break; Case tank_dir_rh:for (int i = 0; i <; i++) {if (Enemybullet[i].life = = 0) {En Emybullet[i].life = 1; Enemybullet[i].dir = Enemytrank.dir; enemybullet[i].x = enemytrank.x + 3; Enemybullet[i].y = enemytrank.y; Print_enemy_bullet (Enemybullet[i]); Break } else {continue; }} break; }}//all bullets initialized to Flasevoid Init_enemy_bullet (Enemytrank enemytrank, Pbullet enemybullet) {for (int i = 0; i <; i++) {enemybullet[i].x = enemytrank.x; Enemybullet[i].y = enemytrank.y; Enemybullet[i].life = 0; }}//determine if the bullet is near home int enemy_bullet_home (Pbullet userbullet) {for (int i = 0; i <; i++) {if (userbullet[i ].x >= && userbullet[i].x <= && userbullet[i].y >=) {userbullet[i].life = 0; Clear_enemy_bullet (Userbullet[i]); } }}
C language Simple version tank war (allenbullet file)