用C语言写一个类似天天酷跑游戏(图形库用easyx)

2023-11-18

1.头文件、全局变量和结构体

  a.玩家结构体

  b.枚举玩家三种状态:奔跑、跳跃、滑行

  c.障碍物结构体

  d.障碍物结点

  e.枚举出障碍物类型

#include<stdio.h>
#include<easyx.h>
#include<conio.h>
#include<assert.h>
#include<vector>
#include"tools.h"

#pragma comment(lib,"Winmm.lib")

using namespace std;
#define WIN_WIDTH 1012
#define WIN_HEIGHT 396
#define OBSTACLE_COUNT 10

IMAGE img_bk[3];
IMAGE people_run[12];//人物跑步图片
IMAGE people_leap[12];//人物跑步图片
IMAGE people_slide[2];//人物滑行



int bk_x[3];//背景坐标
int bk_y;
int bk_speed[3] = { 1,4,8 };//背景运动速度
int obst_count;//增加障碍物时计数
bool update;//是否立即刷新
bool switch_kb;//是否需要打开按键开关
int scored;//得分

//枚举人物状态,奔跑,跳跃,滑行
enum PEOPLE_STATE
{
	run,
	leap,
	slide
};
//人物结构体
struct People
{
	int x;
	int y;
	int frame_run;//跑步时帧
	int motion_state;//人物运动状态
	int leap_height;//跳跃高度
	int frame_leap;//人物跳跃帧
	int jump_offset;//人物跳跃偏移量
	int frame_slide;//人物滑行帧
	int slide_distance;//人物滑行距离
	int exist;
}player;
//障碍物结点
struct Node
{
	struct Obstacle* obstacle_t;
	struct Node* next;
};
//障碍物类型枚举
enum OBSTACLE_TYPE
{
	tortoise,
	lion,
	fire,
	hock1,
	hock2,
	hock3,
	hock4,
	obstacle_type_count
};

//障碍物结构体
struct Obstacle
{
	OBSTACLE_TYPE type;//障碍物类型
	int x;//坐标
	int y;
	int frame_index;//图片帧
	bool exist;//判断是否存在
	int speed;//运动速度
};

vector<vector<IMAGE>>obstacleImgs;//用C++的动态数组

void LoadObstImg();
struct Obstacle* InitOb();
void PrintObImg(struct Obstacle* p_ob);
void MoveOb(struct Obstacle* p_ob);
struct Node* CreateList();
struct Node* CreateNode(Obstacle* p_ob);
void InsertNode(struct Node* p_head, struct Obstacle* p_ob);
void PrintList(struct Node* p_head);
void UpdateOb();
bool CheckCollision(struct Obstacle* p_ob);

struct Node* list = NULL;

2.制作背景和玩家

  a.加载资源和数据初始化

  b.背景绘制以及运动

  c.玩家三种状态绘制与运动

  d.键盘响应

  e.判断玩家与障碍物碰撞

//加载图片
void LoadImg()
{
	
	//加载背景
	char bk_path[20] = {0};//背景图片路径
	for (int i = 0; i < 3; i++)
	{
		sprintf(bk_path, "resource/bg%03d.png", i + 1);
		loadimage(&img_bk[i], bk_path);
	}

	//加载背景音乐
	mciSendString("open resource/bg.mp3 alias bgm", NULL, 0, NULL);
	mciSendString("play bgm repeat", NULL, 0, NULL);
	//加载人物
	char people_path1[20] = { 0 };//人物奔跑图片路径
	for (int i = 0; i < 12; i++)
	{
		sprintf(people_path1, "resource/hero%d.png", i + 1);
		loadimage(&people_run[i], people_path1);
	}
	char people_path2[20] = { 0 };//人物跳跃图片路径
	for (int i = 0; i < 12; i++)
	{
		sprintf(people_path1, "resource/g%02d.png", i + 1);
		loadimage(&people_leap[i], people_path1);
	}
	char people_path3[20] = { 0 };//人物滑行图片路径
	for (int i = 0; i < 2; i++)
	{
		sprintf(people_path3, "resource/d%d.png", i + 1);
		loadimage(&people_slide[i], people_path3);
	}
	LoadObstImg();
}

