C语言游戏实战(11):贪吃蛇大作战(多人对战)

 前言:

这款贪吃蛇大作战是一款多人游戏,玩家需要控制一条蛇在地图上移动,吞噬其他蛇或者食物来增大自己的蛇身长度和宽度。本游戏使用C语言和easyx图形库编写,旨在帮助初学者了解游戏开发的基本概念和技巧。

在开始编写代码之前,我们需要先了解一下游戏的基本规则和功能:

1. 游戏界面:游戏界面是一个矩形区域,玩家可以在这个区域内控制蛇的移动。

2. 玩家贪吃蛇:玩家控制的小球可以在游戏界面内自由移动,按下空格键可以加速。

3. ai贪吃蛇:ai贪吃蛇会在游戏界面中随机移动。

4. 食物:食物会在游戏界面中随机生成一定的数量,贪吃蛇通过吃食物可以增加蛇的长度和宽度。

5. 贪吃蛇的淘汰:当某条贪吃蛇的头部碰到了其他蛇的尾部或游戏界面的边界,这条蛇就会立马死亡,并且在死亡的地方身体变为食物。

接下来,我们将通过以下几个步骤来实现这个游戏:

1. 初始化游戏界面和的基本游戏元素的信息。

2. 处理键盘输入,实现玩家控制贪吃蛇的移动和加速。

3. 控制ai贪吃蛇的移动。

4. 检测贪吃蛇吞噬食物,并增加相应的长度和宽度。

5. 检测贪吃蛇的死亡。

通过学习这个游戏的开发过程,初学者将能够掌握C语言编程和easyx图形库的基本技巧。

1. 初始化游戏界面和基本信息

这款游戏的主要要素有:蛇头、蛇身、食物,而蛇头又分为ai蛇头,与玩家1蛇头,蛇身分为ai蛇身,与玩家1蛇身,其中这些要素都是圆或者由圆组成的,而圆基本特点有半径、颜色、坐标,所以我们需要创建一个包含这几个特点的结构体。

struct ball
{int x;int y;float r;//存放颜色的变量DWORD color;
};
struct ball player;
struct ball player2;
struct ball Ai[Ai_num];
struct ball food[food_num];
struct ball player_body2[9999];
struct ball Ai_body[Ai_num][9999];

(1)初始化玩家贪吃蛇的信息

开始游戏的时候设置玩家1的位置为(Wide / 2,Hight / 2)(这个可以根据自己的意愿设置),然后就是设置蛇尾的位置了,蛇尾是许多圆相连而成的,所以我们需要设置一个存放蛇尾信息的结构体数组,然后将蛇尾数组的中每个初始化的元素(圆)“连接”在头的右侧,也就是使这个数组中的每个元素的x坐标从头部的坐标开始依次减去一定的值,我们将这个值设为一个圆的直径大小即可。

struct ball player;
struct ball player_body[9999];//玩家1-头
player.x = Wide / 2;
player.y = Hight / 2;
player.r = 10;
//玩家1——蛇身
player_body[0].x = player.x - player.r;
player_body[0].y = player.y;
player_body[0].r = player.r;

(2)初始化食物的信息

食物就是一些半径为5的圆,利用随机值将它们的位置随机分布在游戏地图中。为了使食物的颜色不这么单一,所以颜色也利用随机数随机生成RGB的参数,从而随机生成食物的颜色。

RGB色彩模式是一种工业标准,它通过红(R)、绿(G)、蓝(B)三个颜色通道的组合来表示不同的颜色。每个通道通常分配一个0到255之间的数值,其中0表示该颜色通道没有亮度,255表示该颜色通道的最大亮度。通过调整这三个通道的值,可以生成几乎所有人类视觉系统能够感知的颜色。

	//食物for (int i = 0; i < food_num; i++){food[i].x = rand() % Wide_map;food[i].y = rand() % Hight_map;food[i].r = 5;food[i].color = RGB(rand() % 256, rand() % 256, rand() % 256);}

 (3)初始化ai贪吃蛇的信息

ai的数量不止一条所以,ai的蛇头也不止一个,所以我们需要创建一个结构体数组在存放蛇头的信息,之后就是生成蛇尾,蛇尾的信息则需要我们创建一个二维结构体数组来存放。

struct ball Ai[Ai_num];
struct ball Ai_body[Ai_num][9999];//ai头
for (int i = 0; i < Ai_num; i++)
{Ai[i].x = rand() % Wide_map;Ai[i].y = rand() % Hight_map;Ai[i].r = 10;
}
//ai身体
for (int i = 0; i < Ai_num; i++)
{Ai_body_num[i] = 5;Ai_body[i][0].x = Ai[i].x - Ai[i].r;Ai_body[i][0].y = Ai[i].y;Ai_body[i][0].r = Ai[i].r;for (int j = 1; j < Ai_body_num[i]; j++){Ai_body[i][j].x = Ai_body[i][j - 1].x - Ai_body[i][j - 1].r;Ai_body[i][j].y = Ai_body[i][j - 1].y;Ai_body[i][j].r = Ai_body[i][j - 1].r;}
}

2. 显示在窗口绘制游戏信息

在easyx图形库中提供了一个画实心圆的函数—solidcircle函数,通过它我们就可以在窗口中显示圆了,但显示出的圆默认颜色为白色,为了区分不同的圆,我们还需使用setfillcolor函数来改变小球的颜色。因为显示的函数、玩家操作小球的函数等函数都是放在同一个while循环重复执行的,这样就会重复绘制信息,所以我们还需要用到一个清屏函数cleardevice。为了使游戏界面更美观可以使用setbkcolor函数修改窗口的背景颜色,以及使用line函数在窗口中画一些线,函数setlinecolor可以改变线的颜色。 

