这是效果截图:

部分源码:


#include <iostream>
#include <time.h>
#include <windows.h>#define W 1       //上
#define S 2         //下
#define A 3         //左
#define D 4          //右
#define L 4       // 坦克有4条命void HideCursor() {  //隐藏光标            CONSOLE_CURSOR_INFO cursor_info = { 1,0 };SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
void GoToxy(int x, int y) {  //光标移动,X、Y表示横、纵坐标COORD coord = { x, y };SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}//全局变量
int map[50][40];//地图二维数组
int B_num;      //子弹编号
int Pos;     //敌方坦克生成位置,-1为左边,0为中间,1为右边,2为我的坦克位置
int Speed = 7;  //游戏速度
int Enemy; //还未出现的敌人
const char* Tank_Model[3][4] ={{"◢┃ ◣", "◢╦ ◣", "◢╦◣", "◢╦◣"},{"╠ █╣", "╠ █╣", "━█╣", "╠█━"},{"◥╩ ◤", "◥┃ ◤", "◥╩◤", "◥╩◤"}}; //坦克
class Tank{
public:int x, y; //中心坐标int Direction; //方向int Model;  //模型int Revival; //复活次数int Num; //敌方坦克编号  bool Type;   //我方坦克此参数为1bool Exist;  //存活为1,不存活为0
}AI_tank[6], my_tank;
//子弹
class Bullet{
public:int x, y;    //坐标int Direction;  //方向bool Exist;  //1为存在,0不存在bool Type;   //0为敌方子弹,1为我方子弹
}bullet[50] ;//基本函数
void GoToxy(int x, int y);    //光标移动
void HideCursor();           //隐藏光标void Key();  //键盘输入
void Init(); //初始化
void Pause(); //暂停
void Show(); //打印框架
void Print_Map();  //打印地图
void Cheak_Game(); //检测游戏胜负
void GameOver();  //游戏结束//坦克
void Creat_AI_T(Tank* AI_tank); //建立坦克
void Creat_My_T(Tank* my_tank);               void Move_AI_T(Tank* AI_tank);//坦克移动
void Move_My_T(int turn);                     void Clear_T(int x, int y);  //清除坦克
void Print_T(Tank tank);  //打印坦克
bool Cheak_T(Tank tank, int direction); //检测障碍,1阻碍//子弹
void Creat_AI_B(Tank* tank);  //敌方坦克发射子弹
void Creat_My_B(Tank tank);//我方坦克发射子弹
void Move_B(Bullet bullet[50]); //子弹移动
void Break_B(Bullet* bullet); //子弹碰撞
void Print_B(int x, int y);//打印子弹
void Clear_B(int x, int y); //清除子弹
int  Cheak_B(int x, int y);  //子弹前方情况void Show() {       //打印框架   std::cout << "  ▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁";std::cout << "▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁\n";for (int i = 0; i < 48; i++) {std::cout << "▕                                                                             ▏\n";}std::cout << "  ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔";std::cout << "▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔\n";
}
void Print_Map() {     // 打印地图   int Map[50][40] = {
//map里的值: 0为可通过陆地,1为砖,6为墙,100~105为敌方坦克,200为我的坦克,{ 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 },{ 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },{ 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },{ 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },{ 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },{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,0,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },{ 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },{ 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },{ 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },{ 4,0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,1,1,1,0,0,0,0,1,1,1,0,0,0,1,1,0,0,0,4 },{ 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,9,9,9,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },{ 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,9,9,9,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },{ 4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,9,9,9,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4 },{ 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 }};for (int i = 0; i < 50; i++)for (int j = 0; j < 40; j++)        map[i][j] = Map[i][j];for (int i = 0; i < 50; i++)for (int j = 0; j < 40; j++)        if (map[i][j] == 1) {GoToxy(2 * j, i);std::cout << "▓";}            else if (map[i][j] == 6) {GoToxy(2 * j, i);std::cout << "■";}             GoToxy(38, 46);     std::cout << " ◣◢";GoToxy(38, 47);     std::cout << "◣█ ◢";GoToxy(38, 48);     std::cout << "◢█ ◣";
}
void Cheak_Game() {//敌人坦克全部不存活if (Enemy <= 0 && !AI_tank[0].Exist && !AI_tank[1].Exist && !AI_tank[2].Exist&& !AI_tank[3].Exist && !AI_tank[4].Exist && !AI_tank[5].Exist)GameOver();if (my_tank.Revival >= L)//我复活次数用完GameOver();//游戏结束
}
void GameOver() {bool home = 1;while (home) { GoToxy(37, 21);std::cout << "游戏结束!";        if (GetAsyncKeyState(0xD) & 0x8000) {  //回车键system("cls");   //清屏Show();Init(); //初始化break;}else if (GetAsyncKeyState(0x1B) & 0x8000)  //Esc键退出   exit(0);}
}
void Creat_My_T(Tank* my_tank) {//建立我的坦克my_tank->x = 15;my_tank->y = 47;my_tank->Direction = 1;// my_tank->Model = 0;my_tank->Exist = 1;my_tank->Type = 1;Print_T(*my_tank);   //打印我的坦克
}
void Move_My_T(int turn) {//turn为Key()函数传入的方向值Clear_T(my_tank.x, my_tank.y);my_tank.Direction = turn; if (Cheak_T(my_tank, my_tank.Direction))  //我方坦克当前方向上无障碍switch (turn) {case W: my_tank.y--; break;  //上case S: my_tank.y++; break;  //下case A: my_tank.x--; break;  //左case D: my_tank.x++; break;  //右}  Print_T(my_tank);
}
void Print_T(Tank tank) {//打印for (int i = 0; i < 3; i++) {GoToxy((tank.x - 1) * 2, tank.y - 1 + i);//在坦克中心坐标的左边,上中下三行打印std::cout << Tank_Model[i][tank.Direction - 1]; //打印的是地址,地址既字符串for (int j = 0; j < 3; j++)if (tank.Type)//若为我的坦克map[tank.y + j - 1][tank.x + i - 1] = 200;//在map上敌方值为100~105,我方为200elsemap[tank.y + j - 1][tank.x + i - 1] = 100 +tank.Num;//这样可以通过map值读取坦克编号}
}
void Creat_AI_T(Tank* AI_tank) {AI_tank->x = 19 + 17 * (Pos); //pos为坦克生成位置,-1为左位置,0为中间,1为右,2为我的坦克位置AI_tank->y = 2;AI_tank->Direction = 2;  //方向朝下AI_tank->Revival++; //复活次数+1AI_tank->Exist = 1;//存在Pos++;Enemy--;if (Pos == 2)  //循环重置(pos只能为-1,0,1)Pos = -1;Print_T(*AI_tank);return;
}
void Move_AI_T(Tank* AI_tank) { if (AI_tank->Exist) {  //存在 Clear_T(AI_tank->x, AI_tank->y);if (Cheak_T(*AI_tank, AI_tank->Direction))//前方无障碍switch (AI_tank->Direction) {case W: AI_tank->y--; break;  //上case S: AI_tank->y++; break;  //下case A: AI_tank->x--; break;  //左case D: AI_tank->x++; break;  //右}else {//前方有障碍 for (int i = rand() % 4 + 1; i <= 4; i++)if (Cheak_T(*AI_tank, i)){  //循环判断,返1可通过AI_tank->Direction = i;break;}}Print_T(*AI_tank);     //打印敌方坦克}
}
bool Cheak_T(Tank tank, int direction) {  //检测坦克前方障碍,返1为可通过switch (direction) {                   case W: if (map[tank.y - 2][tank.x] == 0 && map[tank.y - 2][tank.x - 1] == 0 && map[tank.y - 2][tank.x + 1] == 0)return 1;else return 0;case S:if (map[tank.y + 2][tank.x] == 0 && map[tank.y + 2][tank.x - 1] == 0 && map[tank.y + 2][tank.x + 1] == 0)return 1;else return 0;case A:if (map[tank.y][tank.x - 2] == 0 && map[tank.y - 1][tank.x - 2] == 0 && map[tank.y + 1][tank.x - 2] == 0)return 1;else return 0;case D:if (map[tank.y][tank.x + 2] == 0 && map[tank.y - 1][tank.x + 2] == 0 && map[tank.y + 1][tank.x + 2] == 0)return 1;else return 0;default: return 0;}
}
void Clear_T(int x, int y) {   //清除坦克for (int i = 0; i <= 2; i++)for (int j = 0; j <= 2; j++) {//将坦克占用的地图清零map[y + j - 1][x + i - 1] = 0;GoToxy(2 * x + 2 * j - 2, y + i - 1);std::cout << "  ";}
}//键盘输入
void Key() {                 //上下左右键if (GetAsyncKeyState('W') & 0x8000)Move_My_T(W);else if (GetAsyncKeyState('S') & 0x8000)Move_My_T(S);else if (GetAsyncKeyState('A') & 0x8000)Move_My_T(A);else if (GetAsyncKeyState('D') & 0x8000)Move_My_T(D);
//子弹发射else if (GetAsyncKeyState('P') & 0x8000) {Creat_My_B(my_tank);}else if (GetAsyncKeyState(0x1B) & 0x8000)// Esc键退出exit(0); else if (GetAsyncKeyState(0x20) & 0x8000)//空格暂停Pause();
}
void Pause() {    //暂停while (1) {if (GetAsyncKeyState(0xD) & 0x8000) {      //回车键继续  break;}else if (GetAsyncKeyState(0x1B) & 0x8000) //Esc键退出   exit(0);}
}
void Creat_AI_B(Tank* tank){ //敌方发射子弹if (!(rand() % 10)) { //在随后的每个游戏周期中有10分之一的可能发射子弹       Creat_My_B(*tank);}
}
void Creat_My_B(Tank tank) {switch (tank.Direction) {  case W:bullet[B_num].x = tank.x;bullet[B_num].y = tank.y - 2;bullet[B_num].Direction = 1;//1表示向上break;case S:bullet[B_num].x = tank.x;bullet[B_num].y = tank.y + 2;bullet[B_num].Direction = 2;//2表示向下break;case A:bullet[B_num].x = tank.x - 2;bullet[B_num].y = tank.y;bullet[B_num].Direction = 3;//3表示向左break;case D:bullet[B_num].x = tank.x + 2;bullet[B_num].y = tank.y;bullet[B_num].Direction = 4;//4表示向右break;}bullet[B_num].Exist = 1; //子弹存在bullet[B_num].Type = tank.Type; //我方坦克发射的子弹bullet.Type=1B_num++;if (B_num == 50) //如果子弹编号增长到50号,那么重头开始编号B_num = 0;   //考虑到地图上不可能同时存在50颗子弹,所以数组元素设置50个
}
void Move_B(Bullet bullet[50]) {  //子弹移动                            for (int i = 0; i < 50; i++) {if (bullet[i].Exist) {//如果子弹存在        if (map[bullet[i].y][bullet[i].x] == 0) {         Clear_B(bullet[i].x, bullet[i].y);//子弹当前位置无障碍,抹除子弹图形switch (bullet[i].Direction) {//子弹变到下一个坐标case W:(bullet[i].y)--; break;case S:(bullet[i].y)++; break;case A:(bullet[i].x)--; break;case D:(bullet[i].x)++; break;}}//判断子弹当前位置情况if (map[bullet[i].y][bullet[i].x] == 0) //子弹坐标无障碍Print_B(bullet[i].x, bullet[i].y);//打印else Break_B(&bullet[i]);     //子弹碰撞       for (int j = 0; j < 50; j++) //子弹间的碰撞判断,若是我方子弹和敌方子弹碰撞则都删除,若为两敌方子弹则无视if (bullet[j].Exist && j != i && (bullet[i].Type || bullet[j].Type) && bullet[i].x == bullet[j].x && bullet[i].y == bullet[j].y){                              //同样的两颗我方子弹不可能产生碰撞bullet[j].Exist = 0;bullet[i].Exist = 0;Clear_B(bullet[j].x, bullet[j].y);break;}}}
}
void Break_B(Bullet* bullet) {  int x = bullet->x;  int y = bullet->y;  //子弹坐标int i;if (map[y][x] == 1) {  //子弹碰到砖块   if (bullet->Direction == A || bullet->Direction == D)     //若子弹是横向的for (i = -1; i <= 1; i++)if (map[y + i][x] == 1) {map[y + i][x] = 0;GoToxy(2 * x, y + i);std::cout << "  ";}if (bullet->Direction == W || bullet->Direction == S)   //子弹是向上或是向下移动的for (i = -1; i <= 1; i++)if (map[y][x + i] == 1) {  //如果子弹打中砖块两旁为砖块,则删除砖,若不是则忽略    map[y][x + i] = 0;    //砖块碎GoToxy(2 * (x + i), y);std::cout << "  ";}bullet->Exist = 0; //子弹不存在}else if (map[y][x] == 4 || map[y][x] == 6)  //子弹碰到边框或者不可摧毁方块bullet->Exist = 0;else if (bullet->Type ==1 && map[y][x] >= 100 && map[y][x] <= 105) { //我方子弹碰到了敌方坦克    AI_tank[(int)map[y][x] % 100].Exist = 0;bullet->Exist = 0; Clear_T(AI_tank[(int)map[y][x] % 100].x, AI_tank[(int)map[y][x] % 100].y);  //清除坦克}else if (bullet->Type == 0 && map[y][x] == 200) {   //若敌方子弹击中我的坦克    my_tank.Exist = 0;bullet->Exist = 0;Clear_T(my_tank.x, my_tank.y);my_tank.Revival++; //我方坦克复活次数加1}else if (map[y][x] == 9) { //子弹碰到巢    bullet->Exist = 0;GoToxy(38, 46);      std::cout << "      "; GoToxy(38, 47);      std::cout << "      ";GoToxy(38, 48);      std::cout << "◢◣  ";GameOver();}
}
int Cheak_B(int x, int y) {//子弹当前位置情况if (map[y][x] == 0)return 1;elsereturn 0;
}
void Print_B(int x, int y){GoToxy(2 * x, y);std::cout << "o";
}
void Clear_B(int x, int y){GoToxy(2 * x, y);if (Cheak_B(x, y) == 1) {//子弹当前坐标在空地上 std::cout << "  ";}
}void Init() {      //初始化Enemy = 24;my_tank.Revival = 0;  //我的坦克复活次数为0Pos = 0;B_num = 0;Print_Map();Creat_My_T(&my_tank);for (int i = 0; i < 50; i++) {//子弹bullet[i].Exist = 0;}for (int i = 0; i <= 5; i++) {//敌方坦克AI_tank[i].Revival = 0;AI_tank[i].Exist = 0;  //初始化坦克全是不存活的,用Creat_AI_T()建立不存活的坦克AI_tank[i].Num = i;AI_tank[i].Type = 0;}
}int main() {                              int i;int gap[16] = { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 };  //间隔数组,用于控制速度HideCursor();     //隐藏光标Show();      //打印框架Init();     //初始化while(1) {if (gap[0]++ % Speed == 0) {//速度调整,     Cheak_Game();  //游戏胜负检测for (i = 0; i <= 5; i++) {//敌方坦克移动循环if (gap[i + 7]++ % 3 == 0)Move_AI_T(&AI_tank[i]);}for (i = 0; i <= 5; i++)//建立敌方坦克if (AI_tank[i].Exist == 0 && AI_tank[i].Revival < 4 && gap[i+1]++ % 50 == 0) {  //一个敌方坦克每局只有4条命//坦克死掉后间隔一段时间建立Creat_AI_T(&AI_tank[i]);break;          } for (i = 0; i <= 5; i++)if (AI_tank[i].Exist)Creat_AI_B(&AI_tank[i]);if (my_tank.Exist && gap[14]++ % 2 == 0)Key();if (my_tank.Exist == 0 && my_tank.Revival < L && gap[15]++ % 15 == 0)//我方坦克复活Creat_My_T(&my_tank);            Move_B(bullet);            }Sleep(5);}return 0;
}

经典坦克大战——C++实现(附源码)相关推荐

  1. 用pygame做经典坦克大战游戏(附源码)

    首先,我们得分析这个项目的结构,设计出它的框架 坦克大战游戏项目开发 需求分析 1.分析项目需要多少个类 2.分析每个类有哪些方法 1.坦克类(敌方坦克,我方坦克) 移动.射击.展示 2.子弹类 移动 ...

  2. 经典日内策略——空中花园(附源码)

    空中花园属于期货日内突破策略,是一个相对"粗暴"的策略.   一般来说,如果开盘突破就入场,出错率较高.而这一策略增加了额外的条件,也就是开盘时要大幅高开或者低开,形成一个空窗,然 ...

  3. Python实现飞机大战-第二部分(附源码、素材、超详细教程)

    飞机大战第二部分 1.前言 2.飞机射击 2.1.添加子弹的相关设置 2.2.创建文件bullet.py 2.3.修改game_functions.py 2.4.修改mian.py 2.5.射击效果 ...

  4. 100行JS代码实现❤坦克大战js小游戏源码 HTML5坦克大战游戏代码(HTML+CSS+JavaScript )

    坦克大战js小游戏源码 HTML5坦克大战游戏代码(HTML+CSS+JavaScript ) HTML5坦克大战网页小游戏,完美还原小霸王学习机效果,以坦克战斗及保卫基地为主题,属于策略型类游戏. ...

  5. 熬夜整理出了70个清华大佬都在用的Python经典练手项目【附源码】

    我们都知道,不管学习那门语言最终都要做出实际的东西来,而对于编程而言,这个实际的东西当然就是项目啦,不用我多说大家都知道学编程语言做项目的重要性. 于是,小编熬了几个通宵,终于整理出了70个清华大佬都 ...

  6. 《游戏学习》JAVA版坦克大战课程设计及源码

    1.功能设计 游戏要有图形用户界面,界面能够反映游戏所有的细节. 界面中要有坦克,墙,树林,河流. 界面中要有一个"家","家"被攻击中则输了游戏. 坦克分两种 ...

  7. Python制作六款经典的童年游戏(附源码)

    这里小林分享一下6个python可以制作的经典游戏,看看有没有你的菜, 代码链接放在文末 对了以下游戏皆是小学六年级的代码水平 如有不适,赶快学习 1.雷电 使用模块:pygame 代码长度:490 ...

  8. 《Java语言程序设计——坦克大战单机游戏》源码以及实验报告

    一.引言 游戏本身是一种娱乐方式,带给人无尽的乐趣,而且游戏行业的发展前景也将会是是带动周边相关行业的发展.为了去满足不同的游戏爱好者的要求,对做游戏开发的人的要求也会越来越高.本次Java语言程序设 ...

  9. Python3+pygame实现有趣好玩的飞机大战游戏(附源码及素材)

    版权声明:原创不易,本文禁止抄袭.转载,侵权必究! 目录 一.开发环境 二.功能模块 三.游戏效果 四.完整项目下载 五.作者Info 一.开发环境 开发环境 :Windows10 Python3.6 ...

  10. python没有pygame_Python制作十款经典的童年游戏(附源码)

    不知道行友们每年六一是怎么度过的,行哥的童年是在游戏世界里度过.这里行哥分享一下十个python可以制作的经典游戏,看看有没有你的菜,代码链接放在文末 对了以下游戏皆是小学六年级的代码水平 如有不适, ...

最新文章

  1. numpy使用np.argmax函数获取一维数组中最大值所在的索引(index of largest value in numpy array with np.argmax)
  2. 你可能不清楚的 Vue Router 深度用法(二)
  3. Redis如何支持高并发的访问
  4. 如何在Windows Server 2016上配置iSCSI启动器
  5. JointJS绘制流程图
  6. 外点惩罚函数法matlab程序例子,外点罚函数优化实例.doc
  7. 与报文交换比较,分组交换有哪些优点?
  8. 网站跳出率的相关要点介绍 1
  9. Maven学习记录之依赖问题 Missing artifact org.aspectj:aspectjweaver:jar:1.8.0.M1
  10. CCF-分蛋糕-Java
  11. 常见的http状态码有哪些?分别表示什么意思?
  12. Affinity Derivation and Graph Merge for Instance Segmentation阅读笔记
  13. html人物属性代码,辐射4初始人物超强属性代码一览
  14. 分辨率PPI与DPI(转)
  15. android打开cad卡顿,两万高配置电脑使用CAD非常卡顿怎么办
  16. juniper SRX55 简单配置
  17. 淘宝分布式数据库是如何实现高可用的
  18. 杨辉三角 C语言实现【一维数组】
  19. 逻辑回归优化算法总结一
  20. 计算机硬件英语对话,关于电脑问题的英语对话

热门文章

  1. 舍得网-开发问题(学习别人经验)
  2. NvRam增加记录恢复出厂设置次数(下)
  3. 单片机蜂鸣器的控制程序与驱动电路图
  4. time stamp convert
  5. Teraterm 脚本
  6. 解决了Microsoft Visual C++ Build Tools下载/解决Visual C++ 14.0 is required的问题
  7. 看完这篇解决你99%的运维安全陋习,快别踩坑了!
  8. kindle上网看其他网址_几个超赞的免费电子书下载网站(支持kindle)!
  9. 好压 v6.3.11130 绿色纯净版(编程必备软件)
  10. AutoRunner自动化测试工具下载地址及安装步骤-泽众云测试