//初始化数据
void InitData()
{
	//加载窗口
	initgraph(WIN_WIDTH, WIN_HEIGHT,1);
	//背景X坐标初始为0
	bk_x[3] = { 0 };

	update = false;
	switch_kb = true;

	player.x = WIN_WIDTH*0.5 - people_run[0].getwidth()*0.5;
	player.y = 360 - people_run[0].getheight();
	player.frame_run = 0;
	player.motion_state = run;
	player.frame_leap = 0;
	player.leap_height = 100;
	player.jump_offset = -10;
	player.frame_slide = 0;
	player.slide_distance = 0;
	player.exist = true;

	scored = 0;

	 list = CreateList();//将头结点地址赋予list

	 for (int i = 0; i < OBSTACLE_COUNT; i++)
	 {
		 InsertNode(list, InitOb());
	 }
}

//打印图片
void PrintdImg()
{
	//打印背景图片
	putimagePNG2(bk_x[0], 0, &img_bk[0]);
	putimagePNG2(bk_x[1], 119, &img_bk[1]);
	putimagePNG2(bk_x[2], 330, &img_bk[2]);
	
	//打印人物奔跑图片
	if (run == player.motion_state)
	{
		putimagePNG2(player.x, player.y, &people_run[player.frame_run]);
		//人物奔跑帧改变
		player.frame_run = (player.frame_run + 1) % 12;
	}
	
	//打印人物跳跃图片
	if (leap == player.motion_state)
	{
		putimagePNG2(player.x, player.y, &people_leap[player.frame_leap]);
	}

	//打印人物滑行图片
	if (slide == player.motion_state)//如果是滑行就打印
	{
		player.y = 360 - people_slide[player.frame_slide].getheight();//打印当前图片帧的高度
		putimagePNG2(player.x, player.y, &people_slide[player.frame_slide]);
	}

	//绘制跑步分数
	settextcolor(BLACK);
	settextstyle(20, 25, "黑体");
	setbkmode(TRANSPARENT);
	char count[40];
	sprintf(count, "%d", scored);
	outtextxy(10, 20, count);
	outtextxy(textwidth(count)+10, 20, "分");

}

//图片更新运动
void Update()
{
	for (int i = 0; i < 3; i++)
	{
		bk_x[i] -= bk_speed[i];
		//当背景图片运动一个窗口距离时,重新回到原点
		if (bk_x[i] <= -WIN_WIDTH)
		{
			bk_x[i] = 0;
		}
	}

	scored++;//得分
	
	//人物跳跃运动
	if (leap == player.motion_state)
	{
		if (player.y < player.leap_height)//如果人物高度小于要求高度时,偏移量为正
		{
			player.jump_offset = 10;
		}
		player.y += player.jump_offset;//如果人物高度大于要求高度时,偏移量为负
		if (player.frame_leap != 12)
		{
			player.frame_leap++;//跳跃图片帧改变
		}
		if (player.y >= 360 - people_run[0].getheight())
		{
			player.motion_state = run;
			player.jump_offset = -10;
			player.frame_leap = 0;
			player.frame_run = 0;
			player.frame_slide = 0;
			player.y = 360 - people_run[0].getheight();
		}
	}

	//人物滑行动作
	if (slide == player.motion_state )
	{
		if (0 == player.frame_slide && player.slide_distance >= 4)
		{
			player.frame_slide += 1;
		}
		player.slide_distance++;//滑行距离
		
		if (20 == player.slide_distance)
		{
			player.frame_slide = 0;
			player.motion_state = run;
			player.frame_run = 0;
			player.slide_distance = 0;
			player.y = 360 - people_run[0].getheight();
		}
	}
	
	//检测是否碰撞,碰撞了人物和障碍物一起后移。
	struct Node* p_check = list->next;
	int one = 0;//用于标记当向前一步之后,while循环不再向前移动
	while (p_check!=NULL)
	{
		if (p_check->obstacle_t->exist == false)
		{
			p_check = p_check->next;
			continue;
		}
		if (CheckCollision(p_check->obstacle_t))
		{
			player.x -= p_check->obstacle_t->speed;
			if (player.x <= -people_run->getwidth())
			{
				player.exist = false;
			}
			return;
		}
		else
		{
			if (one<=0 && player.x <= WIN_WIDTH * 0.5 - people_run[0].getwidth() * 0.5)
			{
				player.x += 2;//当人物不在当初位置时向前移动
				one++;
			}
		}
		p_check = p_check->next;
	}
}

