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.rhkb.cn/news/99550.html

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

相关文章

新榜 | CityWalk本地生活商业价值洞察报告

如果说现在有人问&#xff0c;最新的网络热词是什么? “CityWalk”&#xff0c;这可能是大多数人的答案。 近段时间&#xff0c;“CityWalk”刷屏了各种社交媒体&#xff0c;给网友们带来了一场“城市漫步”之旅。 脱离群体狂欢&#xff0c;这个在社交媒体引发热议的词汇背后又…

初识C语言

目录 一、C语言的概念 二、第一个C语言程序 三、数据类型 四、变量和常量 4.1 变量定义方法 4.2 变量的命名 4.3 变量的分类 4.4 变量的作用域和生命周期 4.5 常量 五、字符串和转义字符 5.1 字符串 5.2 转义字符 六、注释 七、选择语句 八、循环语句 九、函数 十、数…

【腾讯云Cloud Studio实战训练营】使用Cloud Studio社区版快速构建React完成点餐H5页面还原

陈老老老板&#x1f9b8; &#x1f468;‍&#x1f4bb;本文专栏&#xff1a;生活&#xff08;主要讲一下自己生活相关的内容&#xff09; &#x1f468;‍&#x1f4bb;本文简述&#xff1a;生活就像海洋,只有意志坚强的人,才能到达彼岸。 &#x1f468;‍&#x1f4bb;上一篇…

快速学会创建uni-app项目并了解pages.json文件

