C++坦克大战源代码

  源码:

#include <iostream>
#include <time.h> 
#include <windows.h>#define W 1       //上
#define S 2         //下
#define A 3         //左
#define D 4          //右
#define L 5       // 坦克有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,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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,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;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/44285.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【会议征稿信息】第二届信息学,网络与计算技术国际学术会议(ICINC2023)

2023年第二届信息学&#xff0c;网络与计算技术国际学术会议(ICINC2023) 2023 2nd International Conference on Informatics,Networking and Computing (ICINC 2023) 2023年第二届信息学&#xff0c;网络与计算技术国际学术会议(ICINC2023)将于2023年10月27-29日于中国武汉召…

首起针对国内金融企业的开源组件投毒攻击事件

简述 2023年8月9日&#xff0c;墨菲监控到用户名为 snugglejack_org (邮件地址&#xff1a;SnuggleBearrxxhotmail.com&#xff09;的用户发布到 NPM 仓库中的 ws-paso-jssdk 组件包具有发向 https://ql.rustdesk[.]net 的可疑流量&#xff0c;经过确认该组件包携带远控脚本&a…

.NET Core6.0使用NPOI导入导出Excel

一、使用NPOI导出Excel //引入NPOI包 HTML <input type"button" class"layui-btn layui-btn-blue2 layui-btn-sm" id"ExportExcel" onclick"ExportExcel()" value"导出" />JS //导出Excelfunction ExportExcel() {…

aardio开发语言Excel数据表读取修改保存实例练习

