基于 Evan_song1234 开发,MoonSpaceCat 增补的2D 我的世界,增加双缓冲实现 cmd控制台窗口或 Powershell 流畅运行

news2024/11/18 1:40:24

游戏玩法:

awsd移动

1234567890 各有功能

t 是命令行

q 是刷新

e 是重开

z 是挖

其他还没来及探索代码

代码来源

C++我的世界2D控制台版_c++minecraft-CSDN博客

其中解决颜色被双缓冲刷新没的方法 参考于自己的博客

用ReadConsoleOutput 解决双缓冲ReadConsoleOutputCharacterA 函数只读取字符,转义字符被过滤导致的颜色丢失问题-CSDN博客

 在 wincon.h 里看到有好几个版本的 ReadConsoleOutput() WriteConsoleOutput(),于是就测试,看看能不能继续保留颜色实现双缓冲刷新,发现W 可以实现,应该是字符集宽度不同,其他的读取不到这些特殊的方格字符。

      W结尾,是宽字符版本,适用于UTF-8,解决由于WriteConsoleOutput 默认窄字符,导致乱码或数据直接打印不出来。解决powshell 出不来地图的问题

WriteConsoleOutputA 也是窄字符,应该是兼容旧机器的代码。

//		WriteConsoleOutput(hout, buffer, coordBufSize, coordBufCoord, &rect);
//		WriteConsoleOutput(hOutBuf, buffer, coordBufSize, coordBufCoord, &rect);
//		WriteConsoleOutputA(hout, buffer, coordBufSize, coordBufCoord, &rect);
//		WriteConsoleOutputA(hOutBuf, buffer, coordBufSize, coordBufCoord, &rect);		
		ReadConsoleOutputW(hout, buffer, coordBufSize, coordBufCoord, &rect);								
		WriteConsoleOutputW(hOutBuf, buffer, coordBufSize, coordBufCoord, &rect);

另外是其他提示选择在双缓冲中会被挤到最下面,因为字符缓冲区没清空。

要么增加缓冲清空代码,要么另外跑,

鄙人不大会,于是想起来旧的默认缓冲区可以试试直接清屏,于是在提示处增加了这一对代码 

	SetConsoleActiveScreenBuffer(hout);								// 切换回原默认输出缓冲区,然后打印,因为新缓冲区清除数据麻烦,不如用旧的缓冲区,可以直接清屏
			
/*vnsdnvlsbvhlsdvsdkj() 等等函数被挤在这里*/
Sleep(2000);
	SetConsoleActiveScreenBuffer(hOutBuf);							// 再换回来,继续双缓冲防止屏闪

效果如图,但是发现cmd只有在编辑器里才能跑

 

 这里换poweshell 应该是由于换了缓冲区导致键盘输入也存在不同缓冲区里了

解决方案,参考自 控制台主机不能运行,切换终端实现RPG运行-CSDN博客

 

重新启动exe文件运行,成功

代码如下 