//按键响应
void KbControl()
{
	char keyboard = {0};
	if (_kbhit())
	{
		update = true;
		keyboard = getch();
		switch (keyboard)
		{
		case ' ':
			if (slide == player.motion_state)//滑行时可以跳跃,但是Y坐标不在奔跑时高度,需要重新初始化
			{
				player.y = 360 - people_run[0].getheight();
			}
			player.motion_state = leap;
			break;
		case 80:
			if (player.motion_state != leap)//跳跃时不允许滑行
			{
				player.motion_state = slide;
			}
			break;
		default:
			break;
		}
	}
}

3.制作障碍物

  a.创建障碍物链表

  b.加载资源

  c.障碍物运动和绘制d

  d.碰撞检测

//加载障碍物图片
void LoadObstImg()
{
	char obstacle_path[20];

	IMAGE img_tortoise;
	vector<IMAGE>tortoiseArr;
	for (int i = 0; i < 7; i++)
	{
		sprintf(obstacle_path, "resource/t%d.png", i + 1);
		loadimage(&img_tortoise, obstacle_path);
		tortoiseArr.push_back(img_tortoise);
	}
	obstacleImgs.push_back(tortoiseArr);


	IMAGE img_lion;
	vector<IMAGE>lionArr;
	for (int i = 0; i < 6; i++)
	{
		sprintf(obstacle_path, "resource/p%d.png", i + 1);
		loadimage(&img_lion, obstacle_path);
		lionArr.push_back(img_lion);
	}
	obstacleImgs.push_back(lionArr);

	IMAGE img_fire;
	vector<IMAGE>fireArr;
	for (int i = 0; i < 9; i++)
	{
		sprintf(obstacle_path, "resource/fire%d.png", i + 1);
		loadimage(&img_fire, obstacle_path, 46, 68, true);
		fireArr.push_back(img_fire);
	}
	obstacleImgs.push_back(fireArr);

	IMAGE img_hock;
	for (int i = 0; i < 4; i++)
	{
		vector<IMAGE>hockArr;
		sprintf(obstacle_path, "resource/h%d.png", i + 1);
		loadimage(&img_hock, obstacle_path,84,260,true);
		hockArr.push_back(img_hock);
		obstacleImgs.push_back(hockArr);
	}
}
//初始化障碍物
struct Obstacle* InitOb()
{
	//srand((unsigned int)time(NULL));
	struct Obstacle* p_ob = (struct Obstacle*)malloc(sizeof(struct Obstacle));
	assert(p_ob);
	
	p_ob->exist = false;
	