import win.ui; /*DSG{{*/ var winform win.form(text"aardio form";right759;bottom479) winform.add( buttonEnd{cls"button";text"末页";left572;top442;right643;bottom473;z6}; buttonExcelRead{cls"button";text"读取Exce…

Qt实现简单的漫游器

文章目录 Qt的OpenGL窗口GLSL的实现摄像机类的实现简单的漫游器 Qt的OpenGL窗口 Qt主要是使用QOpenGLWidget来实现opengl的功能。  QOpenGLWidget 提供了三个便捷的虚函数&#xff0c;可以重载&#xff0c;用来重新实现典型的OpenGL任务&#xff1a; paintGL&#xff1a;渲染…

【数据库系统】--【5】DBMS查询处理

DBMS查询处理 01查询处理概述02查询编译词法、语法分析语义分析查询重写查询优化 03查询执行算法04查询执行模型 01查询处理概述 02查询编译 词法、语法分析 语义分析 查询重写 查询优化 03查询执行算法 04查询执行模型 小结 ● 查询处理概述 ● 查询编译 词法、语法分析语义分…

2021年06月 C/C++(三级)真题解析#中国电子学会#全国青少年软件编程等级考试

第1题&#xff1a;数对 给定2到15个不同的正整数&#xff0c;你的任务是计算这些数里面有多少个数对满足&#xff1a;数对中一个数是另一个数的两倍。 比如给定1 4 3 2 9 7 18 22&#xff0c;得到的答案是3&#xff0c;因为2是1的两倍&#xff0c;4是2个两倍&#xff0c;18是9的…

CNN卷积详解(三)

一、卷积层的计算 4 ∗ * ∗ 4的输入矩阵 I I I 和 3 ∗ * ∗ 3 的卷积核 K K K: 在步长&#xff08;stride&#xff09;为 1 时&#xff0c;输出的大小为 ( 4 − 3 1 ) ( 4 − 3 1) 计算公式&#xff1a; ● 输入图片矩阵 I I I 大小&#xff1a; w w w w ww ●…

微服务系列文章之 SpringBoot 最佳实践

Spring Boot 是一种广泛使用且非常流行的企业级高性能框架。 以下是一些最佳实践和一些技巧&#xff0c;我们可以使用它们来改进 Spring Boot 应用程序并使其更加高效。 Spring Boot 的四大核心 1、自动配置 针对很多Spring应用程序和常见的应用功能&#xff0c;Spring Boo…

攻防世界-fileclude

原题 解题思路 直接展示源码了&#xff0c;flag.php应该存放了flag&#xff0c;在file1与file2都不为空且file2是“hello ctf”时file1将被导入。接下来做法很明显&#xff0c;让file为flag.php&#xff0c;file2为“hello ctf”。“?file1php://filter/readconvert.base64-en…

Open3D 最小二乘拟合空间直线(方法一)

目录 一、算法原理1、空间直线2、最小二乘法拟合二、代码实现三、结果展示本文由CSDN点云侠原创,原文链接。如果你不是在点云侠的博客中看到该文章,那么此处便是不要脸的爬虫。 一、算法原理 1、空间直线 x −

基于web的停车场收费管理系统/基于springboot的停车场管理系统

摘 要 随着汽车工业的迅猛发展&#xff0c;我国汽车拥有量急剧增加。停车场作为交通设施的组成部分,随着交通运输的繁忙和不断发展&#xff0c;人们对其管理的要求也不断提高&#xff0c;都希望管理能够达到方便、快捷以及安全的效果。停车场的规模各不相同,对其进行管理的模…

ElasticSearch 数据聚合、自动补全(自定义分词器)、数据同步

文章目录 数据聚合一、聚合的种类二、DSL实现聚合1、Bucket&#xff08;桶&#xff09;聚合2、Metrics&#xff08;度量&#xff09;聚合 三、RestAPI实现聚合 自动补全一、拼音分词器二、自定义分词器三、自动补全查询四、实现搜索款自动补全&#xff08;例酒店信息&#xff0…

【rust/egui】(三)看看template的app.rs:序列化、持久化存储

说在前面 rust新手&#xff0c;egui没啥找到啥教程&#xff0c;这里自己记录下学习过程环境&#xff1a;windows11 22H2rust版本&#xff1a;rustc 1.71.1egui版本&#xff1a;0.22.0eframe版本&#xff1a;0.22.0上一篇&#xff1a;这里 serde app.rs中首先定义了我们的Templ…

Git判断本地是否最新

场景需求 需要判断是否有新内容更新,确定有更新之后执行pull操作&#xff0c;然后pull成功之后再将新内容进行复制到其他地方 pgit log -1 --prettyformat:"%H" HEAD -- . "origin/HEAD" rgit rev-parse origin/HEAD if [[ $p $r ]];thenecho "Is La…

域名解析和代理

购买域名 这里使用腾讯云进行购买。 对域名进行解析 通过添加记录接口对域名进行解析。 此时我们的服务器地址就被解析到域名上了。 我们可以通过以下格式进行访问&#xff1a; [域名]:[对应的项目端口] 效果为下: 通过nginx进行代理 如果我们使用上述的方式进行访问还是…

【hive】hive分桶表的学习

hive分桶表的学习 前言&#xff1a; 每一个表或者分区&#xff0c;hive都可以进一步组织成桶&#xff0c;桶是更细粒度的数据划分&#xff0c;他本质不会改变表或分区的目录组织方式&#xff0c;他会改变数据在文件中的分布方式。 分桶规则&#xff1a; 对分桶字段值进行哈…

react之react-redux的介绍、基本使用、获取状态、分发动作、数据流、reducer的分离与合并等

react之react-redux的介绍、基本使用、获取状态、分发动作、数据流、reducer的分离与合并等 一、react-redux介绍二、React-Redux-基本使用三、获取状态useSelector四、分发动作useDispatch五、 Redux 数据流六、代码结构七、ActionType的使用八、Reducer的分离与合并九、购物挣…

计算机视觉的应用11-基于pytorch框架的卷积神经网络与注意力机制对街道房屋号码的识别应用

大家好&#xff0c;我是微学AI&#xff0c;今天给大家介绍一下计算机视觉的应用11-基于pytorch框架的卷积神经网络与注意力机制对街道房屋号码的识别应用&#xff0c;本文我们借助PyTorch&#xff0c;快速构建和训练卷积神经网络&#xff08;CNN&#xff09;等模型&#xff0c;…

【Redis从头学-5】Redis中的List数据类型实战场景之天猫热销榜单

&#x1f9d1;‍&#x1f4bb;作者名称&#xff1a;DaenCode &#x1f3a4;作者简介&#xff1a;啥技术都喜欢捣鼓捣鼓&#xff0c;喜欢分享技术、经验、生活。 &#x1f60e;人生感悟&#xff1a;尝尽人生百味&#xff0c;方知世间冷暖。 &#x1f4d6;所属专栏&#xff1a;Re…