(创作不易&#xff0c;感谢有你&#xff0c;你的支持&#xff0c;就是我前行的最大动力&#xff0c;如果看完对你有帮助&#xff0c;请留下您的足迹&#xff09; 目录 前言 创建 uni-app 项目 通过 HBuilderX 创建 pages.json pages style globalStyle tabBar 前言…

【Go】锁相关

文章目录 Mutex锁mutex源码分析LockUnLock mutex两种运行模式mutex normal 正常模式自旋 mutex starvation 饥饿模式 锁的底层实现类型 RWMutexRWMutex 实现其他共享内存线程安全的方式 思考如何设计一个并发更高的锁&#xff1f; Mutex锁 mutex源码分析 Locker接口&#xff…

MySQL流程控制

流程控制 顺序结构&#xff1a; 程序从上往下依次执行分支结构&#xff1a; 程序按条件进行选择执行&#xff0c;从两条或多条路径中选择一条执行。循环结构&#xff1a; 程序满足一定条件下&#xff0c;重复执行一组语句 针对于MySQL的流程控制语句主要有3类。注意&#xff…

stack,queue,deque的使用

1.stack是后进先出的&#xff0c;这也影响其对应的接口&#xff0c;所能实现的功能也有限&#xff0c;其中主要的功能如下&#xff1a; void test_stack1() {stack<int> st;st.push(1);st.push(2);st.push(3);st.push(4);st.push(5);st.push(6);while (!st.empty()){c…

香港服务器备案会通过吗?

​  对于企业或个人来说&#xff0c;合规备案是网络运营的基本要求&#xff0c;也是保护自身权益的重要举措。以下内容围绕备案展开话题&#xff0c;希望为您解开疑惑。 香港服务器备案会通过吗? 目前&#xff0c;香港服务器无法备案&#xff0c;这是由于国内管理规定的限制…

netty(一):NIO——处理消息边界

处理消息边界 为什么要处理边界 因为会存在半包和粘包的问题 1.客户端和服务端约定一个固定长度 优点&#xff1a;简单 缺点&#xff1a;可能造成浪费 2.客户端与服务端约定一个固定分割符 *缺点 效率低 3.先发送长度&#xff0c;再发送数据 TLV格式&#xff1a; type…

Linux问题--docker启动mysql时提示3306端口被占用

问题描述&#xff1a; 解决方法&#xff1a; 1.如果需要kill掉mysqld服务可以先通过 lsof -i :3306 2. 查询到占用3306的PID&#xff0c;随后使用 kill -15 PID 来kill掉mysqld服务。 最后结果

我的创作纪念日(C++修仙练气期总结)

分享自己最喜欢的一首歌&#xff1a;空想フォレスト—伊東歌詞太郎 机缘 现在想想自己在CSDN创作的原因&#xff0c;一开始其实就是想着拿着博客当做自己的学习笔记&#xff0c;笔记嘛&#xff0c;随便写写&#xff0c;自己看得懂就ok了的态度凸(艹皿艹 )。也是用来作为自己学习…

Android动画进阶指北

原文链接 Android Animation Advanced Tricks 前面的文章介绍了动画的基本使用方法&#xff0c;本文来聊一聊涉及到动画的高级技巧&#xff0c;以及一些非常优质的学习资源和动画三方库和框架。 页面之间的过渡动画 常规的动画都是针对某一页面上的某个元素做动画&#xff0c…

CentOS系统环境搭建(十四)——CentOS7.9安装elasticsearch-head

centos系统环境搭建专栏&#x1f517;点击跳转 关于node的安装请看上一篇CentOS系统环境搭建&#xff08;十三&#xff09;——CentOS7安装nvm&#xff0c;&#x1f517;点击跳转。 CentOS7.9安装elasticsearch-head 文章目录 CentOS7.9安装elasticsearch-head1.下载2.解压3.修…

Vue3.X 掌握基础知识(二)

接着上一篇 Vue3.X 创建简单项目&#xff08;一&#xff09;&#xff0c;我们接着往下了解Vue的一些简单的功能。 一、HomeView.vue的改写复习 这里我们介绍数据的绑定、判断、for循环等功能。 <template><h1>hello world</h1><p v-text"data.na…

计算机网络基础

前言 在你立足处深挖下去,就会有泉水涌出!别管蒙昧者们叫嚷:“下边永远是地狱!” 博客主页&#xff1a;KC老衲爱尼姑的博客主页 博主的github&#xff0c;平常所写代码皆在于此 共勉&#xff1a;talk is cheap, show me the code 作者是爪哇岛的新手&#xff0c;水平很有限&…

C# 设置、获取程序,产品版本号

右键&#xff0c;程序属性。打开“程序集信息” 选择需要设置的版本信息。下面的代码&#xff0c;获取不同的设置内容。 string 其他 Assembly.GetExecutingAssembly().FullName; string 程序集版本 Assembly.GetExecutingAssembly().G…

Tip-Adapter: Training-free Adaption of CLIP for Few-shot Classification

Tip-Adapter: Training-free Adaption of CLIP for Few-shot Classification (Paper reading) Renrui Zhang&#xff0c;Shanghai AI Laboratory&#xff0c;ECCV2022&#xff0c;Cited:45&#xff0c;Code&#xff0c;Paper 1. 前言 对比式视觉-语言预训练&#xff0c;也称…

javaScript:对函数的认识与应用

目录 一.前言 二.函数介绍 A.函数的分类 1.自定义函数 示例 2.匿名函数 声明匿名函数 计时器也是匿名函数 3.立即执行函数 解释 示例 B.函数的返回值 没有参数&#xff0c;没有返回值的函数 示例 没有参数&#xff0c;有返回值的函数 示例 有参数&#xff0c;有…

【Leetcode】108. 将有序数组转换为二叉搜索树

一、题目 1、题目描述 给你一个整数数组 nums ,其中元素已经按 升序 排列,请你将其转换为一棵 高度平衡 二叉搜索树。 高度平衡 二叉树是一棵满足「每个节点的左右两个子树的高度差的绝对值不超过 1 」的二叉树。 示例1: 输入:nums = [-10,-3,0,5,9] 输出:[0,-3,9,-1…

java学习——二叉树

二叉树的种类&#xff1a; 满二叉树&#xff1a;如果一棵二叉树只有度为0的结点和度为2的结点&#xff0c;并且度为0的结点在同一层上&#xff0c;则这棵二叉树为满二叉树。 完全二叉树&#xff1a;在完全二叉树中&#xff0c;除了最底层节点可能没填满外&#xff0c;其余每层…