	return p_ob;
}
//打印障碍物
void PrintObImg(struct Obstacle* p_ob)
{
	putimagePNG2(p_ob->x, p_ob->y, &obstacleImgs[p_ob->type][p_ob->frame_index]);
}
//障碍物运动
void MoveOb(struct Obstacle* p_ob)
{
	p_ob->x -= p_ob->speed;
}
//创建头节点
struct Node* CreateList()
{
	struct Node* p_head = (struct Node*)malloc(sizeof(struct Node));
	assert(p_head);
	p_head->obstacle_t = NULL;
	p_head->next = NULL;
	return p_head;
}
//创建结点
struct Node* CreateNode(Obstacle* p_ob)
{
	struct Node* p_node = (struct Node*)malloc(sizeof(struct Node));
	assert(p_node);
	p_node->obstacle_t = p_ob;
	p_node->next = NULL;
	return p_node;
}
//连接结点
void InsertNode(struct Node* p_head, struct Obstacle* p_ob)
{
	struct Node* p_newnode = CreateNode(p_ob);
	p_newnode->next = p_head->next;
	p_head->next = p_newnode;
}
//打印结点
void PrintList(struct Node* p_head)
{
	struct Node* p_move = p_head->next;
	while (p_move != NULL)
	{
		if (false == p_move->obstacle_t->exist)
		{
			p_move = p_move->next;
			continue;
		}
		PrintObImg(p_move->obstacle_t);
		MoveOb(p_move->obstacle_t);
		//减缓障碍物帧率
		static int currFrame = 0;
		static int frame = 5;
		currFrame++;
		if (currFrame >= frame)
		{
			currFrame = 0;
			int len = obstacleImgs[p_move->obstacle_t->type].size();//获取一种障碍物的图片数量
			p_move->obstacle_t->frame_index = (p_move->obstacle_t->frame_index + 1) % len;
		}
		
		if (-obstacleImgs[p_move->obstacle_t->type][p_move->obstacle_t->frame_index].getwidth() >= p_move->obstacle_t->x)
		{
			p_move->obstacle_t->x = WIN_WIDTH;
			p_move->obstacle_t->exist = false;
		}
		
		p_move = p_move->next;
	}
}
//更新障碍物状态类型位置
void UpdateOb()
{
	//srand((unsigned int)(time(NULL)));
	struct Node* p_curr = list->next;
	while (p_curr != NULL)
	{
		if (true == p_curr->obstacle_t->exist)
		{
			p_curr = p_curr->next;
			continue;
		}
		p_curr->obstacle_t->exist = (bool)(rand() % 2);//随机产生障碍物的存在与否
		if (true == p_curr->obstacle_t->exist)
		{
			p_curr->obstacle_t->type = (OBSTACLE_TYPE)(rand() % 4);//随机产生障碍物类型
			if (hock1 == p_curr->obstacle_t->type)
			{
				p_curr->obstacle_t->type = (OBSTACLE_TYPE)(p_curr->obstacle_t->type + (rand() % 4));
			}
			p_curr->obstacle_t->frame_index = 0;
			p_curr->obstacle_t->x = WIN_WIDTH;
			p_curr->obstacle_t->y = 360 - obstacleImgs[p_curr->obstacle_t->type][p_curr->obstacle_t->frame_index].getheight();
			if (lion == p_curr->obstacle_t->type)
			{
				p_curr->obstacle_t->speed = 10;
			}
			else if (tortoise == p_curr->obstacle_t->type)
			{
				p_curr->obstacle_t->speed = 8;
				p_curr->obstacle_t->frame_index = rand() % 7;
			}
			else if (fire == p_curr->obstacle_t->type)
			{
				p_curr->obstacle_t->speed = 8;
				p_curr->obstacle_t->frame_index = rand() % 7;
			}
			else if (p_curr->obstacle_t->type >= hock1 && p_curr->obstacle_t->type <= hock4)
			{
				p_curr->obstacle_t->speed = 8;
				p_curr->obstacle_t->y = 0;
			}
			return;
		}
		p_curr = p_curr->next;
	}
}
//判断碰撞
bool CheckCollision(struct Obstacle* p_ob)
{
	int x01 = player.x + 25;
	int y01 = player.y;
	int x02 = 0;
	int y02 = 0;
	if (run == player.motion_state)
	{
		x02 = player.x + people_run->getwidth() - 20;
		 y02 = player.y + people_run->getheight();
	}
	else if (leap == player.motion_state)
	{
		 x02 = player.x + people_leap->getwidth() - 20;
		 y02 = player.y + people_leap->getheight();
	}
	else if (slide == player.motion_state)
	{
		 x02 = player.x + people_slide->getwidth() - 20;
		 y02 = player.y + people_slide->getheight();
	}
	int x11 = p_ob->x;
	int x12 = p_ob->x + obstacleImgs[p_ob->type][p_ob->frame_index].getwidth();
	int y11 = p_ob->y;
	int y12 = p_ob->y + obstacleImgs[p_ob->type][p_ob->frame_index].getheight();

	int zx = abs(abs(x01) + x02 - x11 - x12);
	int x = abs(x02 - x01) + abs(x12 - x11);
	int zy = abs(y01 + y02 - y11 - y12);
	int y = abs(y02 - y01) + abs(y12 - y11);

	return (x >= zx && y >= zy);
}

4.游戏运行

//游戏运行
void RunGame()
{
	srand(unsigned int(time(NULL)));
	while (player.exist == true)
	{
		if (timer(40, 0))
		{
			update = true;
		}
		KbControl();
		if (update)
		{
			static int currTime = 0;
			static int Time = 40 + rand() % 60;
			currTime++;
			if (currTime >= Time)
			{
				currTime = 0;
				UpdateOb();
			}
			update = false;
			BeginBatchDraw();
			PrintdImg();
			PrintList(list);
			FlushBatchDraw();
			Update();
		}
	}
}