void show()
{srand((unsigned)time(NULL));SetWorkingImage(&map);cleardevice();setbkcolor(RGB(236, 236, 244));//划线颜色setlinecolor(RGB(222, 222, 230));//划线for (int i = 0; i < Wide_map; i += 20){line(i, 0, i, Hight_map);}for (int i = 0; i < Hight_map; i += 20){line(0, i, Wide_map, i);}//食物for (int i = 0; i < food_num; i++){setfillcolor(food[i].color );solidcircle(food[i].x, food[i].y, food[i].r);}//玩家1——蛇头setfillcolor(RED);solidcircle(player.x, player.y, player.r);//玩家1——蛇身for (int i = 0; i < body_num; i++){setfillcolor(RGB(149, 236, 105));solidcircle(player_body[i].x, player_body[i].y, player_body[i].r);}//玩家2——蛇头setfillcolor(RGB(221, 221, 2));solidcircle(player2.x, player2.y, player2.r);//玩家2——蛇身for (int i = 0; i < body_num2; i++){setfillcolor(RGB(149, 236, 105));solidcircle(player_body2[i].x, player_body2[i].y, player_body2[i].r);}//ai蛇头for (int i = 0; i < Ai_num; i++){setfillcolor(RGB(229, 0, 0));solidcircle(Ai[i].x, Ai[i].y, Ai[i].r);}//ai蛇身for (int i = 0; i < Ai_num; i++){for (int j = 0; j < Ai_body_num[i]; j++){setfillcolor(RGB(229, 196, 0));solidcircle(Ai_body[i][j].x, Ai_body[i][j].y, Ai_body[i][j].r);}}//蛇尸体for (int i = 0; i < Ai_num; i++){for (int j = 0; j < Ai_body_food_num[i]; j++){setfillcolor(Ai_body_food[i][j].color );solidcircle(Ai_body_food[i][j].x, Ai_body_food[i][j].y, Ai_body_food[i][j].r);}}//玩家1视角int x = player.x - (Wide / 2) ;int y = player.y - (Hight / 2);//防止窗口越界if (x < -Wide / 4){x = -Wide / 4;}if (y < 0){y = 0;}if (x > Wide_map - Wide){x = Wide_map - Wide;}if (y > Hight_map - Hight){y = Hight_map - Hight;}//玩家2视角int x2 = player2.x - (Wide / 2);int y2 = player2.y - (Hight / 2);//防止窗口越界if (x2 < -Wide / 4){x2 = -Wide / 4;}if (y2 < 0){y2 = 0;}if (x2 > Wide_map - Wide){x2 = Wide_map - Wide;}if (y2 > Hight_map - Hight){y2 = Hight_map - Hight;}settextcolor(RGB(7, 19, 62));TCHAR buffer[50];TCHAR buffer1[50];swprintf_s(buffer, _T("%d"), score);swprintf_s(buffer1, _T("%d"), kill);setbkmode(TRANSPARENT);settextstyle(20, 0, _T("宋体"));outtextxy(player.x, player.y - player.r * 4 - 20, _T("长度:"));outtextxy(player.x + 50, player.y - player.r * 4 - 20, buffer);outtextxy(player.x, player.y - player.r * 4, _T("击杀:"));outtextxy(player.x + 50, player.y - player.r * 4, buffer1);TCHAR buffer2[50];TCHAR buffer3[50];swprintf_s(buffer2, _T("%d"), score2);swprintf_s(buffer3, _T("%d"), kill2);outtextxy(player2.x, player2.y - player2.r * 4 - 20, _T("长度:"));outtextxy(player2.x + 50, player2.y - player2.r * 4 - 20, buffer2);outtextxy(player2.x, player2.y - player2.r * 4, _T("击杀:"));outtextxy(player2.x + 50, player2.y - player2.r * 4, buffer3);SetWorkingImage();//把map输出到窗口上putimage(0, 0, Wide / 2, Hight, &map, x + Wide / 4, y);putimage(Wide/2, 0, Wide/2, Hight, &map, x2 + Wide / 4, y2);
}

3. 玩家控制贪吃蛇移动

控制蛇的移动分为两步进行操作,一步是玩家控值蛇头的移动,另一部则是蛇尾跟随蛇头的移动。

(1)玩家控制蛇头的移动

在这里需要用到GetAsyncKeyState(vk virtual key)函数获取异步按键状态,其中vk virtual key是虚拟键值,如果接受到这个虚拟键值,它会返回真。0x20、0x41、0x44、0x57、83分别是空格键、a、d、w、s的虚拟键值。

为了保持蛇运动的持续性,不管我们按不按移动键蛇头的坐标都是应该变化的即在游戏的每次循环中都是应该执行蛇头的x坐标+=一个值,蛇头的y坐标+=一个值这两个表达式的,其中这两个值等于蛇的移动速度大小,或者0,且这两个值不能同时为0。按键改变这两个值的正负号或者令其中一个为零,则可以改变蛇头移动的方向

//蛇速度
int player_speed = 10;int playerSpeedCol = 0;
int playerSpeedRow = 0;void Player_move1()
{//蛇头移动//玩家1//上左if (GetAsyncKeyState(0x57) && GetAsyncKeyState(0x41)){playerSpeedCol = -player_speed;playerSpeedRow = -player_speed;}//上右else if (GetAsyncKeyState(0x57) && GetAsyncKeyState(0x44)){playerSpeedCol = -player_speed;playerSpeedRow = player_speed;}//下右else if (GetAsyncKeyState(83) && GetAsyncKeyState(0x44)){playerSpeedCol = player_speed;playerSpeedRow = player_speed;}//下左else if (GetAsyncKeyState(83) && GetAsyncKeyState(0x41)){playerSpeedCol = player_speed;playerSpeedRow = -player_speed;}//左else if (GetAsyncKeyState(0x41)){playerSpeedRow = -player_speed;playerSpeedCol = 0;}//下else if (GetAsyncKeyState(83)){playerSpeedCol = player_speed;playerSpeedRow = 0;}//右else if (GetAsyncKeyState(0x44)){playerSpeedRow = player_speed;playerSpeedCol = 0;}//上else if (GetAsyncKeyState(0x57)){playerSpeedCol = -player_speed;playerSpeedRow = 0;}//加速if (GetAsyncKeyState(0x20)){if (playerSpeedRow > 0)playerSpeedRow = player_speed + 5;if (playerSpeedCol > 0)playerSpeedCol = player_speed + 5;if (playerSpeedRow < 0)playerSpeedRow = -player_speed - 5;if (playerSpeedCol < 0)playerSpeedCol = -player_speed - 5;}else{if (playerSpeedRow > 0)playerSpeedRow = player_speed;if (playerSpeedCol > 0)playerSpeedCol = player_speed;if (playerSpeedRow < 0)playerSpeedRow = -player_speed;if (playerSpeedCol < 0)playerSpeedCol = -player_speed;}//尾部处理int m = player.x;int n = player.y;player.x += playerSpeedRow;player.y += playerSpeedCol;int x = player_body[0].x;int y = player_body[0].y;player_body[0].x = m;player_body[0].y = n;for (int i = 1; i < body_num; i++){int a, b;if (i % 2 == 1){a = player_body[i].x;b = player_body[i].y;player_body[i].x = x;player_body[i].y = y;}else{x = player_body[i].x;y = player_body[i].y;player_body[i].x = a;player_body[i].y = b;}}
}

 (2)蛇尾跟随蛇头