#include <iostream>
#include <conio.h>
#include <string>
#include <map>
#include <cmath>
#include <windows.h>
#include <time.h> 
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
int fallspeed;
int jumpspeed = -3;
int gravity = 1;
int y = 400, x = 500;
int restartposy, restartposx, face, health = 1000, lasthealth = 1000, breath = 100, hungry = 1000, dienum;
bool attack, defense, hurt, mode;
struct TNT
{
	int y;
	int x;
	int time;
//	bool issave;
	int issave;
};
struct BLOCK
{
	int color;
	string ch;
	string type;
};
struct MOB
{
	int fallspeed;
	int health;
	bool hurt;
	int y;
	int x;
	int attack;
	string shap;
	bool isenemy;
	int color;
	string name;
};
struct ARROW
{
	string shap;
	double y;
	double x;
	double fallspeed;
	double plusx;
};
TNT tnt[20];
string die;
ARROW arrow[100];
MOB mobs[50] = {
	{0,1000,0,0,0,100,"危",true,7,"危"},
	{0,10,0,0,0,10,"  ",true,7,"  "},
	{0,1000,0,0,0,100,"MM",false,7,"MM"},
	{0,100000,0,90,70,-100,"AC",true,7,"Accept"},
	{0,10000,0,90,70,500,"BO",true,7,"BOSS"},
	{0,100000,0,90,70,-1000,"AK",true,7,"AK"},
};
MOB mob[100] = {
	{0,1000,0,92,4,100,"WA",true,7,"Wrong Anwser"},
	{0,1000,0,92,4,100,"TL",true,7,"Time Limit Error"},
	{0,2000,0,92,4,300,"CE",true,7,"Compile Error"},
	{0,1000,0,45,9,100,"WA",true,7,"Wrong Anwser"},
	{0,100000,0,90,70,-100,"AC",true,7,"Accept"},
	{0,100000,0,90,70,-1000,"AK",true,7,"AK"},
	{0,10000,0,90,70,500,"UK",true,7,"Unknown Error"},
	{0,1000,0,92,3,0,"MM",false,7,"MM"},
	{0,1000,0,92,3,0,"MM",false,7,"MM"},
	{0,1000,0,90,15,0,"MM",false,7,"MM"},
	{0,1000,0,90,80,0,"MM",false,7,"MM"},
};
BLOCK block[32] = {
	{0,"  ","air"},//空气
	{6,"██","block"},//土块
	{8,"██","block"},//石头
	{2,"██","block"},//草方块
	{15,"██","block"},//雪块 
	{4,"██","block"},//岩浆块
	{14,"▓▓","fallblock"},//沙块 
	{8,"II","fallblock"},//铁砧
	{9,"██","water"},//水
	{9,"▇▇","water"},//水
	{9,"▆▆","water"},//水
	{9,"▅▅","water"},//水
	{9,"▄▄","water"},//水
	{9,"▃▃","water"},//水
	{9,"▂▂","water"},//水
	{9,"▁▁","water"},//水
	{12,"██","lava"},//岩浆
	{12,"▇▇","lava"},//岩浆
	{12,"▆▆","lava"},//岩浆
	{12,"▅▅","lava"},//岩浆
	{12,"▄▄","lava"},//岩浆
	{12,"▃▃","lava"},//岩浆
	{12,"▂▂","lava"},//岩浆
	{12,"▁▁","lava"},//岩浆  
	{12,"危","background"},//危
	{6,"██","background"},//木头
	{10,"▓▓","background"},//树叶 
	{15,"▓▓","background"},//带雪树叶
	{15,"▅▅","bomb"},//TNT爆炸 
	{12,"Ⅲ","TNT"},//TNT
	{7,"Ⅲ","TNT"},//TNT2
	{6,"∷","ladder"},//梯子
};
int board[1005][1005];
int setboard[1005][1005];
int bag[100];
int clear_buffer()
{
	while(kbhit())
	{
		if(getch() != EOF); 
		for(int i = 1; i <= 256; i++)
		{
			if(GetAsyncKeyState(i));
		}
	}
	return 0;
}
void color(int a)
{
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
	/*	1	深蓝色
	2	深绿色
	3	深青色 
	4	深红色
	5	深粉色
	i	黄色
	7	深白色
	8	灰色
	9	浅蓝色
	10	浅绿色 
	11	浅青色 
	12	浅红色 
	13	浅粉色 
	14	浅黄色 
	15	浅白色 
	背景
	1~15		黑色 
	16~31		深蓝色 
	32~47		深绿色
	48~63		深青色
	64~79		深红色
	'S'~95		深粉色
	96~111		深黄色
	112~127 	深白色
	128~143 	灰色
	144~159 	浅蓝色
	160~1'A' 	浅绿色
	176~191 	浅青色
	192~207 	浅红色
	208~223 	浅粉色
	224~239 	浅黄色
	240~255 	浅白色
	*/
}
int init()//听说有人要我增加地图生成的注释,所以我就写了。 
{
	for(int j = 0; j < 100; j++)
	{
		bag[j] = 0;//这个...初始化背包 
	}
	for(int i = 0; i < 1000; i++)
	{
		for(int j = 0; j < 1000; j++)
		{
			board[i][j] = 0;//初始化地图 (我们的y是倒着来的) 
		}
	} 
	double lasty = rand() % 101 + 400;//lasty代表上一个我们选择的点的高度。 
	for(int i = 5; i < 1000; i += 5)//i每次加5,每隔5个点连一条线 
	{
		double y = rand() % 21 - 10 + lasty;//y代表这个点我们选择的高度,为了不出现太陡峭的山,我们只允许这个高度在刚才的点的高低10格内。 
		y = min(450.0, y);//这是最小高度,防止整个地图都在水里。 
		double high = lasty;//这个high是用来统计当前高度的,用double可以更加精确。
		int dirt = rand() % 5 + 2;//dirt代表这一列上泥土高度。 
		for(int j = i - 5; j < i; j++)
		{
			high += (y - lasty) / 5;//high每次增加差距的1/5。 
			for(int k = 999; k >= (int)high; k--)
			{
				if(k == (int)high)//如果是最高点 
				{
					setboard[k][j] = 3;//就用草地 
					if(high <= 350)//如果high比较高 
					{
						setboard[k][j] = 4;//就用雪地 
					}
				}
				else if(k - dirt <= (int)high)//泥土 
				{
					setboard[k][j] = 1;
				}
				else 
				{
					setboard[k][j] = 2;//石头 
				}
			}
		}
		lasty = y;//赋值 
	}
	//再来一边,填满最后几格 
	int dirt = rand() % 5 + 2;
	double high = lasty;
	for(int j = 995; j < 999; j++)
	{
		for(int k = 999; k >= (int)high; k--)
		{
			if(k == (int)high)
			{
				setboard[k][j] = 3;
				if(high <= 350)
				{
					setboard[k][j] = 4;
				}
			}
			else if(k - dirt <= (int)high)
			{
				setboard[k][j] = 1;
			}
			else 
			{
				setboard[k][j] = 2;
			}
		}
	}
	//填满水,这里默认把海平面高度设为410。 
	for(int i = 0; i < 1000; i++)
	{
		for(int j = 600; j >= 410; j--)
		{
			if(setboard[j][i] == 0)
			{
				setboard[j][i] = 8;
			}
		}
	}
	//沙子 
	for(int i = 0; i < 1000; i++)
	{
		bool a = 0;
		for(int j = 999; j >= 0; j--)
		{
			if(a && setboard[j][i] != 0  && setboard[j][i] != 8)
			{
				setboard[j][i] = 6;
				continue;
			}
			if(setboard[j][i] == 8)
			{
				continue;
			}
			if(setboard[j][i + 3] == 8)
			{
				a = true;
				setboard[j][i] = 6;
			}
			if(setboard[j][i + 2] == 8)
			{
				a = true;
				setboard[j][i] = 6;
			}
			if(setboard[j][i + 1] == 8)
			{
				a = true;
				setboard[j][i] = 6;
			}
			if(setboard[j][i - 1] == 8)
			{
				a = true;
				setboard[j][i] = 6;
			}
			if(setboard[j][i - 2] == 8)
			{
				a = true;
				setboard[j][i] = 6;
			}
			if(setboard[j][i - 3] == 8)
			{
				a = true;
				setboard[j][i] = 6;
			}
			if(setboard[j - 2][i] == 8)
			{
				a = true;
				setboard[j][i] = 6;
			}
			if(setboard[j - 1][i] == 8)
			{
				a = true;
				setboard[j][i] = 6;
			}
			if(setboard[j - 3][i] == 8)
			{
				a = true;
				setboard[j][i] = 6;
			}
			if(setboard[j - 4][i] == 8)
			{
				a = true;
				setboard[j][i] = 6;
			}
		}
	}
	//树 
	for(int i = 0; i < 1000; i++)
	{
		for(int j = 0; j < 1000; j++)
		{
			if(setboard[j][i] == 0 && block[setboard[j + 1][i]].type == "block")
			{
				if(rand() % 10 == 1)
				{
					setboard[j][i] = 25;
					setboard[j - 1][i] = 25;
					setboard[j - 2][i] = 25;
					setboard[j - 3][i] = 25;
					setboard[j - 3][i + 1] = 26;
					setboard[j - 3][i - 1] = 26;
					setboard[j - 4][i + 2] = 26; 
					setboard[j - 4][i + 1] = 26;
					setboard[j - 4][i] = 26;
					setboard[j - 4][i - 1] = 26;
					setboard[j - 4][i - 2] = 26;
					setboard[j - 5][i + 2] = 26;
					setboard[j - 5][i + 1] = 26;
					setboard[j - 5][i] = 26;
					setboard[j - 5][i - 1] = 26;
					setboard[j - 5][i - 2] = 26;
					setboard[j - 6][i + 1] = 26;
					setboard[j - 6][i] = 26;
					setboard[j - 6][i - 1] = 26;
					if(j <= 350)
					{
						setboard[j - 3][i + 1] = 27;
						setboard[j - 3][i - 1] = 27;
						setboard[j - 4][i + 2] = 27; 
						setboard[j - 4][i + 1] = 27;
						setboard[j - 4][i] = 27;
						setboard[j - 4][i - 1] = 27;
						setboard[j - 4][i - 2] = 27;
						setboard[j - 5][i + 2] = 27;
						setboard[j - 5][i + 1] = 27;
						setboard[j - 5][i] = 27;
						setboard[j - 5][i - 1] = 27;
						setboard[j - 5][i - 2] = 27;
						setboard[j - 6][i + 1] = 27;
						setboard[j - 6][i] = 27;
						setboard[j - 6][i - 1] = 27;
					}
				}
			}
		}
	} 
	//地洞 
	for(int j = 999; j >= 700; j--)
	{
		if(rand() % 20 == 1)
		{
			setboard[j - 3][2] = 0;
			setboard[j - 2][2] = 0; setboard[j - 2][3] = 0;
			setboard[j - 1][2] = 0; setboard[j - 1][3] = 0; setboard[j - 1][4] = 0;
			setboard[j][2] = 0; setboard[j][3] = 0; setboard[j][4] = 0; setboard[j][5] = 0;
			setboard[j + 1][2] = 0; setboard[j + 1][3] = 0; setboard[j + 1][4] = 0;
			setboard[j + 2][2] = 0; setboard[j + 2][3] = 0;
			setboard[j + 3][2] = 0;
		}
	}
	for(int i = 3; i < 997; i++)
	{
		for(int j = 996; j >= 500; j--)
		{
			if(block[setboard[j + 3][i]].type == "block" && block[setboard[j - 3][i]].type == "block" && setboard[j][i] == 0 && setboard[j + 1][i] == 0 && setboard[j + 2][i] == 0 && setboard[j - 1][i] == 0  && setboard[j - 2][i] == 0)
			{
				j += rand() % 5 - 2;
				j = max(3, j);
				j = min(996, j);
				if(rand() % 500 <= 499)
				{
					setboard[j - 3][i] = 0;
					setboard[j - 2][i - 1] = 0; setboard[j - 2][i] = 0; setboard[j - 2][i + 1] = 0;
					setboard[j - 1][i - 2] = 0; setboard[j - 1][i - 1] = 0; setboard[j - 1][i] = 0; setboard[j - 1][i + 1] = 0; setboard[j - 1][i + 2] = 0;
					setboard[j][i - 3] = 0; setboard[j][i - 2] = 0; setboard[j][i - 1] = 0; setboard[j][i] = 0; setboard[j][i + 1] = 0; setboard[j][i + 2] = 0; setboard[j][i + 3] = 0;
					setboard[j + 1][i - 2] = 0; setboard[j + 1][i - 1] = 0; setboard[j + 1][i] = 0; setboard[j + 1][i + 1] = 0; setboard[j + 1][i + 2] = 0;
					setboard[j + 2][i - 1] = 0; setboard[j + 2][i] = 0; setboard[j + 2][i + 1] = 0;
					setboard[j + 3][i] = 0;
					if(rand() % 20 == 1)
					{
						for(int k = 0; k < 100; k++)
						{
							if(mob[k].shap == "")
							{
								mob[k] = {0,1000,0,0,0,100,"SS",true,7,"僵尸"};
								mob[k].x = i;
								mob[k].y = j;
								break;
							}
						}
					}
				}
			}
			else if(block[setboard[j + 3][i]].type == "block" && block[setboard[j + 2][i]].type == "block" && block[setboard[j + 1][i]].type == "block" && block[setboard[j][i]].type == "block" && block[setboard[j - 1][i]].type == "block" && block[setboard[j - 2][i]].type == "block" && block[setboard[j - 3][i]].type == "block")
			{
				if(rand() % 500 == 1)
				{
					setboard[j - 3][i] = 0;
					setboard[j - 2][i - 1] = 0; setboard[j - 2][i] = 0; setboard[j - 2][i + 1] = 0;
					setboard[j - 1][i - 2] = 0; setboard[j - 1][i - 1] = 0; setboard[j - 1][i] = 0; setboard[j - 1][i + 1] = 0; setboard[j - 1][i + 2] = 0;
					setboard[j][i - 3] = 0; setboard[j][i - 2] = 0; setboard[j][i - 1] = 0; setboard[j][i] = 0; setboard[j][i + 1] = 0; setboard[j][i + 2] = 0; setboard[j][i + 3] = 0;
					setboard[j + 1][i - 2] = 0; setboard[j + 1][i - 1] = 0; setboard[j + 1][i] = 0; setboard[j + 1][i + 1] = 0; setboard[j + 1][i + 2] = 0;
					setboard[j + 2][i - 1] = 0; setboard[j + 2][i] = 0; setboard[j + 2][i + 1] = 0;
					setboard[j + 3][i] = 0;
				}
			}
		}
	}
	//出生点 
	bool a = false;
	for(int i = 400; i < 1000; i++)
	{
		for(int j = 0; j < 1000; j++)
		{
			if(setboard[j][i] == 0 && block[setboard[j + 1][i]].type == "block" && (setboard[j + 1][i] == 3 || setboard[j + 1][i] == 4))
			{
				restartposy = j;
				restartposx = i;
				y = j;
				x = i;
				a = true;
				break;
			}
		}
		if(a)
		{
			break;
		}
	}
	return 0;
}
int Arrowmove()
{
	for(int i = 0; i < 100; i++)
	{
		if(arrow[i].shap == "")
		{
			continue;
		}
		arrow[i].x += (int)arrow[i].plusx;
		arrow[i].plusx -= 0.1;
		for(int j = (int)arrow[j].y + 1; j <= (int)arrow[j].y + (int)arrow[j].fallspeed; j++)
		{
			if(block[board[j][(int)arrow[j].x]].type == "block" || block[board[j][(int)arrow[j].x]].type == "fallblock")
			{
				arrow[i].fallspeed = 0;
				return 0;
			}
		}
		arrow[i].y += arrow[i].fallspeed;
		arrow[i].fallspeed += 0.1;
		if(arrow[i].y > 999)
		{
			arrow[i].shap = "";
		}
		if(block[board[(int)arrow[i].y + 1][(int)arrow[i].x]].type == "block" || block[board[(int)arrow[i].y + 1][(int)arrow[i].x]].type == "fallblock")
		{
			arrow[i].shap = "";
		}
	}
	return 0;
}
int mobmove()
{
	for(int j = 0; j < 100; j++)
	{
		if(mob[j].shap == "")
		{
			continue;
		}
		mob[j].hurt = false;
		mob[j].color = 7;
		if(mob[j].health <= 0 || mob[j].y > 999)
		{
			mob[j].shap = "";
			mob[j].color = 7;
			continue;
		}
		if(block[board[mob[j].y][mob[j].x]].type == "lava")
		{
			mob[j].health -= 200;
			mob[j].hurt = true;
		}
		else if((board[mob[j].y + 1][mob[j].x] == 5) || ((mob[j].y == y || mob[j].y == y - 1) && (mob[j].x == x + 1 || mob[j].x == x || mob[j].x == x - 1) && KEY_DOWN(' ')))
		{
			mob[j].health -= 100;
			mob[j].hurt = true;
		}
		if(mob[j].y == y && mob[j].x == x && mob[j].isenemy)
		{
			health -= mob[j].attack;
			hurt = true;
			die = "被 " + mob[j].name + " 杀死了";
		}
		for(int i = mob[j].y - 1; i >= mob[j].y + mob[j].fallspeed; i--)
		{
			if(block[board[i - 1][mob[j].x]].type == "block")
			{
				mob[j].fallspeed = 0 - mob[j].y + i + 1;
				return 0;
			}
		}
		for(int i = mob[j].y + 1; i <= mob[j].y + mob[j].fallspeed; i++)
		{
			if(block[board[i][mob[j].x]].type == "block" || block[board[i][mob[j].x]].type == "fallblock")
			{
				if(mob[j].fallspeed >= 5 && block[board[i - 1][mob[j].x]].type == "water")
				{
					mob[j].health -= 50 * (mob[j].fallspeed - 4);
					mob[j].hurt = true;
				}
				mob[j].fallspeed = 0;
				return 0;
			}
		}
		mob[j].y += mob[j].fallspeed;
		mob[j].fallspeed += gravity;
		if(mob[j].isenemy)
		{
			if(mob[j].y > y && (block[board[mob[j].y + 1][mob[j].x]].type == "block" || block[board[mob[j].y + 1][mob[j].x]].type == "fallblock"))
			{
				if(mob[j].y > y + 50)
				{
					mob[j].fallspeed = -7;
				}
				mob[j].fallspeed = -3;
			}
			if(mob[j].x < x)
			{
				if(block[board[mob[j].y][mob[j].x + 1]].type != "block" || block[board[mob[j].y][mob[j].x + 1]].type != "fallblock")
				{
					mob[j].x++;
				}
				else if(block[board[mob[j].y + 1][mob[j].x]].type == "block" || block[board[mob[j].y + 1][mob[j].x]].type != "fallblock")
				{
					mob[j].fallspeed = -3;
				}
			}
			else if(mob[j].x > x)
			{
				if(block[board[mob[j].y][mob[j].x - 1]].type != "block" || block[board[mob[j].y][mob[j].x - 1]].type != "fallblock")
				{
					mob[j].x--;
				}
				else if(block[board[mob[j].y + 1][mob[j].x]].type == "block" || block[board[mob[j].y + 1][mob[j].x]].type != "fallblock")
				{
					mob[j].fallspeed = -3;
				}
			}
		}
		else
		{
			if(rand() % 3 == 0)
			{
				if(block[board[mob[j].y][mob[j].x + 1]].type != "block" || block[board[mob[j].y][mob[j].x + 1]].type != "fallblock")
				{
					mob[j].x++;
				}
				else if(block[board[mob[j].y + 1][mob[j].x]].type == "block" || block[board[mob[j].y + 1][mob[j].x]].type != "fallblock")
				{
					mob[j].fallspeed = -3;
				}
			}
			else if(rand() % 3 == 1)
			{
				if(block[board[mob[j].y][mob[j].x - 1]].type != "block" || block[board[mob[j].y][mob[j].x - 1]].type != "fallblock")
				{
					mob[j].x--;
				}
				else if(block[board[mob[j].y + 1][mob[j].x]].type == "block" || block[board[mob[j].y + 1][mob[j].x]].type != "fallblock")
				{
					mob[j].fallspeed = -3;
				}
			}
		}
		if(mob[j].hurt)
		{
			mob[j].color = 12;
		}
	}
	return 0;
}
int print()
{
	if(!mode)
	{
		color(8);
		cout << "生命值:";
		color(12);
		cout << health << endl; 
		for(int i = 0; i < health; i += 100)
		{
			cout << "◆";
		}
		color(7);
		for(int i = health; i < lasthealth; i += 100)
		{
			cout << "◇";
		}
		cout << endl;
		color(8);
		cout << "氧气:";
		color(11);
		cout << breath << endl;
		for(int i = 0; i < breath; i += 10)
		{
			cout << "●";
		}
		for(int i = breath; i < 91; i += 10)
		{
			cout << "○";
		}
		cout << endl;
		color(8);
		cout << "饱食度:";
		color(14);
		cout << hungry << endl;
		for(int i = 0; i < hungry; i += 100)
		{
			cout << "§";
		}
		cout <<endl <<"按c以加满饱食度" <<endl;
	} 
	color(8);
	cout << "死亡次数:";
	color(4);
	cout << dienum << endl;
	for(int i = y - 6; i <= y + 6; i++)
	{
		for(int j = x - 6; j <= x + 6; j++)
		{
			bool ismob = false;
			for(int s = 0; s < 100; s++)
			{
				if(mob[s].shap == "")
				{
					continue;
				}
				else if(mob[s].x == j && mob[s].y == i)
				{
					color(mob[s].color);
					cout << mob[s].shap;
					ismob = true;
					break;
				}
			}
			if(ismob)
			{
				continue;
			}
			for(int s = 0; s < 100; s++)
			{
				if(arrow[s].shap == "")
				{
					continue;
				}
				else if((int)arrow[s].x == j && (int)arrow[s].y == i)
				{
					color(7);
					cout << arrow[s].shap;
					ismob = true;
					break;
				}
			}
			if(ismob)
			{
				continue;
			}
			else if(i == y && j == x)
			{
				if (KEY_DOWN('S'))
				{
					color(14);
					if(hurt)
					{
						color(12);
					}
					cout << "()";
				}
				else
				{
					color(9);
					if(hurt)
					{
						color(12);
					}
					cout << "∏";
				}
			}
			else if(i == y - 1 && j == x)
			{
				if (!KEY_DOWN('S'))
				{
					color(14);
					if(hurt)
					{
						color(12);
					}
					cout << "()";
				}
				else
				{
					color(block[board[i][j]].color);
					cout << block[board[i][j]].ch;
				}
			}
			else
			{
				if(i < 0 || i >= 1000 || j < 0 || j >= 1000)
				{
					cout << "  ";
					continue;
				}
				color(block[board[i][j]].color);
				cout << block[board[i][j]].ch;
			}
		}
		cout << endl;
	}
	color(7);
	cout << "Y坐标:";
	color(6);
	cout << 1000 - y << endl;
	color(7);
	cout << "X坐标:";
	color(6);
	cout << x << endl;
	
	return 0;
}
int move()
{
	if(board[y][x] == 31)
	{
		y += fallspeed;
		return 0;
	}
	if(block[board[y][x]].type == "water")
	{
		if(fallspeed > 1)
		{
			fallspeed = 1;
		}
	}
	else
	{
		for(int i = y - 1; i >= y + fallspeed; i--)
		{
			if(block[board[i - 1][x]].type == "block" || block[board[i - 1][x]].type == "fallblock")
			{
				fallspeed = 0 - y + i + 1;
				return 0;
			}
		}
	}
	for(int i = y + 1; i <= y + fallspeed; i++)
	{
		if(block[board[i][x]].type == "block" || block[board[i][x]].type == "fallblock")
		{
			if(fallspeed >= 5 && block[board[i - 1][x]].type != "water")
			{
				health -= 50 * (fallspeed - 4);
				if(fallspeed >= 7)
				{
					die = "落地过猛";
				}
				else
				{
					die = "从高处摔了下来";
				}
				hurt = true;
			}
			fallspeed = 0;
			return 0;
		}
	}
	y += fallspeed;
	fallspeed += gravity;
	return 0;
}
int bomb()
{
	for(int i = 0; i < 20; i++)
	{
		if(tnt[i].time == 0)
		{
			int atk = 0;
			if(abs(x - tnt[i].x) + abs(y - tnt[i].y) == 4)
			{
				atk = 50;
				fallspeed -= 1;
				x += x - tnt[i].x;
			}
			if(abs(x - tnt[i].x) + abs(y - tnt[i].y) == 3)
			{
				atk = 100;
				fallspeed -= 2;
				x += x - tnt[i].x;
			}
			if(abs(x - tnt[i].x) + abs(y - tnt[i].y) == 2)
			{
				atk = 300;
				fallspeed -= 4;
				x += 2 * (x - tnt[i].x);
			}
			if(abs(x - tnt[i].x) + abs(y - tnt[i].y) == 1)
			{
				atk = 500;
				fallspeed -= 7;
				x += 5 * (x - tnt[i].x);
			}
			if(abs(x - tnt[i].x) + abs(y - tnt[i].y) == 0)
			{
				atk = 800;
				fallspeed -= 10;
			}
			tnt[i].time--;
			if(!tnt[i].issave)
			{
				health -= atk;
			}
			die = "被TNT炸死了";
			if(atk > 0 && !tnt[i].issave)
			{
				hurt = true;
			}
			if(!tnt[i].issave)
			{
				for(int yy = tnt[i].y - 3; yy <= tnt[i].y + 3; yy++)
				{
					for(int xx = tnt[i].x - 3; xx <= tnt[i].x + 3; xx++)
					{
						if((int)(sqrt(abs(yy - tnt[i].y) * abs(yy - tnt[i].y) + abs(xx - tnt[i].x) * abs(xx - tnt[i].x)) + 0.9999) == 3)
						{
							setboard[yy][xx] = 28;
						}
						if((int)(sqrt(abs(yy - tnt[i].y) * abs(yy - tnt[i].y) + abs(xx - tnt[i].x) * abs(xx - tnt[i].x)) + 0.9999) < 3)
						{
							setboard[yy][xx] = 0;
						}
					}
				}
			}
		}
		else if(tnt[i].time == -1)
		{
			setboard[tnt[i].y][tnt[i].x] = 0;
			if(!tnt[i].issave)
			{
				for(int yy = tnt[i].y - 3; yy <= tnt[i].y + 3; yy++)
				{
					for(int xx = tnt[i].x - 3; xx <= tnt[i].x + 3; xx++)
					{
						if((int)(sqrt(abs(yy - tnt[i].y) * abs(yy - tnt[i].y) + abs(xx - tnt[i].x) * abs(xx - tnt[i].x)) + 0.9999) <= 3)
						{
							setboard[yy][xx] = 0;
						}
					}
				}
			}
			tnt[i].time--;
		}
		else if(tnt[i].time > 0)
		{
			tnt[i].time--;
			if(tnt[i].time % 2 == 0)
			{
				setboard[tnt[i].y][tnt[i].x] = 29;
			}
			else
			{
				setboard[tnt[i].y][tnt[i].x] = 30;
			}
		}
	}
	return 0;
}
int check()
{
	for(int i = 0; i < 1000; i++)
	{
		for(int j = 0; j < 1000; j++)
		{
			if(block[board[i][j]].type == "water" && board[i][j] != 15)
			{
				if(board[i + 1][j] == 0)
				{
					setboard[i + 1][j] = board[i][j];
					setboard[i + 1][j] = 8;
				}
				else if(block[board[i + 1][j]].type == "lava")
				{
					setboard[i + 1][j] = 2;
				}
				else if(block[board[i + 1][j]].type == "block" || block[board[i + 1][j]].type == "fallblock")
				{
					if(board[i][j + 1] == 0)
					{
						setboard[i][j + 1] = board[i][j] + 1;
					}
					else if(block[board[i][j + 1]].type == "lava")
					{
						setboard[i][j + 1] = 2;
					}
					if(board[i][j - 1] == 0)
					{
						setboard[i][j - 1] = board[i][j] + 1;
					}
					else if(block[board[i][j - 1]].type == "lava")
					{
						setboard[i][j - 1] = 2;
					}
				}
			}
			if(block[board[i][j]].type == "lava" && board[i][j] != 23)
			{
				if(board[i + 1][j] == 0)
				{
					setboard[i + 1][j] = board[i][j];
					setboard[i + 1][j] = 16;
				}
				else if(block[board[i + 1][j]].type == "water")
				{
					setboard[i + 1][j] = 2;
				}
				else if(block[board[i + 1][j]].type == "block" || block[board[i + 1][j]].type == "fallblock")
				{
					if(board[i][j + 1] == 0)
					{
						setboard[i][j + 1] = board[i][j] + 1;
					}
					else if(block[board[i][j + 1]].type == "water")
					{
						setboard[i][j + 1] = 2;
					}
					if(board[i][j - 1] == 0)
					{
						setboard[i][j - 1] = board[i][j] + 1;
					}
					else if(block[board[i][j - 1]].type == "water")
					{
						setboard[i][j - 1] = 2;
					}
				}
			}
			if(block[board[i][j]].type == "fallblock")
			{
				if(board[i + 2][j] == 0 && board[i + 1][j] == 0 && i + 2 < 100)
				{
					setboard[i][j] = 0;
					setboard[i + 2][j] = board[i][j];
					if(board[i][j] == 7 && j == x && i + 2 == y)
					{
						health -= 600;
						hurt = true;
						die = "被压扁了";
					}
				}
				else if(board[i + 1][j] == 0 && i + 1 < 100)
				{
					setboard[i][j] = 0;
					setboard[i + 1][j] = board[i][j];
					if(board[i][j] == 7 && j == x && i + 1 == y)
					{
						health -= 600;
						hurt = true;
						die = "被压扁了";
					}
					else if(board[i][j] == 7 && j == x && i + 2 == y)
					{
						health -= 600;
						hurt = true;
						die = "被压扁了";
					}
				}
			}
		}
	}
	for(int i = 0; i < 1000; i++)
	{
		for(int j = 0; j < 1000; j++)
		{
			board[i][j] = setboard[i][j];
		}
	}
}
int main()
{
	//创建新的缓冲区
	HANDLE hOutBuf = CreateConsoleScreenBuffer(
		GENERIC_READ | GENERIC_WRITE,
		FILE_SHARE_READ | FILE_SHARE_WRITE,
		NULL,
		CONSOLE_TEXTMODE_BUFFER,
		NULL
		);
	
	//设置新的缓冲区为活动显示缓冲
	SetConsoleActiveScreenBuffer(hOutBuf);
	
	const int X = 0;								// rect.left 代表采样区左上角,X就是左上角起点 由改成X=10,会丢失左半部分测试得到
	const int Y = 4;								// rect.top 代表采样区左上角,Y就是左上角起点, 由改成Y=10,会丢失上半部分测试得到			改成Y=4,顶上的重复地图不采样,Y=-4会有四行翻到上面
	const int MROW = 23+12;		// 多12行为了命令行弹出不被剪切掉				// coordBufSize.Y 代表采样高度				由30改成20丢失下部坐标得到该结论				改成MROW=23,底下的坐标不显示
	const int MCOL = 50;							// coordBufSize.X 代表采样宽度
	HANDLE hout = GetStdHandle(STD_OUTPUT_HANDLE);	// 获取默认的输出缓冲区,用于提取字符信息
	SMALL_RECT rect;
	CHAR_INFO buffer[MROW * MCOL]; //lpBuffer		// 采样的数据存储,采样数据包括颜色,大小,背景色,字符
	COORD coordBufSize; //dwBufferSize
	COORD coordBufCoord; // dwBufferCoord
	
	coordBufSize.Y = MROW;
	coordBufSize.X = MCOL;
	coordBufCoord.X = 0; //???????					// 未知,但是从12改到30,左边平移到右边,应该是新的打印起点
	coordBufCoord.Y = 0; //???????					// 未知,但是从0到10,最下面数据丢失了,应该是裁剪起点
	
	rect.Top = Y;
	rect.Left = X;
	rect.Bottom = MROW + Y;
	rect.Right = MCOL + X;
	
	// 以上1001 - 1032 部分是缓冲区所需的全部变量
	
	srand((int)time(0));
	for(int i = 0; i < 20; i++)
	{
		tnt[i].time = -2;
	}
	init();
	while(1)
	{
//		system ("cls");												// 加装了双缓冲绘图代码,需要注释掉清屏才能实现不闪屏——bilibili 民用级脑的研发记录 2024-5-1  基于 MoonSpaceCat 增加的 Evan_song开发的我的世界2D版本  https://blog.csdn.net/weixin_45122104/article/details/123054939
		if(!mode)
		{
			move();
		} 
		if(KEY_DOWN('F'))
		{
			setboard[y + 1][x] = 2;
		}
		check();
		bomb();
		Arrowmove();
		mobmove();
		if(mode)
		{
			hurt = false;
		} 
		print();
		
//		WriteConsoleOutput(hout, buffer, coordBufSize, coordBufCoord, &rect);
//		WriteConsoleOutput(hOutBuf, buffer, coordBufSize, coordBufCoord, &rect);
//		WriteConsoleOutputA(hout, buffer, coordBufSize, coordBufCoord, &rect);
//		WriteConsoleOutputA(hOutBuf, buffer, coordBufSize, coordBufCoord, &rect);		
		ReadConsoleOutputW(hout, buffer, coordBufSize, coordBufCoord, &rect);								// W结尾,是宽字符版本,适用于UTF-8,解决由于WriteConsoleOutput 默认窄字符,导致乱码或数据直接打印不出来。解决powshell 出不来地图的问题
		WriteConsoleOutputW(hOutBuf, buffer, coordBufSize, coordBufCoord, &rect);
		
		Sleep(30);
		hungry--;
		hungry = max(hungry, 0);
		if(hungry == 0)
		{
			die = "饿死了";
			hurt = true;
			health -= 10;
		}
		if(mode)
		{
			health = 1000;
		}
		if(health <= 0)
		{
			Sleep(500); 
			
			SetConsoleActiveScreenBuffer(hout);								// 切换回原默认输出缓冲区,然后打印,因为新缓冲区清除数据麻烦,不如用旧的缓冲区,可以直接清屏
			
			system("cls");
			color(12);
			cout << "           You Died !           " << endl;
			color(7);
			cout << "          Alex " << die << endl;
			dienum++;
			
						
			Sleep(2000);
			
			SetConsoleActiveScreenBuffer(hOutBuf);							// 再换回来,继续双缓冲防止屏闪
			
			x = restartposx;
			y = restartposy;
			health = 1000;
			hungry = 1000;
			breath = 100;
			fallspeed = 0;
		}
		health += (hungry + 201) / 300; 
		if(health > 1000)
		{
			health = 1000; 
		} 
		if(attack)
		{
			attack = 0;
		}
		if(defense)
		{
			defense = 0;
		}
		if(hurt)
		{
			hurt = false;
			lasthealth = health;
		}
		if(block[board[y][x]].type == "water")
		{
			fallspeed = 1;
			if(KEY_DOWN('W'))
			{
				fallspeed = -1;
			}
		}
		if(block[board[y - 1][x]].type == "water")
		{
			die = "被水淹死了"; 
			breath--; 
		}
		else
		{
			breath++; 
			if(breath > 100)
			{
				breath = 100; 
			} 
		} 
		if(board[y][x] == 31)
		{
			fallspeed = 0;
			if(KEY_DOWN('W'))
			{
				fallspeed = -1;
			}
			if(KEY_DOWN('S'))
			{
				fallspeed = 1;
			}
		}
		if(block[board[y][x]].type == "lava")
		{
			fallspeed = 1;
			if(KEY_DOWN('W'))
			{
				fallspeed = -1;
			}
			die = "试图在岩浆里游泳"; 
			hurt = true;
			health -= 100; 
		}
		if (KEY_DOWN('W') && !KEY_DOWN('S'))
		{
			if(mode)
			{
				y--;
			}
			else
			{
				if(block[board[y][x]].type != "water" && board[y][x] != 31)
				{
					if(block[board[y + 1][x]].type == "block" || block[board[y + 1][x]].type == "fallblock")
					{
						fallspeed = jumpspeed;
					}
				}
			}
		}
		if (KEY_DOWN('A'))
		{
			if((block[board[y][x - 1]].type != "block" && block[board[y][x - 1]].type != "fallblock") || mode)
			{
				if(KEY_DOWN('S') || (block[board[y - 1][x - 1]].type != "block" && block[board[y - 1][x - 1]].type != "fallblock") || mode)
				{
					x -= 1;
				}
			}
			face = -1;
		}
		if (KEY_DOWN('D'))
		{
			if((block[board[y][x + 1]].type != "block" && block[board[y][x + 1]].type != "fallblock") || mode)
			{
				if(KEY_DOWN('S') || (block[board[y - 1][x + 1]].type != "block"  && block[board[y - 1][x + 1]].type != "fallblock") || mode)
				{
					x += 1;
				}
			}
			face = 1;
		}
		if(KEY_DOWN('S'))
		{
			if(mode)
			{
				y++;
			}
			else
			{
				fallspeed += 1;
			}
		}
		if(KEY_DOWN(' '))
		{
			attack = true;
		}
		if(KEY_DOWN('E'))
		{
			
			SetConsoleActiveScreenBuffer(hout);								// 切换回原默认输出缓冲区,然后打印,因为新缓冲区清除数据麻烦,不如用旧的缓冲区,可以直接清屏
			
			system("cls");
			color(7);
			cout << "┌──┬──┬──┬──┬──┬──┬──┬──┬──┬──┐" << endl;
			for(int i = 0; i < 9; i++)
			{
				color(7);
				cout << "│";
				for(int j = 0; j < 10; j++)
				{
					color(block[bag[i * 10 + j]].color);
					cout << block[bag[i * 10 + j]].ch;
					color(7);
					cout << "│";
				}
				cout << endl;
				color(7);
				cout << "├──┼──┼──┼──┼──┼──┼──┼──┼──┼──┤" << endl;
			}
			color(7);
			cout << "│";
			for(int j = 0; j < 10; j++)
			{
				color(block[bag[90 + j]].color);
				cout << block[bag[90 + j]].ch;
				color(7);
				cout << "│";
			}
			color(7);
			cout << endl;
			cout << "└──┴──┴──┴──┴──┴──┴──┴──┴──┴──┘" << endl;
			
			Sleep(3000);
			
			SetConsoleActiveScreenBuffer(hOutBuf);							// 再换回来,继续双缓冲防止屏闪
			
		}
		if(KEY_DOWN('C'))
		{
			hungry += 100;
			hungry = min(hungry, 1000);
		}
		if(KEY_DOWN('Q'))
		{
			for(int i = 0; i < 20; i++)
			{
				if(tnt[i].time == -2)
				{
					tnt[i] = {y, x, 10, 0};
					break;
				}
			}
		}
		if(KEY_DOWN('i'))
		{
			for(int i = 0; i < 20; i++)
			{
				if(tnt[i].time == -2)
				{
					tnt[i] = {y, x, 10, 1};
					break;
				}
			}
		}
		if(KEY_DOWN('8'))
		{
			for(int i = 0; i < 20; i++)
			{
				if(tnt[i].time == -2)
				{
					tnt[i] = {y, x, 10, 2};
					break;
				}
			}
		}
		if(KEY_DOWN('9'))
		{
			for(int i = 0; i < 20; i++)
			{
				if(tnt[i].time == -2)
				{
					tnt[i] = {y, x, 10, 3};
					break;
				}
			}
		}
		if(KEY_DOWN('0'))
		{
			for(int i = 0; i < 20; i++)
			{
				if(tnt[i].time == -2)
				{
					tnt[i] = {y, x, 10, 4};
					break;
				}
			}
		}
		if(KEY_DOWN('I'))
		{
			for(int i = 0; i < 20; i++)
			{
				if(tnt[i].time == -2)
				{
					tnt[i] = {y, x, 10, 5};
					break;
				}
			}
		}
		if(KEY_DOWN('Z'))
		{
			setboard[y + 1][x] = 0;
		}
		if(KEY_DOWN('X'))
		{
			setboard[y][x] = 24;
		}
		if(KEY_DOWN('3'))
		{
			setboard[y + 1][x] = 6;
		}
		if(KEY_DOWN('4'))
		{
			setboard[y + 1][x] = 7;
		}
		if(KEY_DOWN('1'))
		{
			setboard[y + 1][x] = 8;
		}
		if(KEY_DOWN('2'))
		{
			setboard[y + 1][x] = 16;
		}
		if(KEY_DOWN('5'))
		{
			if(face == 1)
			{
				for(int i = 0; i < 100; i++)
				{
					if(arrow[i].shap == "")
					{
						arrow[i] = {"→",y,x,-0.7,2};
						break; 
					}
				}
			}
			else
			{
				for(int i = 0; i < 100; i++)
				{
					if(arrow[i].shap == "")
					{
						arrow[i] = {"←",y,x,-0.7,-2};
						break;
					}
				}
			}
		}
		if(KEY_DOWN('T'))
		{
			clear_buffer();
			
			SetConsoleActiveScreenBuffer(hout);								// 切换回原默认输出缓冲区,然后打印,因为新缓冲区清除数据麻烦,不如用旧的缓冲区,可以直接清屏
			
			system("cls");
			cout << "请输入指令(只能输一次):" << endl;
			string a;
			cout << "kill " <<"杀死自己"<<endl;
			cout << "health_full " <<"生命值加满"<<endl;
			cout << "hungry_full " <<"饱食度加满"<<endl;
			cout << "air_full " <<"氧气值加满"<<endl; 
			cout << "creative "<<"创造模式"<<endl;
			cout << "move " <<"瞬移(可能死亡!)"<<endl;
			cout << "summon "<<"有几率生成BOSS"<<endl;
			
			
			cin >> a;
			if(a == "kill")
			{
				die = "失败了。";
				hurt = true;
				health = 0; 
			}
			if(a == "health_full")
			{
				health = 1000; 
			}
			if(a == "hungry_full")
			{
				hungry = 1000;
			}
			if(a == "air_full")
			{
				breath = 100;
			}
			if(a == "creative")
			{
				mode = !mode;
			}
			if(a == "move")
			{
				cin >> y >> x;
				y = 1000 - y;
			}
			if(a == "summon")
			{
				int a;
				cin >> a;
				for(int i = 0; i < 100; i++)
				{
					if(mob[i].shap == "")
					{
						mob[i] = mobs[a];
						mob[i].x = x;
						mob[i].y = y;
						break;
					}
				}
			}
			
			SetConsoleActiveScreenBuffer(hOutBuf);							// 再换回来,继续双缓冲防止屏闪
			
		}
		if(KEY_DOWN('O'))
		{
			for(int i = 0; i < 1000; i++)
			{
				for(int j = 0; j < 1000; j++)
				{
					setboard[i][j] = 0;
				}
			}
		}
		if(KEY_DOWN('P'))
		{
			for(int i = 0; i < 1000; i++)
			{
				for(int j = 0; j < 1000; j++)
				{
					setboard[i][j] = 2;
				}
			}
		}
		if(y > 1000)
		{
			die = "掉出了这个世界";
			hurt = true;
			health -= 200; 
		}
		if(breath <= 0)
		{
			breath = 0;
			hurt = true;
			health -= 10; 
		}
		if(!KEY_DOWN('S') && block[board[y - 1][x]].type == "block")
		{
			die = "在墙里窒息死亡";
			hurt = true;
			health -= 50;
		}
		if(board[y + 1][x] == 5)
		{
			hurt = true;
			die = "发现了地板是熔岩做的";
			health -= 30; 
		}
		clear_buffer();
		
		
		
	}
	return 0;
}

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

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