int main(void)
{
	LoadImg();
	InitData();
	RunGame();

	getchar();
	closegraph();
	
	return 0;
}

5.tools用于透明贴图

#include <stdio.h>
#include <Windows.h>

#include <mmsystem.h>
#pragma comment(lib, "winmm.lib")
// 载入PNG图并去透明部分
void putimagePNG(int  picture_x, int picture_y, IMAGE* picture) //x为载入图片的X坐标,y为Y坐标
{
    DWORD* dst = GetImageBuffer();    // GetImageBuffer()函数,用于获取绘图设备的显存指针,EASYX自带
    DWORD* draw = GetImageBuffer();
    DWORD* src = GetImageBuffer(picture); //获取picture的显存指针
    int picture_width = picture->getwidth(); //获取picture的宽度,EASYX自带
    int picture_height = picture->getheight(); //获取picture的高度,EASYX自带
    int graphWidth = getwidth();       //获取绘图区的宽度,EASYX自带
    int graphHeight = getheight();     //获取绘图区的高度,EASYX自带
    int dstX = 0;    //在显存里像素的角标

    // 实现透明贴图 公式: Cp=αp*FP+(1-αp)*BP , 贝叶斯定理来进行点颜色的概率计算
    for (int iy = 0; iy < picture_height; iy++)
    {
        for (int ix = 0; ix < picture_width; ix++)
        {
            int srcX = ix + iy * picture_width; //在显存里像素的角标
            int sa = ((src[srcX] & 0xff000000) >> 24); //0xAArrggbb;AA是透明度
            int sr = ((src[srcX] & 0xff0000) >> 16); //获取RGB里的R
            int sg = ((src[srcX] & 0xff00) >> 8);   //G
            int sb = src[srcX] & 0xff;              //B
            if (ix >= 0 && ix <= graphWidth && iy >= 0 && iy <= graphHeight && dstX <= graphWidth * graphHeight)
            {
                dstX = (ix + picture_x) + (iy + picture_y) * graphWidth; //在显存里像素的角标
                int dr = ((dst[dstX] & 0xff0000) >> 16);
                int dg = ((dst[dstX] & 0xff00) >> 8);
                int db = dst[dstX] & 0xff;
                draw[dstX] = ((sr * sa / 255 + dr * (255 - sa) / 255) << 16)  //公式: Cp=αp*FP+(1-αp)*BP  ; αp=sa/255 , FP=sr , BP=dr
                    | ((sg * sa / 255 + dg * (255 - sa) / 255) << 8)         //αp=sa/255 , FP=sg , BP=dg
                    | (sb * sa / 255 + db * (255 - sa) / 255);              //αp=sa/255 , FP=sb , BP=db
            }
        }
    }
}

// 适用于 y <0 以及x<0的任何情况
void putimagePNG2(int x, int y, IMAGE* picture) {
    IMAGE imgTmp;
    if (y < 0) {
        SetWorkingImage(picture);
        getimage(&imgTmp, 0, -y,
            picture->getwidth(), picture->getheight() + y);
        SetWorkingImage();
        y = 0;
        picture = &imgTmp;
    }

    if (x < 0) {
        SetWorkingImage(picture);
        getimage(&imgTmp, -x, 0, picture->getwidth() + x, picture->getheight());
        SetWorkingImage();
        x = 0;
        picture = &imgTmp;
    } 

    putimagePNG(x, y, picture);
}

// 适用于 y <0 以及y>0的任何情况
void putimagePNG2(int x, int y, int winWidth, IMAGE* picture) {
    IMAGE imgTmp;
    if (y < 0) {
        SetWorkingImage(picture);
        getimage(&imgTmp, 0, -y,
            picture->getwidth(), picture->getheight() + y);
        SetWorkingImage();
        y = 0;
        picture = &imgTmp;
    }

    if (x < 0) {
        SetWorkingImage(picture);
        getimage(&imgTmp, -x, 0, picture->getwidth() + x, picture->getheight());
        SetWorkingImage();
        x = 0;
        picture = &imgTmp;
    }
    else if (x >= winWidth) {
        return;
    }
    else if (x > winWidth-picture->getwidth()) {
        SetWorkingImage(picture);
        getimage(&imgTmp, 0, 0, winWidth - x, picture->getheight());
        SetWorkingImage();
        picture = &imgTmp;
    }

    putimagePNG(x, y, picture);
}