蛇头移动后,蛇尾圆1(也就紧贴蛇头的蛇尾圆)则移动到蛇头移动前的位置,然后蛇尾圆2(也就是紧贴蛇尾圆1的蛇尾圆)则移动到蛇尾1移动前的位置,按照这种方式移动最终将所有的蛇尾圆移动完后,就完成了蛇尾的移动了。具体操作是蛇尾圆1移动前,我们需要用两个变量m,n将蛇尾圆1的x,y值(坐标值)记录下来,然后再用两个变量a,b将蛇尾圆2移动前的坐标值记录下来,最后将m、n的值传递给蛇尾圆2,这样就完成了蛇尾圆2的移动,移动完蛇尾圆2后m、n这两个变量就空了下来,就可以让这两个值记录下一个要移动的圆的坐标,然后重复上面的移动就可以移动完整个蛇尾了,所以整个蛇尾移动的过程中我们只需要设置四个变量就可以了。

成果展示:

贪吃蛇(多人对战)

源码:

#include<stdio.h>
#include<easyx.h>
#include<time.h>
#include<math.h>#define Wide 1420
#define Hight 660
#define Wide_map Wide*5
#define Hight_map Hight*5
#define food_num 2000
#define Ai_num 98
#define Ai_num2 100
IMAGE map(Wide_map, Hight_map);
int player_speed = 10;
int body_num = 5;int body_num2 = 5;int playerSpeedCol = 0;
int playerSpeedRow = 0;int playerSpeedCol2 = 0;
int playerSpeedRow2 = 0;int AiSpeedCol[Ai_num] = { 0 };
int AiSpeedRow[Ai_num] = { 0 };
int Ai_body_num[Ai_num] = { 0 };
int Ai_body_food_num[Ai_num] = { 0 };int score = 100;
int kill = 0;int score2 = 100;
int kill2 = 0;struct ball
{int x;int y;float r;DWORD color;
};
struct ball player;
struct ball player2;
struct ball Ai[Ai_num];
struct ball food[food_num];
struct ball player_body[9999];
struct ball player_body2[9999];
struct ball Ai_body[Ai_num][9999];
struct ball Ai_body_food[Ai_num][9999];
void init()
{srand((unsigned)time(NULL));//玩家1-头player.x = Wide / 2;player.y = Hight / 2;player.r = 10;//玩家1——蛇身player_body[0].x = player.x - player.r;player_body[0].y = player.y;player_body[0].r = player.r;for (int i = 1; i < body_num; i++){player_body[i].x = player_body[i - 1].x - player_body[i - 1].r;player_body[i].y = player_body[i - 1].y;player_body[i].r = player_body[i - 1].r;}//玩家2-头player2.x = Wide;player2.y = Hight / 2;player2.r = 10;//玩家2——蛇身player_body2[0].x = player2.x - player2.r;player_body2[0].y = player2.y;player_body2[0].r = player2.r;for (int i = 1; i < body_num2; i++){player_body2[i].x = player_body2[i - 1].x - player_body2[i - 1].r;player_body2[i].y = player_body2[i - 1].y;player_body2[i].r = player_body2[i - 1].r;}//食物for (int i = 0; i < food_num; i++){food[i].x = rand() % Wide_map;food[i].y = rand() % Hight_map;food[i].r = 5;food[i].color = RGB(rand() % 256, rand() % 256, rand() % 256);}//ai头for (int i = 0; i < Ai_num; i++){Ai[i].x = rand() % Wide_map;Ai[i].y = rand() % Hight_map;Ai[i].r = 10;}//ai身体for (int i = 0; i < Ai_num; i++){Ai_body_num[i] = 5;Ai_body[i][0].x = Ai[i].x - Ai[i].r;Ai_body[i][0].y = Ai[i].y;Ai_body[i][0].r = Ai[i].r;for (int j = 1; j < Ai_body_num[i]; j++){Ai_body[i][j].x = Ai_body[i][j - 1].x - Ai_body[i][j - 1].r;Ai_body[i][j].y = Ai_body[i][j - 1].y;Ai_body[i][j].r = Ai_body[i][j - 1].r;}}
}
//距离
int Distance(int x, int y, int x1, int y1)
{return sqrt((x - x1) * (x - x1) + (y - y1) * (y - y1));
}
//玩家操作
void Player_move1()
{//蛇头移动//玩家1//上左if (GetAsyncKeyState(0x57) && GetAsyncKeyState(0x41)){playerSpeedCol = -player_speed;playerSpeedRow = -player_speed;}//上右else if (GetAsyncKeyState(0x57) && GetAsyncKeyState(0x44)){playerSpeedCol = -player_speed;playerSpeedRow = player_speed;}//下右else if (GetAsyncKeyState(83) && GetAsyncKeyState(0x44)){playerSpeedCol = player_speed;playerSpeedRow = player_speed;}//下左else if (GetAsyncKeyState(83) && GetAsyncKeyState(0x41)){playerSpeedCol = player_speed;playerSpeedRow = -player_speed;}//左else if (GetAsyncKeyState(0x41)){playerSpeedRow = -player_speed;playerSpeedCol = 0;}//下else if (GetAsyncKeyState(83)){playerSpeedCol = player_speed;playerSpeedRow = 0;}//右else if (GetAsyncKeyState(0x44)){playerSpeedRow = player_speed;playerSpeedCol = 0;}//上else if (GetAsyncKeyState(0x57)){playerSpeedCol = -player_speed;playerSpeedRow = 0;}//加速if (GetAsyncKeyState(0x20)){if (playerSpeedRow > 0)playerSpeedRow = player_speed + 5;if (playerSpeedCol > 0)playerSpeedCol = player_speed + 5;if (playerSpeedRow < 0)playerSpeedRow = -player_speed - 5;if (playerSpeedCol < 0)playerSpeedCol = -player_speed - 5;}else{if (playerSpeedRow > 0)playerSpeedRow = player_speed;if (playerSpeedCol > 0)playerSpeedCol = player_speed;if (playerSpeedRow < 0)playerSpeedRow = -player_speed;if (playerSpeedCol < 0)playerSpeedCol = -player_speed;}//尾部处理int m = player.x;int n = player.y;player.x += playerSpeedRow;player.y += playerSpeedCol;int x = player_body[0].x;int y = player_body[0].y;player_body[0].x = m;player_body[0].y = n;for (int i = 1; i < body_num; i++){int a, b;if (i % 2 == 1){a = player_body[i].x;b = player_body[i].y;player_body[i].x = x;player_body[i].y = y;}else{x = player_body[i].x;y = player_body[i].y;player_body[i].x = a;player_body[i].y = b;}}//玩家2//上左if (GetAsyncKeyState(VK_UP) && GetAsyncKeyState(VK_LEFT)){playerSpeedCol2 = -player_speed;playerSpeedRow2 = -player_speed;}//上右else if (GetAsyncKeyState(VK_UP) && GetAsyncKeyState(VK_RIGHT)){playerSpeedCol2 = -player_speed;playerSpeedRow2 = player_speed;}//下右else if (GetAsyncKeyState(VK_DOWN) && GetAsyncKeyState(VK_RIGHT)){playerSpeedCol2 = player_speed;playerSpeedRow2 = player_speed;}//下左else if (GetAsyncKeyState(VK_DOWN) && GetAsyncKeyState(VK_LEFT)){playerSpeedCol2 = player_speed;playerSpeedRow2 = -player_speed;}//左else if (GetAsyncKeyState(VK_LEFT)){playerSpeedRow2 = -player_speed;playerSpeedCol2 = 0;}//下else if (GetAsyncKeyState(VK_DOWN)){playerSpeedCol2 = player_speed;playerSpeedRow2 = 0;}//右else if (GetAsyncKeyState(VK_RIGHT)){playerSpeedRow2 = player_speed;playerSpeedCol2 = 0;}//上else if (GetAsyncKeyState(VK_UP)){playerSpeedCol2 = -player_speed;playerSpeedRow2 = 0;}//加速if (GetAsyncKeyState(0x4D)){if (playerSpeedRow2 > 0)playerSpeedRow2 = player_speed + 5;if (playerSpeedCol2 > 0)playerSpeedCol2 = player_speed + 5;if (playerSpeedRow2 < 0)playerSpeedRow2 = -player_speed - 5;if (playerSpeedCol2 < 0)playerSpeedCol2 = -player_speed - 5;}else{if (playerSpeedRow2 > 0)playerSpeedRow2 = player_speed;if (playerSpeedCol2 > 0)playerSpeedCol2 = player_speed;if (playerSpeedRow2 < 0)playerSpeedRow2 = -player_speed;if (playerSpeedCol2 < 0)playerSpeedCol2 = -player_speed;}//尾部处理int m2 = player2.x;int n2 = player2.y;player2.x += playerSpeedRow2;player2.y += playerSpeedCol2;int x2 = player_body2[0].x;int y2 = player_body2[0].y;player_body2[0].x = m2;player_body2[0].y = n2;for (int i = 1; i < body_num2; i++){int a, b;if (i % 2 == 1){a = player_body2[i].x;b = player_body2[i].y;player_body2[i].x = x2;player_body2[i].y = y2;}else{x2 = player_body2[i].x;y2 = player_body2[i].y;player_body2[i].x = a;player_body2[i].y = b;}}
}//ai移动
void Ai_move()
{srand((unsigned)time(NULL));int count[Ai_num] = { 0 };for (int i = 0; i < Ai_num; i++){//随机移动count[i] = rand() % 8;//蛇头移动//上左if (count[i] == 0){AiSpeedCol[i] = -player_speed;AiSpeedRow[i] = -player_speed;}//上右else if (count[i] == 1){AiSpeedCol[i] = -player_speed;AiSpeedRow[i] = player_speed;}//下右else if (count[i] == 2){AiSpeedCol[i] = player_speed;AiSpeedRow[i] = player_speed;}//下左else if (count[i] == 3){AiSpeedCol[i] = player_speed;AiSpeedRow[i] = -player_speed;}//左else if (count[i] == 4){AiSpeedRow[i] = -player_speed;AiSpeedCol[i] = 0;}//下else if (count[i] == 5){AiSpeedCol[i] = player_speed;AiSpeedRow[i] = 0;}//右else if (count[i] == 6){AiSpeedRow[i] = player_speed;AiSpeedCol[i] = 0;}//上else if (count[i] == 7){AiSpeedCol[i] = -player_speed;AiSpeedRow[i] = 0;}//ai不触碰边界if (Ai[i].x >= Wide_map - player_speed){//左AiSpeedRow[i] = -player_speed;}else if (Ai[i].y >= Hight_map - player_speed){//上AiSpeedCol[i] = -player_speed;}else if (Ai[i].y <= player_speed){//下AiSpeedCol[i] = player_speed;}else if (Ai[i].x <= player_speed){//右AiSpeedRow[i] = player_speed;}//ai躲避玩家1身体for (int j = 0; j < body_num; j++){if (Distance(player_body[j].x, player_body[j].y, Ai[i].x, Ai[i].y) < Ai[i].r + player_body[i].r + 20){//左if (Ai[i].x < player_body[j].x){AiSpeedRow[i] = -player_speed;}//上if (Ai[i].y < player_body[j].y){AiSpeedCol[i] = -player_speed;}//下if (Ai[i].x > player_body[j].x){AiSpeedCol[i] = player_speed;}//右if (Ai[i].y > player_body[j].y){AiSpeedRow[i] = player_speed;}}}//ai躲避玩家2身体for (int j = 0; j < body_num2; j++){if (Distance(player_body2[j].x, player_body2[j].y, Ai[i].x, Ai[i].y) < Ai[i].r + player_body2[i].r + 20){//左if (Ai[i].x < player_body2[j].x){AiSpeedRow[i] = -player_speed;}//上if (Ai[i].y < player_body2[j].y){AiSpeedCol[i] = -player_speed;}//下if (Ai[i].x > player_body2[j].x){AiSpeedCol[i] = player_speed;}//右if (Ai[i].y > player_body2[j].y){AiSpeedRow[i] = player_speed;}}}//尾部处理int m = Ai[i].x;int n = Ai[i].y;Ai[i].x += AiSpeedRow[i];Ai[i].y += AiSpeedCol[i];int x = Ai_body[i][0].x;int y = Ai_body[i][0].y;Ai_body[i][0].x = m;Ai_body[i][0].y = n;for (int j = 1; j < Ai_body_num[i]; j++){int a, b;if (j % 2 == 1){a = Ai_body[i][j].x;b = Ai_body[i][j].y;Ai_body[i][j].x = x;Ai_body[i][j].y = y;}else{x = Ai_body[i][j].x;y = Ai_body[i][j].y;Ai_body[i][j].x = a;Ai_body[i][j].y = b;}}}
}
void eatfood()
{srand((unsigned)time(NULL));for (int i = 0; i < food_num; i++){//玩家1吃食物if (Distance(food[i].x, food[i].y, player.x, player.y) < player.r + food[i].r + player_speed){score += 3;player.r += 0.01;player_body[0].r = player.r;for (int j = 1; j < body_num; j++){player_body[j].r = player_body[j - 1].r;}food[i].x = rand() % Wide_map;food[i].y = rand() % Hight_map;food[i].r = 5;body_num += 1;player_body[body_num - 1].x = player_body[body_num - 2].x - player_body[body_num - 2].r;player_body[body_num - 1].y = player_body[body_num - 2].y;player_body[body_num - 1].r = player_body[body_num - 2].r;}//玩家2吃食物if (Distance(food[i].x, food[i].y, player2.x, player2.y) < player2.r + food[i].r + player_speed){score2 += 3;player2.r += 0.01;player_body2[0].r = player2.r;for (int j = 1; j < body_num2; j++){player_body2[j].r = player_body2[j - 1].r;}food[i].x = rand() % Wide_map;food[i].y = rand() % Hight_map;food[i].r = 5;body_num2 += 1;player_body2[body_num2 - 1].x = player_body2[body_num2 - 2].x - player_body2[body_num2 - 2].r;player_body2[body_num2 - 1].y = player_body2[body_num2 - 2].y;player_body2[body_num2 - 1].r = player_body2[body_num2 - 2].r;}//ai吃食物for (int j = 0; j < Ai_num; j++){if (Distance(food[i].x, food[i].y, Ai[j].x, Ai[j].y) <= Ai[i].r + food[i].r + player_speed * 3){Ai[j].r += 0.01;Ai_body[j][0].r = Ai[j].r;for (int z = 1; z < Ai_body_num[j]; z++){Ai_body[j][z].r = Ai_body[j][z - 1].r;}food[i].x = rand() % Wide_map;food[i].y = rand() % Hight_map;food[i].r = 5;food[i].color = RGB(rand() % 256, rand() % 256, rand() % 256);Ai_body_num[j] += 1;Ai_body[j][Ai_body_num[j] - 1].x = Ai_body[j][Ai_body_num[j] - 2].x - Ai_body[j][Ai_body_num[j] - 2].r;Ai_body[j][Ai_body_num[j] - 1].y = Ai_body[j][Ai_body_num[j] - 2].y;Ai_body[j][Ai_body_num[j] - 1].r = Ai_body[j][Ai_body_num[j] - 2].r;}}}for (int i = 0; i < Ai_num; i++){for (int j = 0; j < Ai_body_food_num[i]; j++){//玩家1吃尸体if (Distance(Ai_body_food[i][j].x, Ai_body_food[i][j].y, player.x, player.y)< player.r + Ai_body_food[i][j].r + player_speed){int v = rand() % food_num;score += Ai_body_food[i][j].r / 5 * 3;player.r += Ai_body_food[i][j].r / 5 * 0.01;player_body[0].r = player.r;for (int z = 1; z < body_num; z++){player_body[z].r = player_body[z - 1].r;}Ai_body_food[i][j].x = food[v].x;Ai_body_food[i][j].y = food[v].y;Ai_body_food[i][j].r = food[v].r;Ai_body_food[i][j].color = food[v].color;body_num += Ai_body_food[i][j].r / 5;player_body[body_num - 1].x = player_body[body_num - 2].x - player_body[body_num - 2].r;player_body[body_num - 1].y = player_body[body_num - 2].y;player_body[body_num - 1].r = player_body[body_num - 2].r;}//玩家2吃尸体if (Distance(Ai_body_food[i][j].x, Ai_body_food[i][j].y, player2.x, player2.y)< player2.r + Ai_body_food[i][j].r + player_speed){int v = rand() % food_num;score2 += Ai_body_food[i][j].r / 5 * 3;player2.r += Ai_body_food[i][j].r / 5 * 0.01;player_body2[0].r = player2.r;for (int z = 1; z < body_num2; z++){player_body2[z].r = player_body2[z - 1].r;}Ai_body_food[i][j].x = food[v].x;Ai_body_food[i][j].y = food[v].y;Ai_body_food[i][j].r = food[v].r;Ai_body_food[i][j].color = food[v].color;body_num2 += Ai_body_food[i][j].r / 5;player_body2[body_num2 - 1].x = player_body2[body_num2 - 2].x - player_body2[body_num2 - 2].r;player_body2[body_num2 - 1].y = player_body2[body_num2 - 2].y;player_body2[body_num2 - 1].r = player_body2[body_num2 - 2].r;}}}//ai吃尸体for (int p = 0; p < Ai_num; p++){for (int i = 0; i < Ai_num; i++){for (int j = 0; j < Ai_body_food_num[i]; j++){if (Distance(Ai_body_food[i][j].x, Ai_body_food[i][j].y, Ai[p].x, Ai[p].y) <Ai[p].r + Ai_body_food[i][j].r + player_speed){int v = rand() % food_num;Ai[p].r += Ai_body_food[i][j].r / 5 * 0.01;Ai_body[p][0].r = Ai[p].r;for (int z = 1; z < Ai_body_num[p]; z++){Ai_body[p][z].r = Ai_body[p][z - 1].r;}Ai_body_food[i][j].x = food[v].x;Ai_body_food[i][j].y = food[v].y;Ai_body_food[i][j].r = food[v].r;Ai_body_food[i][j].color = food[v].color;Ai_body_num[p] += Ai_body_food[i][j].r / 5;Ai_body[p][Ai_body_num[p] - 1].x = Ai_body[p][Ai_body_num[p] - 2].x - Ai_body[p][Ai_body_num[p] - 2].r;Ai_body[p][Ai_body_num[p] - 1].y = Ai_body[p][Ai_body_num[p] - 2].y;Ai_body[p][Ai_body_num[p] - 1].r = Ai_body[p][Ai_body_num[p] - 2].r;}}}}
}
void SnakeOut()
{//玩家1碰到边界if (player.x > Wide_map || player.x <0 || player.y >Hight_map || player.y < 0){body_num = 5;score = 100;kill = 0;//蛇player.x = Wide / 2;player.y = Hight / 2;player.r = 10;//蛇身player_body[0].x = player.x - player.r;player_body[0].y = player.y;player_body[0].r = player.r;for (int i = 1; i < body_num; i++){player_body[i].x = player_body[i - 1].x - player_body[i - 1].r;player_body[i].y = player_body[i - 1].y;player_body[i].r = player_body[i - 1].r;}}//玩家2碰到边界if (player2.x > Wide_map || player2.x <0 || player2.y >Hight_map || player2.y < 0){body_num2 = 5;score2 = 100;kill2 = 0;//蛇player2.x = Wide;player2.y = Hight / 2;player2.r = 10;//蛇身player_body2[0].x = player2.x - player2.r;player_body2[0].y = player2.y;player_body2[0].r = player2.r;for (int i = 1; i < body_num2; i++){player_body2[i].x = player_body2[i - 1].x - player_body2[i - 1].r;player_body2[i].y = player_body2[i - 1].y;player_body2[i].r = player_body2[i - 1].r;}}//玩家1吃玩家2蛇尾for (int i = 0; i < body_num2; i++){if (Distance(player_body2[i].x, player_body2[i].y, player.x, player.y) < player_body[i].r + player.r ){kill2 += 1;body_num = 5;score = 100;kill = 0;//蛇player.x = Wide / 2;player.y = Hight / 2;player.r = 10;//蛇身player_body[0].x = player.x - player.r;player_body[0].y = player.y;player_body[0].r = player.r;for (int i = 1; i < body_num; i++){player_body[i].x = player_body[i - 1].x - player_body[i - 1].r;player_body[i].y = player_body[i - 1].y;player_body[i].r = player_body[i - 1].r;}}}//玩家2吃玩家1蛇尾for (int i = 0; i < body_num; i++){if (Distance(player_body[i].x, player_body[i].y, player2.x, player2.y) < player_body[i].r + player2.r){kill += 1;body_num2 = 5;score2 = 100;kill2 = 0;//蛇player2.x = Wide;player2.y = Hight / 2;player2.r = 10;//蛇身player_body2[0].x = player2.x - player2.r;player_body2[0].y = player2.y;player_body2[0].r = player2.r;for (int i = 1; i < body_num2; i++){player_body2[i].x = player_body2[i - 1].x - player_body2[i - 1].r;player_body2[i].y = player_body2[i - 1].y;player_body2[i].r = player_body2[i - 1].r;}}}for (int i = 0; i < Ai_num; i++){//ai碰到边界if (Ai[i].x > Wide_map || Ai[i].x <0 || Ai[i].y >Hight_map || Ai[i].y < 0){//身体变成食物Ai_body_food_num[i] = Ai_body_num[i];for (int z = 1; z < Ai_body_num[i]; z++){Ai_body_food[i][z].x = Ai_body[i][z].x;Ai_body_food[i][z].y = Ai_body[i][z].y;Ai_body_food[i][z].r = Ai_body[i][z].r;Ai_body_food[i][z].color = RGB(rand() % 256, rand() % 256, rand() % 256);}Ai[i].x = rand() % Wide_map;Ai[i].y = rand() % Hight_map;Ai[i].r = 10;//ai身体Ai_body_num[i] = 5;Ai_body[i][0].x = Ai[i].x - Ai[i].r;Ai_body[i][0].y = Ai[i].y;Ai_body[i][0].r = Ai[i].r;for (int j = 1; j < Ai_body_num[i]; j++){Ai_body[i][j].x = Ai_body[i][j - 1].x - Ai_body[i][j - 1].r;Ai_body[i][j].y = Ai_body[i][j - 1].y;Ai_body[i][j].r = Ai_body[i][j - 1].r;}}//ai碰玩家1蛇尾for (int j = 0; j < body_num; j++){if (Distance(player_body[j].x, player_body[j].y, Ai[i].x, Ai[i].y) < Ai[i].r + player_body[i].r){kill += 1;//尾部变成食物Ai_body_food_num[i] = Ai_body_num[i];for (int z = 1; z < Ai_body_num[i]; z++){Ai_body_food[i][z].x = Ai_body[i][z].x;Ai_body_food[i][z].y = Ai_body[i][z].y;Ai_body_food[i][z].r = Ai_body[i][z].r;Ai_body_food[i][z].color = RGB(rand() % 256, rand() % 256, rand() % 256);}//重新生成aiAi[i].x = rand() % Wide_map;Ai[i].y = rand() % Hight_map;Ai[i].r = 10;//ai身体Ai_body_num[i] = 5;Ai_body[i][0].x = Ai[i].x - Ai[i].r;Ai_body[i][0].y = Ai[i].y;Ai_body[i][0].r = Ai[i].r;for (int z = 1; z < Ai_body_num[i]; z++){Ai_body[i][z].x = Ai_body[i][z - 1].x - Ai_body[i][z - 1].r;Ai_body[i][z].y = Ai_body[i][z - 1].y;Ai_body[i][z].r = Ai_body[i][z - 1].r;}}}//ai碰玩家2蛇尾for (int j = 0; j < body_num2; j++){if (Distance(player_body2[j].x, player_body2[j].y, Ai[i].x, Ai[i].y) < Ai[i].r + player_body2[i].r)	{kill2 += 1;//尾部变成食物Ai_body_food_num[i] = Ai_body_num[i];for (int z = 1; z < Ai_body_num[i]; z++){Ai_body_food[i][z].x = Ai_body[i][z].x;Ai_body_food[i][z].y = Ai_body[i][z].y;Ai_body_food[i][z].r = Ai_body[i][z].r;Ai_body_food[i][z].color = RGB(rand() % 256, rand() % 256, rand() % 256);}//重新生成aiAi[i].x = rand() % Wide_map;Ai[i].y = rand() % Hight_map;Ai[i].r = 10;//ai身体Ai_body_num[i] = 5;Ai_body[i][0].x = Ai[i].x - Ai[i].r;Ai_body[i][0].y = Ai[i].y;Ai_body[i][0].r = Ai[i].r;for (int z = 1; z < Ai_body_num[i]; z++){Ai_body[i][z].x = Ai_body[i][z - 1].x - Ai_body[i][z - 1].r;Ai_body[i][z].y = Ai_body[i][z - 1].y;Ai_body[i][z].r = Ai_body[i][z - 1].r;}}}//玩家1碰ai蛇尾for (int j = 0; j < Ai_body_num[i]; j++){if (Distance(Ai_body[i][j].x, Ai_body[i][j].y, player.x, player.y) < player.r + Ai_body[i][j].r){body_num = 5;score = 100;kill = 0;//蛇player.x = Wide / 2;player.y = Hight / 2;player.r = 10;//蛇身player_body[0].x = player.x - player.r;player_body[0].y = player.y;player_body[0].r = player.r;for (int i = 1; i < body_num; i++){player_body[i].x = player_body[i - 1].x - player_body[i - 1].r;player_body[i].y = player_body[i - 1].y;player_body[i].r = player_body[i - 1].r;}}}//玩家2碰ai蛇尾for (int j = 0; j < Ai_body_num[i]; j++){if (Distance(Ai_body[i][j].x, Ai_body[i][j].y, player2.x, player2.y) < player2.r + Ai_body[i][j].r){body_num2 = 5;score2 = 100;kill2 = 0;//蛇player2.x = Wide / 2;player2.y = Hight / 2;player2.r = 10;//蛇身player_body2[0].x = player2.x - player2.r;player_body2[0].y = player2.y;player_body2[0].r = player2.r;for (int i = 1; i < body_num2; i++){player_body2[i].x = player_body2[i - 1].x - player_body2[i - 1].r;player_body2[i].y = player_body2[i - 1].y;player_body2[i].r = player_body2[i - 1].r;}}}//ai碰ai/*	for (int p = 0; p < Ai_num; p++){for (int j = 0; j < Ai_body_num[i]; j++){if (Distance(Ai_body[p][j].x, Ai_body[p][j].y, Ai[i].x, Ai[i].y) < Ai[i].r + Ai_body[p][j].r && i != p){//尾部变成食物Ai_body_food_num[i] = Ai_body_num[p];for (int z = 1; z < Ai_body_num[i]; z++){Ai_body_food[i][z].x = Ai_body[i][z].x;Ai_body_food[i][z].y = Ai_body[i][z].y;Ai_body_food[i][z].r = Ai_body[i][z].r;Ai_body_food[i][z].color = RGB(rand() % 256, rand() % 256, rand() % 256);}//重新生成aiAi[i].x = rand() % Wide_map;Ai[i].y = rand() % Hight_map;Ai[i].r = 10;//ai身体Ai_body_num[i] = 5;Ai_body[i][0].x = Ai[i].x - Ai[i].r;Ai_body[i][0].y = Ai[i].y;Ai_body[i][0].r = Ai[i].r;for (int z = 1; z < Ai_body_num[i]; z++){Ai_body[i][z].x = Ai_body[i][z - 1].x - Ai_body[i][z - 1].r;Ai_body[i][z].y = Ai_body[i][z - 1].y;Ai_body[i][z].r = Ai_body[i][z - 1].r;}}}}*/}
}void show()
{srand((unsigned)time(NULL));SetWorkingImage(&map);cleardevice();setbkcolor(RGB(236, 236, 244));//划线颜色setlinecolor(RGB(222, 222, 230));//划线for (int i = 0; i < Wide_map; i += 20){line(i, 0, i, Hight_map);}for (int i = 0; i < Hight_map; i += 20){line(0, i, Wide_map, i);}//食物for (int i = 0; i < food_num; i++){setfillcolor(food[i].color );solidcircle(food[i].x, food[i].y, food[i].r);}//玩家1——蛇头setfillcolor(RED);solidcircle(player.x, player.y, player.r);//玩家1——蛇身for (int i = 0; i < body_num; i++){setfillcolor(RGB(149, 236, 105));solidcircle(player_body[i].x, player_body[i].y, player_body[i].r);}//玩家2——蛇头setfillcolor(RGB(221, 221, 2));solidcircle(player2.x, player2.y, player2.r);//玩家2——蛇身for (int i = 0; i < body_num2; i++){setfillcolor(RGB(149, 236, 105));solidcircle(player_body2[i].x, player_body2[i].y, player_body2[i].r);}//ai蛇头for (int i = 0; i < Ai_num; i++){setfillcolor(RGB(229, 0, 0));solidcircle(Ai[i].x, Ai[i].y, Ai[i].r);}//ai蛇身for (int i = 0; i < Ai_num; i++){for (int j = 0; j < Ai_body_num[i]; j++){setfillcolor(RGB(229, 196, 0));solidcircle(Ai_body[i][j].x, Ai_body[i][j].y, Ai_body[i][j].r);}}//蛇尸体for (int i = 0; i < Ai_num; i++){for (int j = 0; j < Ai_body_food_num[i]; j++){setfillcolor(Ai_body_food[i][j].color );solidcircle(Ai_body_food[i][j].x, Ai_body_food[i][j].y, Ai_body_food[i][j].r);}}//玩家1视角int x = player.x - (Wide / 2) ;int y = player.y - (Hight / 2);//防止窗口越界if (x < -Wide / 4){x = -Wide / 4;}if (y < 0){y = 0;}if (x > Wide_map - Wide){x = Wide_map - Wide;}if (y > Hight_map - Hight){y = Hight_map - Hight;}//玩家2视角int x2 = player2.x - (Wide / 2);int y2 = player2.y - (Hight / 2);//防止窗口越界if (x2 < -Wide / 4){x2 = -Wide / 4;}if (y2 < 0){y2 = 0;}if (x2 > Wide_map - Wide){x2 = Wide_map - Wide;}if (y2 > Hight_map - Hight){y2 = Hight_map - Hight;}settextcolor(RGB(7, 19, 62));TCHAR buffer[50];TCHAR buffer1[50];swprintf_s(buffer, _T("%d"), score);swprintf_s(buffer1, _T("%d"), kill);setbkmode(TRANSPARENT);settextstyle(20, 0, _T("宋体"));outtextxy(player.x, player.y - player.r * 4 - 20, _T("长度:"));outtextxy(player.x + 50, player.y - player.r * 4 - 20, buffer);outtextxy(player.x, player.y - player.r * 4, _T("击杀:"));outtextxy(player.x + 50, player.y - player.r * 4, buffer1);TCHAR buffer2[50];TCHAR buffer3[50];swprintf_s(buffer2, _T("%d"), score2);swprintf_s(buffer3, _T("%d"), kill2);outtextxy(player2.x, player2.y - player2.r * 4 - 20, _T("长度:"));outtextxy(player2.x + 50, player2.y - player2.r * 4 - 20, buffer2);outtextxy(player2.x, player2.y - player2.r * 4, _T("击杀:"));outtextxy(player2.x + 50, player2.y - player2.r * 4, buffer3);SetWorkingImage();//把map输出到窗口上putimage(0, 0, Wide / 2, Hight, &map, x + Wide / 4, y);putimage(Wide/2, 0, Wide/2, Hight, &map, x2 + Wide / 4, y2);
}int main()
{init();initgraph(Wide, Hight);BeginBatchDraw();while (1){Sleep(10);show();Player_move1();eatfood();SnakeOut();Ai_move();FlushBatchDraw();}closegraph();}

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

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

相关文章

是否可以在HTTP中缓存POST方法

如果您想知道是否可以缓存post请求&#xff0c;并尝试研究该问题的答案&#xff0c;那么您很可能不会成功。当搜索“缓存post请求”时&#xff0c;第一个结果是这个StackOverflow问题。 答案是令人困惑的&#xff0c;包括缓存应该如何工作&#xff0c;缓存如何根据RFC工作&…

RDD算子介绍(二)

1. coalesce 用于缩减分区&#xff0c;减少分区个数&#xff0c;减少任务调度成本。 val rdd : RDD[Int] sc.makeRDD(List(1, 2, 3, 4), 4) val newRDD rdd.coalesce(2) newRDD.saveAsTextFile("output") 分区数可以减少&#xff0c;但是减少后的分区里的数据分布…

代码随想录算法训练营Day41 ||leetCode 0-1背包问题 || 416. 分割等和子集

0-1背包问题 dp[i][j]的含义&#xff1a;从下标为[0-i]的物品里任意取&#xff0c;放进容量为j的背包&#xff0c;价值总和最大是多少。 那么可以有两个方向推出来dp[i][j]&#xff0c; 不放物品i&#xff1a;由dp[i - 1][j]推出&#xff0c;即背包容量为j&#xff0c;里面不放…

02-app端文章查看,静态化freemarker,分布式文件系统minIO-黑马头条

app端文章查看&#xff0c;静态化freemarker,分布式文件系统minIO 1)文章列表加载 1.1)需求分析 文章布局展示 1.2)表结构分析 ap_article 文章基本信息表 ap_article_config 文章配置表 ap_article_content 文章内容表 三张表关系分析 1.3)导入文章数据库 1.3.1)导入数据…

详解@Configuration

简介 Configuration注解用于标识一个类作为Spring的配置类&#xff0c;从而允许使用纯Java代码的方式来定义Bean和Bean之间的依赖关系。 Configuration注解是Spring框架中非常核心的一个功能&#xff0c;它提供了一种替代XML配置文件的方法。通过该注解&#xff0c;开发人员可…

ROS2从入门到精通0-2:ROS2简介、对比ROS1与详细安装流程

目录 0 专栏介绍1 什么是机器人操作系统&#xff1f;2 ROS的发展历程3 ROS2与ROS1的区别4 ROS2安装4.1 基本安装4.2 测试ROS24.2.1 测试一&#xff1a;发布者与订阅者4.2.2 测试二&#xff1a;海龟仿真器 5 常见问题 0 专栏介绍 本专栏旨在通过对ROS2的系统学习&#xff0c;掌…

信息系统项目管理师--成本管理

项⽬成本管理重点关注完成项⽬活动所需资源的成本&#xff0c;但同时也考虑项⽬决策对项⽬产品、服务或成果的使⽤成本、维护成本和⽀持成本的影响。不同的⼲系⼈会在不同的时间&#xff0c;⽤不同的⽅法 测算项⽬成本。 就某些项⽬&#xff0c;特别是⼩项⽬⽽⾔&#xff0c;成…

FocusVisualStyle通常是键盘焦点样式

设置了Button的FocusVisualSytle但是死活没有效果&#xff0c;查了一下这个是键盘焦点样式&#xff0c;摁下Tab键了才能让Button有焦点 <ButtonWidth"100"Height"30"FocusVisualStyle"{DynamicResource MyFocusVisual}">按钮1 </Butto…

VSCode报错:/bin/sh: python: command not found

背景 以前都是直接用txt写python&#xff0c;然后直接命令行运行。 这次涉及的代码较多&#xff0c;决定用编译器。 写好的一段python点击运行报错&#xff01; 问题描述 因为我本地安装的是python3&#xff0c;但是vscode用的是另一个路径的python&#xff0c;所以找不到 解决…

_note_04_02

1&#xff1a;输出1-20之间的奇数。 package _09142023.homework_04;import java.util.Scanner;/**** 输出1-20之间的奇数。**/ public class _07_1 {public static void main(String[] args) {System.out.println("1到20之间的奇数&#xff1a;");for (int i 1; i…

视觉语言处理:用Transformer桥接视觉与语言

引言 人工智能研究的前沿领域见证了显著的交叉融合。将计算机视觉和自然语言处理的领域融合&#xff0c;问题随之而来&#xff1a;AI能否直接从其视觉表现&#xff0c;即从原始像素中辨识和理解语言&#xff1f;在这篇博客中&#xff0c;我试图探究AI从图像中直接理解自然语言的…

在 Android 上恢复已删除文件的 5 种简单方法

您可能会因为意外删除、未完成的 Android 更新、手机意外关机等原因而丢失 Android 上的重要数据。新技术的发展使许多手机功能或程序能够从内部恢复丢失的数据。 在 Android 上恢复已删除文件的 5 种简单方法 然而恢复成功率的不确定性也成为人们克服数据丢失困境的重要考虑因…

Android14音频进阶:AudioTrack与AudioFlinger创建数据通道(五十八)

简介: CSDN博客专家,专注Android/Linux系统,分享多mic语音方案、音视频、编解码等技术,与大家一起成长! 优质专栏:Audio工程师进阶系列【原创干货持续更新中……】🚀 优质专栏:多媒体系统工程师系列【原创干货持续更新中……】🚀 人生格言: 人生从来没有捷径,只…

子类和父类不在同一包中的继承性

不同包中的继承性 继承父类的protected 、public 成员变量 继承父类的 protected 、public 方法&#xff1b; 继承的成员或方法的 。 public class People { int age,leg 2,hand 2; public void showPeopleMess() { System.out.printf("%d岁&#xff0c;%d只脚,%d只手…

[Spring] IoC 控制反转和DI依赖注入和Spring中的实现以及常见面试题

目录 1. 什么是Spring 2.什么是IoC容器 3.通过实例来深入了解IoC容器的作用 3.1造一量可以定义车辆轮胎尺寸的车出现的问题 3.2解决方法 3.3IoC优势 4.DI介绍 5.Spring中的IoC和DI的实现 5.1.存对象 5.1.2 类注解 5.1.3 方法注解 5.2取对像 (依赖注入) 5.2.1.属性…

FPGA高端项目:FPGA基于GS2971的SDI视频接收+HLS多路视频融合叠加,提供1套工程源码和技术支持

目录 1、前言免责声明 2、相关方案推荐本博已有的 SDI 编解码方案本方案的SDI接收转HDMI输出应用本方案的SDI接收图像缩放应用本方案的SDI接收纯verilog图像缩放纯verilog多路视频拼接应用本方案的SDI接收HLS图像缩放Video Mixer多路视频拼接应用本方案的SDI接收OSD动态字符叠加…

护眼台灯怎么选比较好?明基、爱德华、书客护眼台灯硬核PK测评

现在不管是学生党学习阅读&#xff0c;还是办公族加班工作&#xff0c;都离不开一盏光源舒适的台灯&#xff0c;然而如今的台灯市场水实在太深的&#xff0c;各种网红、劣质产品混杂在其中&#xff0c;这类台灯往往采用劣质电源&#xff0c;其电源品质较差&#xff0c;导致输出…

开发指南002-前后端信息交互规范-返回值定义

public enum IOResultEnum {SUCCESS(88888888, "IOResult_88888888"),//操作成功ERROR(99999999, "IOResult_99999999"), //操作失败EXCEPTION(11111111, "IOResult_11111111"),//操作异常AUTHORIZATE_FAIL(9000,"IOResult_9000"),//没…

VUE3 显示Echarts百度地图

本次实现最终效果 技术基础以及环境要求 vue3 echarts 百度地图API 要求1&#xff1a; VUE3 环境搭建&#xff1a;https://blog.csdn.net/LQ_001/article/details/136293795 要求2&#xff1a; VUE3 echatrs 环境搭建:https://blog.csdn.net/LQ_001/article/details/1363…

Ps:画笔工具

画笔工具 Brush Tool是 Photoshop 中最常用的工具&#xff0c;可广泛地用于绘画与修饰工作之中。 快捷键&#xff1a;B ◆ ◆ ◆ 常用操作方法与技巧 1、熟练掌握画笔工具的操作对于使用其他工具也非常有益&#xff0c;因为 Photoshop 中许多与笔刷相关的工具有类似的选项和操…