相关文章

短视频素材哪个App最好?短视频素材哪里有免费的?

在数字媒体的黄金时代&#xff0c;富有创意的视频内容已成为吸引观众的关键。高质量的视频素材不仅能增强视觉效果&#xff0c;还能提升整体叙述的力度。以下列出了一系列全球顶尖的视频素材提供网站&#xff0c;它们将为你的广告制作、社交媒体或任何视频项目提供极具影响力的…

Python制作精美表格——plottable

plottable是一个基础matplotlib的绘制精美图形表格的库。他将表格内容美化并转为一张图片 使用前提&#xff1a; 1、原始数据数量较少&#xff0c;可以一屏展示。这个库会将原始表格的所有数据都放到一个图片里&#xff0c;数据太多展示效果较差。 2、pandas读取时会将index列…

vue3步骤条带边框点击切换高亮

如果是div使用clip-path: polygon(0% 0%, 92% 0%, 100% 50%, 92% 100%, 0% 100%, 8% 50%);进行裁剪加边框没实现成功。目前这个使用svg完成带边框的。 形状可自行更改path 标签里的 :d“[num ! 1 ? ‘M 0 0 L 160 0 L 176 18 L 160 38 L 0 38 L 15.5 18 Z’ : ‘M 0,0 L 160,0…

飞腾D2000+X100 TYPE6全国产核心板

飞腾D2000X100 TYPE6核心板 产品概述 飞腾D2000X100 TYPE6核心板为增强型自主控制器核心板&#xff0c;其核心芯片CPU采用飞腾D2000/8核工业版CPU、飞腾桥片X100、双通道DDR4L插槽、PHY芯片等。 产品特点 l 基于飞腾D2000X100桥片 l 丰富的PCIE扩展资源&#xff0c;一路PCIE…

Java设计模式 _结构型模式_过滤器模式

一、过滤器模式 1、过滤器模式 过滤器模式&#xff08;Filter Pattern&#xff09;是这一种结构型设计模式。过滤器&#xff0c;顾名思义&#xff0c;就是对一组数据进行过滤&#xff0c;从而最终获取到我们预期的数据。 2、实现思路 &#xff08;1&#xff09;、定义过滤器的…

图搜索算法详解与示例代码

在计算机科学领域&#xff0c;图搜索算法是一类用于在图数据结构中查找特定节点或路径的算法。图搜索算法在许多领域都有着广泛的应用&#xff0c;包括网络路由、社交网络分析、游戏开发等。本文将详细介绍几种常见的图搜索算法&#xff0c;包括深度优先搜索&#xff08;DFS&am…

数据结构四:线性表之带头结点的单向循环链表的设计

前面两篇介绍了线性表的顺序和链式存储结构&#xff0c;其中链式存储结构为单向链表&#xff08;即一个方向的有限长度、不循环的链表&#xff09;&#xff0c;对于单链表&#xff0c;由于每个节点只存储了向后的结点的地址&#xff0c;到了尾巴结点就停止了向后链的操作。也就…

LeetCode 98.验证二叉搜索树

题目描述 给你一个二叉树的根节点 root &#xff0c;判断其是否是一个有效的二叉搜索树。 有效 二叉搜索树定义如下&#xff1a; 节点的左 子树 只包含 小于 当前节点的数。节点的右子树只包含 大于 当前节点的数。所有左子树和右子树自身必须也是二叉搜索树。 示例 1&#xff…

服务端不 listen 可以创建 tcp 连接吗

这个问题有三类答案。 上来就撸 linux kernel 源码&#xff0c;折腾半天&#xff0c;哦&#xff0c;终于在 tcp_rcv_state_process 里找到了 tcp_rcv_synsent_state_process 调用&#xff0c;后者包含&#xff1a; if (th->syn) {/* We see SYN without ACK. It is attemp…

如何 “ 一劳永逸 ” 去掉引用网址的小尾巴

引用文章的链接时会出现很长冗余信息&#xff0c;删&#xff0c;删&#xff0c;删……&#xff0c;直到从平流层删到地平线 示例链接 使用 Neat URL&#xff08;支持 google 系、Firefox&#xff09;扩展中的【拦截参数】可以去除的这类百无聊赖的小尾巴。 安装后&#xff…

信创 | 信创中间件全览:核心种类与关键组件!

信创产业中的中间件主要包括基础中间件和广义中间件两大类。基础中间件包括交易中间件、消息中间件、应用服务器中间件等&#xff0c;而广义中间件则涵盖了更多种类的中间件产品&#xff0c;以适应不断变化的技术需求。 一、常用的信创中间件包含&#xff1a; 交易中间件&…

20232937文兆宇 2023-2024-2 《网络攻防实践》实践八报告

20232937文兆宇 2023-2024-2 《网络攻防实践》实践八报告 1.实践内容 动手实践任务一 对提供的rada恶意代码样本&#xff0c;进行文件类型识别&#xff0c;脱壳与字符串提取&#xff0c;以获得rada恶意代码的编写作者&#xff0c;具体操作如下&#xff1a; &#xff08;1&am…

Eclipse MAT工具分析内存溢出

1、通过dominator_tree可以查看哪些对象大 可以看到com.codex.terry.entity.User对象有57万个 2、打开thread_overview查看内存溢出的代码

PyVista 3D数据可视化 Python 库 简介 含源码

Pyvista是一个用于科学可视化和分析的Python库 &#xff1b;我认为它适合做一些网格数据的处理&#xff1b; 它封装了VTK&#xff08;Visualization Toolkit&#xff09;之上&#xff0c;提供了一些高级接口&#xff0c; 3D数据可视化变得更加简单和易用。 1.安装 pyvista&…

表格中斜线的处理

此处的斜线,不是用表格写的,但是也适用于表格,只是需要更改表格的样式,可以 按照如下处理,即可 呈现的效果:如图所示 template部分: <div class"header_detail custom"><div class"right">节次</div><div class"left">…

YARN详解

YARN 简介 YARN 是Yet Another Resource Negotiator的缩写。 YARN是第二代MapReduce,即MRv2,是在第一代MapReduce基础上演变而来的,主要是为了解决原始Hadoop扩展性较差,不支持多计算框架而提出的;通俗讲就是资源管理器. YARN核心思想: 将 MR1 中资源管理和作业调度两个功能分…

Javascript:Web APIs(一)

Javascript基础&#xff08;一&#xff09; Javascript基础&#xff08;二&#xff09; Javascript基础&#xff08;三&#xff09; Javascript基础已经结束&#xff0c;接下来我们将进入到整个Web API学习中&#xff0c;在此&#xff0c;我们将学习DOM操作&#xff0c;基本的…

Linux内核之页面映射到虚拟地址:insert_page用法实例(六十五)

简介&#xff1a; CSDN博客专家&#xff0c;专注Android/Linux系统&#xff0c;分享多mic语音方案、音视频、编解码等技术&#xff0c;与大家一起成长&#xff01; 优质专栏&#xff1a;Audio工程师进阶系列【原创干货持续更新中……】&#x1f680; 优质专栏&#xff1a;多媒…

卫星通信现状与展望三 -- 6G

作者:私语茶馆 6G星地一体远景规划 中国信通院《6G总体远景与潜在关键技术白皮书》指出6G将实现地面网络、不同轨道高度上 的卫星(高中低轨卫星)以及不同空域飞行器等融合而成全新的移动信息网络,通过地面网络实现城市热点常态化覆盖,利用天基、空基网络实现偏远地…

Flink学习(九)-jar 包提交给 flink 集群执行

一、界面执行 1&#xff0c;点击左侧的 submit new job&#xff0c;然后点击add New 2&#xff0c;粘贴程序入口&#xff0c;设置并行度 3&#xff0c;执行后&#xff0c;就可以在 taskManager 中找到相关任务了 二、控制台执行 在命令行中&#xff0c;在flink 的安装目录下&…