本游戏开发基于rock老师视频内容(视频学习网站上都能找到)以及自己学到的知识编写,可以简单学习链表和图形工具的运用,根据自己的喜好加以修改,仅供学习参考,不足之处还望指出,大家一起学习进步。

资源:链接:https://pan.baidu.com/s/1sLC0f1D77iQ-EUQrTbnu-Q 
提取码:0lp8

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

用C语言写一个类似天天酷跑游戏(图形库用easyx) 的相关文章

  • 为什么使用abs()或fabs()而不是条件否定?

    在 C C 中 为什么要使用abs or fabs 不使用以下代码即可查找变量的绝对值 int absoluteValue value lt 0 value value 这与较低级别的指令较少有关吗 您提出的 有条件的abs 并不等于std
  • 在 C++ 中分割大文件

    我正在尝试编写一个程序 该程序接受一个大文件 任何类型 并将其分成许多较小的 块 我想我已经有了基本的想法 但由于某种原因我无法创建超过 12 kb 的块大小 我知道谷歌等上有一些解决方案 但我更感兴趣的是了解这个限制的根源是什么 然后实际
  • 如何进行带有偏差的浮点舍入(始终向上或向下舍入)?

    我想以偏置舍入浮动 要么总是向下 要么总是向上 代码中有一个特定的点 我需要这个 程序的其余部分应该像往常一样四舍五入到最接近的值 例如 我想四舍五入到最接近的 1 10 倍数 最接近 7 10 的浮点数约为 0 69999998807 但
  • 获取两个字符串之间的公共部分c# [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我需要的是获取两个单词之间的共同部分并获取差异 例子 场景1 word1 感言 word2 Test 将返回 公共部分Test 不同之
  • ASP .NET MVC,创建类似路由配置的永久链接

    我需要帮助在 MVC 网站中创建类似 URL 路由的永久链接 Slug 已设置为 www xyz com profile slug 代码为 routes MapRoute name Profile url profile slug defa
  • TextBox 焦点的 WinForms 事件?

    我想添加一个偶数TextBox当它有焦点时 我知道我可以用一个简单的方法来做到这一点textbox1 Focus并检查布尔值 但我不想那样做 我想这样做 this tGID Focus new System EventHandler thi
  • 调试内存不足异常

    在修复我制作的小型 ASP NET C Web 应用程序的错误时 我遇到了 OutOfMemoryException 没有关于在哪里查看的提示 因为这是一个编译时错误 如何诊断此异常 我假设这正是内存分析发挥作用的地方 有小费吗 Thank
  • ZLIB 解压缩

    我编写了一个小型应用程序 该应用程序应该解压缩以 gzip deflate 格式编码的数据 为了实现这一点 我使用 ZLIB 库 使用解压缩功能 问题是这个功能不起作用 换句话说 数据不是未压缩的 我在这里发布代码 int decompre
  • 获取从属性构造函数内部应用到哪个属性的成员?

    我有一个自定义属性 在自定义属性的构造函数内 我想将属性的属性值设置为属性所应用到的属性的类型 是否有某种方式可以访问该属性所应用到的成员从我的属性类内部 可以从 NET 4 5 using CallerMemberName Somethi
  • C++11 函数局部静态 const 对象的线程安全初始化

    这个问题已在 C 98 上下文中提出 并在该上下文中得到回答 但没有明确说明有关 C 11 的内容 const some type create const thingy lock my lock some mutex static con
  • 转到 C# WPF 中的第一页

    我正在 WPF 中使用导航服务 为了导航到页面 我使用 this NavigationService Navigate new MyPage 为了返回我使用 this NavigationService GoBack 但是如何在不使用的情况
  • 范围和临时初始化列表

    我试图将我认为是纯右值的内容传递到范围适配器闭包对象中 除非我将名称绑定到初始值设定项列表并使其成为左值 否则它不会编译 这里发生了什么 include
  • 通过不同 DLL 或 EXE 中的指针或引用访问 STL 对象时发生访问冲突

    我在使用旧版 VC6 时遇到以下问题 我只是无法切换到现代编译器 因为我正在处理遗留代码库 http support microsoft com kb 172396 http support microsoft com kb 172396
  • 如何排列表格中的项目 - MVC3 视图 (Index.cshtml)

    我想使用 ASP NET MVC3 显示特定类型食品样本中存在的不同类型维生素的含量 如何在我的视图 Index cshtml 中显示它 an example 这些是我的代码 table tr th th foreach var m in
  • 在 C 中复制两个相邻字节的最快方法是什么?

    好吧 让我们从最明显的解决方案开始 memcpy Ptr const char a b 2 调用库函数的开销相当大 编译器有时不会优化它 我不会依赖编译器优化 但即使 GCC 很聪明 如果我将程序移植到带有垃圾编译器的更奇特的平台上 我也不
  • C# 搜索目录中包含字符串的所有文件,然后返回该字符串

    使用用户在文本框中输入的内容 我想搜索目录中的哪个文件包含该文本 然后我想解析出信息 但我似乎找不到该字符串或至少返回信息 任何帮助将不胜感激 我当前的代码 private void btnSearchSerial Click object
  • 过期时自动重新填充缓存

    我当前缓存方法调用的结果 缓存代码遵循标准模式 如果存在 则使用缓存中的项目 否则计算结果 在返回之前将其缓存以供将来调用 我想保护客户端代码免受缓存未命中的影响 例如 当项目过期时 我正在考虑生成一个线程来等待缓存对象的生命周期 然后运行
  • gdb查找行号的内存地址

    假设我已将 gdb 附加到一个进程 并且在其内存布局中有一个文件和行号 我想要其内存地址 如何获取文件x中第n行的内存地址 这是在 Linux x86 上 gdb info line test c 56 Line 56 of test c
  • 我应该在应用程序退出之前运行 Dispose 吗?

    我应该在应用程序退出之前运行 Dispose 吗 例如 我创建了许多对象 其中一些对象具有事件订阅 var myObject new MyClass myObject OnEvent OnEventHandle 例如 在我的工作中 我应该使
  • 在基类集合上调用派生方法

    我有一个名为 A 的抽象类 以及实现 A 的其他类 B C D E 我的派生类持有不同类型的值 我还有一个 A 对象的列表 abstract class A class B class A public int val get privat

随机推荐

  • vue 集成高德地图

    准备工作 高德地图官网 https lbs amap com 高德地图JS API 2 0 教程 https lbs amap com api jsapi v2 summary 高德地图JS API 2 0 参考手册 https lbs a
  • python中sqlite3对数据库的增删改查

    1 python API的介绍 1 connection 数据库连接对象 连接对象 建立python客户端与数据库的网络连接 创建方法 sqlite3 connect 参数 2 cursor 游标对象 2 增删改查的流程 select语句
  • C++代码审查工具Cppcheck和TscanCode

    cppcheck简介 cppcheck 是一个静态代码检查工具 支持c c 代码 作为编译器的一种补充检查 cppcheck对源代码执行严格的逻辑检查 助力开发与测试工程师从代码层面挖掘问题 聚焦于包括逻辑错误 可疑的代码 运算错误 空指针
  • stm32通过spi连接esp8266的hspi 开发

    stm32通过spi连接esp8266的hspi 开发 刚刚做了stm32通过spi连接esp8266的开发 目前已经解决了遇到的大多数问题 基本可以交付使用了 写一篇文章留作记录 也可以给以后做这个的朋友做为参考 esp8266模块本身发
  • Nand Flash基础知识

    1 Nand Flash组织架构 Device Package 就是封装好的nand flash单元 包含了一个或者多个target 一个target包含了一个或者多个LUN 一个target的一个或者多个LUN共享一组数据信号 每个tar
  • 一个迷惑性很高的生产故障-Elasticsearch日志rotate导致节点CPU激增

    背景 Elasticsearch CPU很高的场景很常见 优化读写以及扩容即可解决问题 如果只有一个节点CPU高 那可能的情况就比较多了 节点机器异常 读写不均匀 GC过高 forcemerge 这里描述一个极具迷惑性的case 问题 收到
  • 电机专题2:直流有刷电机工作原理

    直流有刷电机的工作原理 直流有刷电机 其实就是直接最简单的方式利用安培力 给导线通电 然后在磁场中运动 在上面的电流电机物理模型中 电刷和主磁铁是固定不动的 是电机的定子 绕组线圈和换向片连接到一起 为转子 电机的工作过程 这种是直流有刷电
  • diskmark使用教程

    raid盘测速 首先说明一下软件各个参数的意义 1 9 测试次数 50MB 4000MB 测试规模 C D E F选择测试对象 ALL 测试以下所有 第一行代表你硬盘的读写速度 第二行代表你硬盘4K文件多线程读写速度 第三行代表你硬盘的连续
  • 计算机概论易错题总结:概念类

    为期末考试 冲鸭 文字类 1 在计算机运行时 把程序和数据一样存放在内存中 这是1946年由 领导的研究小组 正式提出并论证的 冯 诺依曼 2 被誉为第一位程序员的是 Augusta 3 我国自行设计研制的天河2号计算机是 巨型机 记法 天
  • JSP动态网页设计——tomcat配置、第一个动态工程

    默认设置 已完成eclipse安装 JDK安装 环境配置 下载tomcat压缩包 已上传至资源 并解压好 启动tomcat 在此文件夹下找到bin文件 在bin目录下点击startup bat 启动标志 双击弹出黑框 若出现以下图片 则已启
  • STL之Set基本用法

    单独说一下Set是因为这个工具以前很少用 因为接触不多 后来发现功能太强大了 本来很多题目用Set可以快速通过 但无奈之前都没有使用set的习惯 导致吃了不少亏 set功能非常强大 原因在于Set就是一棵二叉搜索树 我们在很多题目中经常遇到
  • 在Android下初始化Native OpenGL ES

    在上一篇文章中 介绍了在Android Native层初始化EGL及OpenGL ES的方法 其中 大量代码花费在EGL的初始化上面 非常的麻烦 在本文中 将展示利用GLSurfaceView来代替我们手动初始化EGL的过程 用GLSurf
  • 数据分析 告诉你《飞驰人生》为什么这么燃?

    数据分析 飞驰人生 为什么这么燃 2019年贺岁电影 飞驰人生 在豆瓣排名和猫眼排名中都排名第二的位置 我们这里爬取了豆瓣500条的评论数据来 分析一下 飞驰人生 为何这么燃 这里说明一下 之所以获取这么点数据 是豆瓣的 的反爬限制 非登录
  • Vue 0基础学习路线(24)—— 图解深度详述vue的路由动画效果的使用及详细案例(附详细案例代码解析过程及版本迭代过程)

    文章目录 1 路由动画效果 2 实例 2 1 example01 1 路由动画效果 路由动画 gt 利用 transition 组件 我们还可以给路由导航加上动效 App vue
  • TCP/IP协议:传输层之UDP

    一 UDP用户数据报协议 它是一个无连接的 面向数据报的协议 它不提供可靠性但传输速度比TCP要快 UDP数据报中的 UDP长度 为两个字节 所以我们要发送的UDP数据最多支持65507大约68K的数据 超过该大小的话需要自己来分割发送 使
  • JAVA如何连接redis以及Springboot整合redis详解

    1 java连接redis 1 1 java连接单机redis 首先创建一个普通的maven工程 1 引入依赖
  • 我发现了一个很好看的字体,霞鹜文楷!如何换windows和typora字体?

    1 字体 官方地址如下 下载也很简单 https github com lxgw LxgwWenKai 有1W多的stars 方式 直接打包下载 下载不来 可以联系在下面留言 然后ttf的文件 全部安装就行了 2 更换系统字体 然后换win
  • Codeforces Round 871 (Div. 4)G. Hits Different

    G Hits Different 题意 给一个如图所示的三角形 输入n 击倒方块n 获得分数n n 同时方块n上面的两个方块也会落下 同时获得这两个方块的分数 一直向上走 知道方块1 如图所示为n 9的时候掉落的方块 求获得的分数 思路 先
  • python对csv文件取特定列生成新csv文件

    import csv import os def file name in file out file reader csv reader in file header next reader data header format head
  • 用C语言写一个类似天天酷跑游戏(图形库用easyx)

    1 头文件 全局变量和结构体 a 玩家结构体 b 枚举玩家三种状态 奔跑 跳跃 滑行 c 障碍物结构体 d 障碍物结点 e 枚举出障碍物类型 include