C++之文字修仙小游戏

news2025/3/15 16:28:37

1 效果

1.1 截图

游戏运行:

存档:

 1.2 游玩警告

注意!不要修改装备概率,装备的概率都是凑好的数字。如果想要速升,修改灵石数量

2 代码

2.1 代码大纲

1. 游戏框架与初始化

  • 控制台操作:通过 gotoxy() 和 hide_cursor() 控制光标位置与可见性,color() 函数设置颜色,实现动态界面。

  • 全局变量:管理玩家等级(Lv)、经验(Exp)、关卡(G)、灵石(SpiritStone)等核心数据,以及装备稀有度概率(如 GreyGreen)。

  • 初始化函数 init():重置装备数据、加载存档、设置控制台颜色并隐藏光标。


2. 装备系统

  • 结构体 equipment

    • 属性 稀有度(rare)、等级(lv)、类型(type)、名称(name)、伤害(damage)、生命值(HP)和威力(power)。

    • 动态颜色 (ecolor()):根据稀有度显示不同颜色(如灰色、绿色),高稀有度装备(如红色、彩虹)使用 HSL 动态渐变。

    • 装备生成 (init()):基于类型和稀有度生成名称(如“玄铁重剑”)、计算属性,稀有度越高加成越大(如彩虹装备伤害+80%)。


3. 战斗与关卡

  • 战斗循环:玩家与敌人轮流攻击,血量(HPnowMHPnow)实时更新,伤害由装备属性累加计算。

  • 关卡推进:击败敌人后关卡(G)递增,敌人血量根据公式 MHP = G * G 动态增长。

  • 装备掉落:击败敌人随机生成新装备,玩家可选择替换或分解,分解获得灵石和经验。


4. 成长与升级

  • 角色升级:经验值(Exp)满后提升等级,解锁更高境界(如筑基期、金丹期)。

  • 仙树升级:消耗灵石升级仙树(TreeLV),调用 TreeUP() 调整稀有度概率(如减少灰色装备概率,增加橙色概率)。

  • 属性计算:玩家总血量(HP)和伤害(damage)由装备属性累加,功力(power)进行装备战力估算。


5. 存档与颜色处理

  • 存档机制SaveRecord() 和 LoadRecord() 将装备数据、等级、灵石等保存至文件(equipment.save 和 Tree.save)。

  • HSL转RGBHSLtoRGB() 函数实现动态颜色效果(如至宝装备颜色渐变),增强视觉表现。


6. 关键逻辑细节

  • 装备生成概率:根据 GreyGreen 等全局变量加权随机,高关卡解锁更稀有装备。

  • 时间控制times 变量控制攻击动画节奏,Sleep(20) 调节循环速度。

2.2 游戏代码

#include <iostream>
#include <Windows.h>
#include <conio.h>
#include <time.h>
#include <string>
#include <fstream>
#include <sstream>
#include <vector>

#define Rgrey 1
#define Rgreen 2
#define Rblue 3
#define Rpurple 4
#define Rorange 5
#define Rred 6
#define Rgold 7
#define Rlightblue  8
#define Rrainbow 9
#define RRrainbow 10
#define Rblack 11
#define RRblack 12

using namespace std;

int Lv = 0, Exp = 0, Exp2 = 50;
int times = 0;

int G = 1;
int TreeLV = 1;
int Grey = 33;
int Green = 31;
int Blue = 25;
int Purple = 11;
int Orange = 0;
int Red = 0;
int Gold = 0;
int Lightblue = 0;
float Rainbow = 0;
float Rainbow2 = 0;
float Black = 0;
float Black2 = 0;

int EquipmentLV = 1;
long long SpiritStone = 0;

struct equipment;
struct COLORRGB;
int getrand(int min, int max);
void gotoxy(int x, int y);
void hide_cursor();
void color(int r, int g, int b);
void color2(COLORRGB c);
void init();
void TreeUP();
void SaveRecord();
void LoadRecord();
void ecolor(short rare);

COLORRGB HSLtoRGB(float h, float s, float l);

struct COLORRGB { int r, g, b; };
struct equipment
{
	short rare = 0;
	int lv = 1;
	char type[20] = { "" };
	char name[20] = { "" };
	int damage = 0;
	long long HP = 0;
	long long power = 0;

	void ecolor()
	{
		switch (rare)
		{
		case Rgrey: color(140, 140, 140); break;
		case Rgreen: color(0, 153, 0); break;
		case Rblue: color(0, 0, 153); break;
		case Rpurple: color(102, 0, 204); break;
		case Rorange: color(255, 153, 51); break;
		case Rred:
			color(175 + (times / 2) % 80, 0, 0);
			if ((times / 2) % 160 >= 80) color(255 - (times / 2) % 80, 0, 0);
			break;
		case Rgold:
			color(220 + (times / 3) % 20, 220 + (times / 3) % 20, 0);
			if ((times / 3) % 40 >= 20) color(240 - (times / 3) % 20, 240 - (times / 3) % 20, 0);
			break;
		case Rlightblue:
		{
			float H = 211;
			float S = 1;
			if (times % 200 >= 100) color2(HSLtoRGB(H, S, 0.85f - float(times % 100) / 500));
			else color2(HSLtoRGB(H, S, 0.65f + float(times % 100) / 500));
			break;
		}
		case Rrainbow:
		{
			float S = 1;
			float L = 0.5f;
			color2(HSLtoRGB(times % 720 / 2, S, L));
			break;
		}
		case RRrainbow:
		{
			float S = 1;
			float L = 0.5f;
			color2(HSLtoRGB(times % 360, S, L));
			break;
		}
		case Rblack:
		{
			float H = 0;
			float S = 0;
			if (times % 200 >= 100)
			{
				color2(HSLtoRGB(H, S, 0.25f - float(times % 100) / 400));
			}
			else
			{
				color2(HSLtoRGB(H, S, float(times % 100) / 400));
			}
			break;
		}
		case RRblack:
		{
			float H = 0;
			float S = 0;
			if (times % 200 >= 100)
			{
				color2(HSLtoRGB(H, S, 0.5f - float(times % 100) / 200));
			}
			else
			{
				color2(HSLtoRGB(H, S, float(times % 100) / 200));
			}
			break;
		}
		default: color(245, 245, 245);
		}
	}

	void init(short _rare, short _type)
	{
		lv = Lv + 1;
		rare = _rare;

		const char* types[9] = { "头盔", "护甲", "护腿", "披风", "护臂", "护腕", "武器", "宝物" };
		strcpy_s(type, types[_type]);

		const char* names[8][13] = {
			{"", "铜盔", "玄铁帽", "岩骨护盔", "星玄流云盔", "淬星龙鳞冠", "紫淬寰宇冠", "鸿蒙太虚冠", "九转星璇盔", "灭世星辰冠", "灵宝-星辰冠", "玄龙", "道"},
			{"", "布衣", "藤心软甲", "玄龟灵甲", "金丝蟠龙铠", "九霄雷纹甲", "紫淬龙宇铠", "无相法身袍", "混元星璇袍", "寰宇灭世铠", "灵宝-寰宇铠", "破天", "法"},
			{"", "草编护腿", "铁锁护腿", "青蟒护腿", "玄冰踏云腿", "金乌焚尘腿", "流风逐月腿", "八荒六合腿", "太乙青冥腿", "日月琼天腿", "灵宝-日月腿", "神霄", "神"},
			{"", "布织斗篷", "狼裘披风", "玄鹤羽氅", "赤霞飞云帔", "金乌焰翎", "乾坤一气幡", "八荒太极袍", "太虚寰宇氅", "万象归墟幡", "灵宝-归墟幡", "护道", "霄"},
			{"", "灰布缠臂", "铜虎臂", "赤蛟吞云臂", "玄铁护心臂", "紫电惊雷臂", "龙魂缚天臂", "盘龙天蚕扣", "阴阳两仪环", "寂灭轮回臂", "灵宝-轮回臂", "踏仙", "寂"},
			{"", "草绳腕带", "铁纹护腕", "冰魄玉环", "玄火缠丝扣", "金乌焚天腕", "太阴锁灵环", "须弥太极腕", "造化寰宇腕", "玄天寂灭腕", "灵宝-玄天腕", "寂世", "世"},
			{"", "生锈短刀", "青锋短匕", "玄铁重剑", "赤霄斩月刀", "九幽噬魂枪", "太虚星辰剑", "破界碎空戟", "混沌太虚剑", "轮回灭世戟", "灵宝-灭世戟", "万道", "墟"},
			{"", "聚灵珠", "琉璃钟", "三昧真火珠", "玄冰凝魂镜", "金乌炎阳珠", "太虚玄火钟", "周天星辰珠", "鸿蒙造化珠", "万象归墟镜", "灵宝-归墟镜", "太虚", "灵"}
		};

		strcpy_s(name, names[_type][_rare]);

		damage = getrand(lv * 14, lv * 14 + 10);
		HP = getrand(lv * 50, lv * 50 + 10);

		if (_type == 6)
		{
			damage *= 1.3;
			HP /= 1.1;
		}
		if (_type == 7)
		{
			damage /= 1.1;
			HP *= 1.3;
		}

		switch (rare)
		{
		case Rblue: damage *= 1.05; HP *= 1.2; break;
		case Rpurple: damage *= 1.15; HP *= 1.35; break;
		case Rorange: damage *= 1.25; HP *= 1.65; break;
		case Rred: damage *= 1.4; HP *= 1.95; break;
		case Rgold: damage *= 1.5; HP *= 2.1; break;
		case Rlightblue: damage *= 1.6; HP *= 2.3; break;
		case Rrainbow: damage *= 1.7; HP *= 2.5; break;
		case RRrainbow: damage *= 1.8; HP *= 2.7; break;
		case Rblack: damage *= 2.0; HP *= 3.1; break;
		case RRblack: damage *= 2.2; HP *= 5.0; break;
		}

		if (_rare == 0)
		{
			strcpy_s(name, type);
			HP = 0;
			damage = 0;
		}
		else
		{
			power = rare * 84 + lv * 104 + HP * 15 + damage * 45;
		}
	}
} E[15];

int main()
{
	bool NewEquipment = false;
	short randtype = 0;
	int MHPnow = 10, MHP = 10, damage = 1;
	int _damage = 1, _power = 0;
	long long _HP = 0;
	long long HPnow = 100, HP = 100, power = 0;
	equipment equ;

	init();
	for (short i = 0; i < 8; i++)
	{
		_HP += E[i].HP;
		_damage += E[i].damage;
		_power += E[i].power;
	}
	HP = _HP + 100;
	HPnow = HP;
	power = _power;
	damage = _damage;

	MHP = G * 2 * G;
	if (G >= 100) MHP = max(G * 1.5 * G, 100 * 2 * 100);
	else if (G >= 150) MHP = max(G * 1.3 * G, G * 1.5 * G);
	else if (G >= 200) MHP = max(G * G, G * 1.3 * G);
	else if (G >= 250) MHP = max(G * G / 1.1, G * G);
	else if (G >= 300) MHP = max(G * G / 1.3, G * G / 1.1);
	else MHP = max(G * G / 1.5, G * G / 1.3);
	if (MHP <= 5) MHP = 5;
	MHPnow = MHP;

	bool upgrade = false;
	int UpgradeTimes = 10, UpgradeTimes2 = 10;
	UpgradeTimes = TreeLV * 10 + (TreeLV - 1) * 15;
	UpgradeTimes2 = UpgradeTimes;

	while (1) {
		while (HPnow > 0)
		{
			for (short i = 0; i < 8; i++)
			{
				E[i].ecolor();
				gotoxy(4, 2 + i * 2);
				printf("[%d级]%s  ", E[i].lv, E[i].name);
			}
			color(0, 0, 0);

			if (Red > 0 || Orange > 0 || Purple > 0)
			{
				gotoxy(100, 2); ecolor(1);
				printf("凡品概率 %d%%  ", Grey);
				gotoxy(100, 4); ecolor(2);
				printf("下品概率 %d%%  ", Green);
				gotoxy(100, 6); ecolor(3);
				printf("中品概率 %d%%  ", Blue);
				gotoxy(100, 8); ecolor(4);
				printf("上品概率 %d%%  ", Purple);
				gotoxy(100, 10); ecolor(5);
				printf("极品概率 %d%%  ", Orange);
				gotoxy(100, 12); ecolor(6);
				printf("仙品概率 %d%%  ", Red);
				gotoxy(100, 14); ecolor(7);
				printf("完美概率 %d%%  ", Gold);
				gotoxy(100, 16); ecolor(8);
				printf("先天概率 %d%%  ", Lightblue);
				gotoxy(100, 18); ecolor(9);
				printf("至宝概率 %.2f%%  ", Rainbow);
			}
			else
			{
				gotoxy(100, 2); ecolor(6);
				printf("仙品概率 %d%%  ", Red);
				gotoxy(100, 4); ecolor(7);
				printf("完美概率 %d%%  ", Gold);
				gotoxy(100, 6); ecolor(8);
				printf("先天概率 %d%%  ", Lightblue);
				gotoxy(100, 8); ecolor(9);
				printf("至宝概率 %.2f%%  ", Rainbow);
				gotoxy(100, 10); ecolor(10);
				printf("灵宝概率 %.2f%%  ", Rainbow2);
				gotoxy(100, 12); ecolor(11);
				printf("神器概率 %.2f%%  ", Black);
				gotoxy(100, 14); ecolor(12);
				printf("仙器概率 %.2f%%  ", Black2);
			}
			color(0, 0, 0);
			gotoxy(4, 18);
			printf("血量:%d  ", HP);
			gotoxy(4, 19);
			printf("攻击:%d  ", damage);
			gotoxy(4, 20);
			if (Lv < 10) printf("练气期");
			else if (Lv < 20) printf("筑基期");
			else if (Lv < 30) printf("金丹期");
			else if (Lv < 40) printf("元婴期");
			else if (Lv < 50) printf("化神期");
			else if (Lv < 60) printf("炼虚期");
			else if (Lv < 70) printf("合体期");
			else if (Lv < 80) printf("大乘期");
			else if (Lv < 90) printf("渡劫期");
			else if (Lv < 100) printf("金仙期");
			else if (Lv < 110) printf("真仙期");
			else if (Lv < 120) printf("地仙期");
			else if (Lv < 130) printf("天仙期");
			else  printf("玄仙期%d级", (Lv - 130) / 10 + 1);
			printf("%d阶 (%d/%d)      ", Lv % 10 + 1, Exp, Exp2);
			gotoxy(4, 21);
			printf("功力:%lld  ", power + (Lv - 1) * 203);
			gotoxy(4, 22);
			printf("灵石:%lld  ", SpiritStone);
			gotoxy(4, 23);
			printf("仙树等级:%d", TreeLV);
			if (!(SpiritStone >= TreeLV * 322 + (TreeLV - 1) * 638))
			{
				gotoxy(4, 24);
				color(90, 90, 90);
				if (TreeLV < 87)
					printf("(需%d灵石可升级)  ", TreeLV * 322 + (TreeLV - 1) * 638);
			}
			else
			{
				if (upgrade == false)
				{
					gotoxy(4, 24);
					color(0, 153, 0);
					if (TreeLV < 87)
					{
						printf("(可升级 按F键升级)     ");
						if (GetAsyncKeyState('F') & 0x8000)
						{
							upgrade = true;
							SpiritStone -= TreeLV * 322 + (TreeLV - 1) * 638;
						}
					}
					else
					{
						color(90, 90, 90);
						printf("已满级");
					}
				}
				else if (!(GetAsyncKeyState('F') & 0x8000))
				{
					if (UpgradeTimes <= 0)
					{
						UpgradeTimes = TreeLV * 5 + UpgradeTimes2 / 2 + (TreeLV - 1) * 10;
						UpgradeTimes2 = UpgradeTimes;
						upgrade = false;
						gotoxy(4, 24);
						printf("                                             ");
						TreeUP();
						TreeLV++;
					}
					else
					{
						gotoxy(4, 24);
						color(0, 0, 0);
						printf("正在升级 需%d秒 按P花费%d灵石立刻升级", UpgradeTimes, UpgradeTimes * 50);
						if (times % 30 == 0)
						{
							if (upgrade) UpgradeTimes--;
						}
						if (GetAsyncKeyState('P') & 0x8000)
						{
							if (SpiritStone >= UpgradeTimes * 50)
							{
								SpiritStone -= UpgradeTimes * 50;
								UpgradeTimes = 0;
							}
							else
							{
								SpiritStone = 0;
								UpgradeTimes -= SpiritStone / 50;
							}
						}
					}
				}
			}

			color(0, 0, 0);

			gotoxy(58, 1);
			printf("关卡 %d", G);
			color(0, 153, 0);
			gotoxy(50, 8); printf("我");
			gotoxy(44, 9);
			printf("HP:%d / %d   ", HPnow, HP);
			color(153, 0, 0);
			gotoxy(72, 8); printf("敌");
			gotoxy(66, 9);
			printf("HP:%d / %d   ", MHPnow, MHP);

			if (NewEquipment == true)
			{
				equ.ecolor();
				gotoxy(45, 12);
				printf("获得新装备:[%d级]%s", equ.lv, equ.name);
				gotoxy(45, 13);
				printf("功力 %d(%+d)", equ.power, equ.power - E[randtype].power);
				gotoxy(45, 14);
				printf("血量 %d(%+d)", equ.HP, equ.HP - E[randtype].HP);
				gotoxy(45, 15);
				printf("伤害 %d(%+d)", equ.damage, equ.damage - E[randtype].damage);
				gotoxy(45, 16);
				printf("替换并分解原装备(y) 分解(n)", equ.damage, equ.damage - E[randtype].damage);
				if (GetAsyncKeyState('Y') & 0x8000)
				{
					Exp = Exp + 10 + equ.power / 1000;
					SpiritStone += E[randtype].power / 10;
					E[randtype] = equ;
					NewEquipment = false;
					long long _HP = 100;
					int _damage = 1;
					int _power = 0;

					for (short i = 0; i < 8; i++)
					{
						_HP += E[i].HP;
						_damage += E[i].damage;
						_power += E[i].power;
					}
					HP = _HP + 100;
					HPnow = HP;
					power = _power;
					damage = _damage;
					SaveRecord();
					system("cls");
				}
				else if (GetAsyncKeyState('N') & 0x8000)
				{
					Exp = Exp + 10 + E[randtype].power / 1000;
					SpiritStone += equ.power / 10;
					NewEquipment = false;
					system("cls");
					HPnow = HP;
				}
			}
			if (NewEquipment == false)
			{
				if (times % 30 == 1)
				{
					color(240, 240, 240);
					gotoxy(72, 8); printf("敌");
					Exp++;
				}

				if (times % 30 == 16)
				{
					color(240, 240, 240);
					gotoxy(50, 8); printf("我");
					Exp++;
				}

				if (times % 15 == 0)
				{
					if (times % 30 == 15)
					{
						HPnow -= G * G / 10;
						color(240, 240, 240);
						gotoxy(50, 8); printf("我");
					}
					else
					{
						MHPnow -= damage;
						color(240, 240, 240);
						gotoxy(72, 8); printf("敌");
					}
				}
				if (Exp >= Exp2)
				{
					Exp -= Exp2;
					Exp2 = Exp2 += Lv * 5;
					Lv++;
					if (Lv % 10 == 0) Exp2 -= 100;
				}
			}
			if (MHPnow <= 0)
			{
				Sleep(200);
				G++;
				MHP = G * 2 * G;
				if (G >= 100) MHP = max(G * 1.5 * G, 100 * 2 * 100);
				else if (G >= 150) MHP = max(G * 1.3 * G, G * 1.5 * G);
				else if (G >= 200) MHP = max(G * G, G * 1.3 * G);
				else if (G >= 250) MHP = max(G * G / 1.1, G * G);
				else if (G >= 300) MHP = max(G * G / 1.3, G * G / 1.1);
				else MHP = max(G * G / 1.5, G * G / 1.3);
				if (MHP <= 5) MHP = 5;
				MHPnow = MHP;
				randtype = getrand(0, 7);
				int EquipmentRand = getrand(1, 100);
				if (EquipmentRand <= Grey)
					equ.init(Rgrey, randtype);
				else if (EquipmentRand - Grey <= Green)
					equ.init(Rgreen, randtype);
				else if (EquipmentRand - Grey - Green <= Blue)
					equ.init(Rblue, randtype);
				else if (EquipmentRand - Grey - Green - Blue <= Purple)
					equ.init(Rpurple, randtype);
				else if (EquipmentRand - Grey - Green - Blue - Purple <= Orange)
					equ.init(Rorange, randtype);
				else if (EquipmentRand - Green - Blue - Purple - Orange <= Red)
					equ.init(Rred, randtype);
				else if (EquipmentRand - Blue - Purple - Orange - Red <= Gold)
					equ.init(Rgold, randtype);
				else if (EquipmentRand - Purple - Orange - Red - Gold <= Lightblue)
					equ.init(Rlightblue, randtype);
				else if (EquipmentRand - Orange - Red - Gold - Lightblue <= Rainbow)
					equ.init(Rrainbow, randtype);
				else if (EquipmentRand - Red - Gold - Lightblue - Rainbow <= Rainbow2)
					equ.init(RRrainbow, randtype);
				else if (EquipmentRand - Gold - Lightblue - Rainbow - Rainbow2 <= Black)
					equ.init(Rblack, randtype);
				else if (EquipmentRand - Gold - Lightblue - Rainbow - Rainbow2 - Black <= Black2)
					equ.init(RRblack, randtype);

				if (G == 51)
				{
					strcpy_s(equ.type, "");
					equ.rare = Rorange;
					equ.HP = 9999;
					equ.damage = 2999;
				}
				NewEquipment = true;

				system("cls");
			}
			times++;
			if (times == 3000) times = 0;
			Sleep(20);
		}
		init();
		for (short i = 0; i < 8; i++)
		{
			_HP += E[i].HP;
			_damage += E[i].damage;
			_power += E[i].power;
		}
		HP = _HP + 100;
		HPnow = HP;
		power = _power;
		damage = _damage;
		MHPnow = MHP;
		system("cls");
		gotoxy(58, 4);
		color(0, 0, 0);
		printf("GA"); Sleep(1000);
		printf("ME"); Sleep(1000);
		printf(" OV"); Sleep(1000);
		printf("ER"); Sleep(1000);
	}
}

void init()
{
	srand(time(0));

	for (short i = 0; i < 8; i++)
	{
		E[i].init(0, i);
	}
	LoadRecord();

	system("color F0");
	hide_cursor();
	Lv++;
}

int getrand(int min, int max)
{
	return (rand() % (max - min + 1)) + min;
}

void gotoxy(int x, int y)
{
	COORD c;
	c.X = x;
	c.Y = y;
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), c);
}

void hide_cursor()
{
	HANDLE h_GAME = GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_CURSOR_INFO cursor_info;
	GetConsoleCursorInfo(h_GAME, &cursor_info);
	cursor_info.bVisible = false;
	SetConsoleCursorInfo(h_GAME, &cursor_info);
}

void color(int r, int g, int b)
{
	wprintf(L"\x1b[38;2;%d;%d;%dm", r, g, b);
}
void color2(COLORRGB c)
{
	wprintf(L"\x1b[38;2;%d;%d;%dm", c.r, c.g, c.b);
}
void TreeUP()
{
	if (Grey > 0)
	{
		if (Grey > 3)
		{
			Grey -= 6;
			Green += 2;
			Blue += 2;
			Purple += 2;
		}
		else
		{
			Grey -= 3;
			Green += 1;
			Blue += 1;
			Purple += 1;
		}
	}
	else if (Green > 0)
	{
		Green -= 6;
		Blue += 2;
		Purple += 2;
		Orange += 2;
	}
	else if (Blue > 0)
	{
		Blue -= 5;
		Purple++;
		Orange += 2;
		Red += 2;
	}
	else if (Purple > 0)
	{
		if (Purple > 2)
		{
			Purple -= 4;
			Red += 2;
			Gold += 2;
		}
		else
		{
			Purple -= 2;
			Red += 1;
			Gold += 1;
		}
	}
	else if (Orange > 0)
	{
		if (Purple > 2)
		{
			Orange -= 4;
			Gold += 2;
			Lightblue += 2;
		}
		else
		{
			Orange -= 2;
			Gold += 1;
			Lightblue += 1;
		}
	}
	else if (Red > 0)
	{
		if (Red == 43)
		{
			Red -= 3;
			Rainbow += 3;
		}
		else
		{
			Red -= 5;
			Gold += 1;
			Lightblue += 2;
			Rainbow += 2;
		}
	}
	else if (Gold > 0)
	{
		Gold -= 6;
		Lightblue += 2;
		Rainbow += 3.5;
		Rainbow2 += 0.5;
	}
	else if (Lightblue > 0)
	{
		Lightblue -= 7;
		Rainbow += 5.2;
		Rainbow2 += 1.3;
		Black += 0.4;
		Black2 += 0.1;
	}
	else if (Rainbow > 0)
	{
		Rainbow -= 8.34;
		Rainbow2 += 2.34;
		Black += 4;
		Black2 += 2;
		if (TreeLV == 86) Rainbow = 0;
	}
}
// 文件操作:保存记录
void SaveRecord() {
	ofstream file("equipment.save");
	for (short i = 0; i < 8; i++)
	{
		file << E[i].HP << " ";
		file << E[i].damage << " ";
		file << E[i].lv << " ";
		file << E[i].rare << " ";
		file << E[i].power << endl;

		file << E[i].type << " ";
		file << E[i].name << endl;
	}

	ofstream file2("Tree.save");
	file2 << Grey << " ";
	file2 << Green << " ";
	file2 << Blue << " ";
	file2 << Purple << " ";
	file2 << Orange << " ";
	file2 << Red << " ";
	file2 << Gold << " ";
	file2 << Lightblue << " ";
	file2 << Rainbow << " ";
	file2 << Rainbow2 << " ";
	file2 << Black << " ";
	file2 << Black2 << " ";
	file2 << Lv << " ";
	file2 << Exp << " ";
	file2 << Exp2 << " ";
	file2 << TreeLV << " ";
	file2 << SpiritStone << " ";
	file2 << G << " ";
}

// 文件操作:加载记录
void LoadRecord() {
	ifstream file("equipment.save");
	if (file) {
		for (short i = 0; i < 8; i++)
		{
			file >> E[i].HP;
			file >> E[i].damage;
			file >> E[i].lv;
			file >> E[i].rare;
			file >> E[i].power;

			file >> E[i].type;
			file >> E[i].name;
		}
	}
	ifstream file2("Tree.save");
	if (file2)
	{
		file2 >> Grey;
		file2 >> Green;
		file2 >> Blue;
		file2 >> Purple;
		file2 >> Orange;
		file2 >> Red;
		file2 >> Gold;
		file2 >> Lightblue;
		file2 >> Rainbow;
		file2 >> Rainbow2;
		file2 >> Black;
		file2 >> Black2;
		file2 >> Lv;
		file2 >> Exp;
		file2 >> Exp2;
		file2 >> TreeLV;
		file2 >> SpiritStone;
		file2 >> G;
	}
}

COLORRGB HSLtoRGB(float h, float s, float l) {
	COLORRGB C;
	float r, g, b;

	if (s == 0) {
		r = g = b = static_cast<int>(l * 255);
	}
	else {
		float m2;
		if (l < 0.5) {
			m2 = l * (1 + s);
		}
		else {
			m2 = l + s - l * s;
		}
		float m1 = 2 * l - m2;

		float t_r = h / 360.0f + 1.0f / 3.0f;
		float t_g = h / 360.0f;
		float t_b = h / 360.0f - 1.0f / 3.0f;

		std::vector<float> color_list = { t_r, t_g, t_b };
		for (float& color : color_list) {
			if (color < 0) color += 1.0f;
			if (color > 1) color -= 1.0f;
		}

		std::vector<float> rgb_values;
		for (float t : color_list) {
			float c_i;
			if (t < 1.0f / 6.0f) {
				c_i = m1 + (m2 - m1) * 6.0f * t;
			}
			else if (t < 3.0f / 6.0f) {
				c_i = m2;
			}
			else if (t < 4.0f / 6.0f) {
				c_i = m1 + (m2 - m1) * (4.0f - 6.0f * t);
			}
			else {
				c_i = m1;
			}
			rgb_values.push_back(c_i);
		}

		r = static_cast<int>(rgb_values[0] * 255);
		g = static_cast<int>(rgb_values[1] * 255);
		b = static_cast<int>(rgb_values[2] * 255);
	}
	C.r = r;
	C.g = g;
	C.b = b;
	return C;
}

void ecolor(short rare)
{
	switch (rare)
	{
	case Rgrey: color(140, 140, 140); break;
	case Rgreen: color(0, 153, 0); break;
	case Rblue: color(0, 0, 153); break;
	case Rpurple: color(102, 0, 204); break;
	case Rorange: color(255, 153, 51); break;
	case Rred:
		color(175 + (times / 2) % 80, 0, 0);
		if ((times / 2) % 160 >= 80) color(255 - (times / 2) % 80, 0, 0);
		break;
	case Rgold:
		color(220 + (times / 3) % 20, 220 + (times / 3) % 20, 0);
		if ((times / 3) % 40 >= 20) color(240 - (times / 3) % 20, 240 - (times / 3) % 20, 0);
		break;
	case Rlightblue:
	{
		float H = 211;
		float S = 1;
		if (times % 200 >= 100) color2(HSLtoRGB(H, S, 0.85f - float(times % 100) / 500));
		else color2(HSLtoRGB(H, S, 0.65f + float(times % 100) / 500));
		break;
	}
	case Rrainbow:
	{
		float S = 1;
		float L = 0.5f;
		color2(HSLtoRGB(times % 720 / 2, S, L));
		break;
	}
	case RRrainbow:
	{
		float S = 1;
		float L = 0.5f;
		color2(HSLtoRGB(times % 360, S, L));
		break;
	}
	case Rblack:
	{
		float H = 0;
		float S = 0;
		if (times % 200 >= 100)
		{
			color2(HSLtoRGB(H, S, 0.25f - float(times % 100) / 400));
		}
		else
		{
			color2(HSLtoRGB(H, S, float(times % 100) / 400));
		}
		break;
	}
	case RRblack:
	{
		float H = 0;
		float S = 0;
		if (times % 200 >= 100)
		{
			color2(HSLtoRGB(H, S, 0.5f - float(times % 100) / 200));
		}
		else
		{
			color2(HSLtoRGB(H, S, float(times % 100) / 200));
		}
		break;
	}
	default: color(245, 245, 245);
	}
}

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

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

相关文章

MacOS 15.3.1 安装 GPG 提示Error: unknown or unsupported macOS version: :dunno

目录 1. 问题锁定 2. 更新 Homebrew 3. 切换到新的 Homebrew 源 4. 安装 GPG 5. 检查 macOS 版本兼容性 6. 使用 MacPorts 或其他包管理器 7. 创建密钥&#xff08;生成 GPG 签名&#xff09; 往期推荐 1. 问题锁定 通常是因为你的 Homebrew 版本较旧&#xff0c;或者你…

硬件驱动——51单片机:独立按键、中断、定时器/计数器

目录 一、独立按键 1.原理 2.封装函数 3.按键控制点灯 数码管 二、中断 1.原理 2.步骤 3.中断寄存器IE 4.控制寄存器TCON 5.打开外部中断0和1 三、定时器/计数器 1.原理 2.控制寄存器TCON 3.工作模式寄存器TMOD 4.按键控制频率的动态闪烁 一、独立按键 1…

P1259 黑白棋子的移动【java】【AC代码】

有 2n 个棋子排成一行&#xff0c;开始为位置白子全部在左边&#xff0c;黑子全部在右边&#xff0c;如下图为 n5 的情况&#xff1a; 移动棋子的规则是&#xff1a;每次必须同时移动相邻的两个棋子&#xff0c;颜色不限&#xff0c;可以左移也可以右移到空位上去&#xff0c;但…

67.Harmonyos NEXT 图片预览组件之性能优化策略

温馨提示&#xff1a;本篇博客的详细代码已发布到 git : https://gitcode.com/nutpi/HarmonyosNext 可以下载运行哦&#xff01; Harmonyos NEXT 图片预览组件之性能优化策略 文章目录 Harmonyos NEXT 图片预览组件之性能优化策略效果预览一、性能优化概述1. 性能优化的关键指标…

Windows下安装Git客户端

① 官网地址&#xff1a;https://git-scm.com/。 ② Git的优势 大部分操作在本地完成&#xff0c;不需要联网&#xff1b;完整性保证&#xff1b;尽可能添加数据而不是删除或修改数据&#xff1b;分支操作非常快捷流畅&#xff1b;与Linux 命令全面兼容。 ③ Git的安装 从官网…

SAP IBP for Supply Chain Certification Guide (Parag Bakde, Rishabh Gupta)

SAP IBP for Supply Chain Certification Guide (Parag Bakde, Rishabh Gupta)

如何处理PHP中的日期和时间问题

如何处理PHP中的日期和时间问题 在PHP开发中&#xff0c;日期和时间的处理是一个常见且重要的任务。无论是记录用户操作时间、生成时间戳&#xff0c;还是进行日期计算&#xff0c;PHP提供了丰富的函数和类来帮助开发者高效处理这些需求。本文将详细介绍如何在PHP中处理日期和…

TDengine 使用最佳实践

简介 阅读本文档需要具备的基础知识&#xff1a; Linux系统的基础知识&#xff0c;及基本命令网络基础知识&#xff1a;TCP/UDP、http、RESTful、域名解析、FQDN/hostname、hosts、防火墙、四层/七层负载均衡 本文档的阅读对象有&#xff1a;架构师、研发工程师&#xff0c;…

Spring、Spring Boot、Spring Cloud 的区别与联系

1. Spring 框架 定位&#xff1a;轻量级的企业级应用开发框架&#xff0c;核心是 IoC&#xff08;控制反转&#xff09; 和 AOP&#xff08;面向切面编程&#xff09;。 核心功能&#xff1a; 依赖注入&#xff08;DI&#xff09;&#xff1a;通过 Autowired、Component 等注解…

AutoGen-构建问答智能体

概述 如https://github.com/microsoft/autogen所述&#xff0c;autogen是一多智能体的框架&#xff0c;属于微软旗下的产品。 依靠AutoGen我们可以快速构建出一个多智能体应用&#xff0c;以满足我们各种业务场景。 环境说明 python&#xff0c;3.10AutoGen&#xff0c;0.4.2…

C语言实现括号匹配检查及栈的应用详解

目录 栈数据结构简介 C语言实现栈 栈的初始化 栈的销毁 栈的插入 栈的删除 栈的判空 获取栈顶数据 利用栈实现括号匹配检查 总结 在编程中&#xff0c;经常会遇到需要检查括号是否匹配的问题&#xff0c;比如在编译器中检查代码的语法正确性&#xff0c;或者在…

阿里云魔笔低代码应用开发平台快速搭建教程

AI低代码&#xff0c;大模型时代应用开发新范式 什么是魔笔 介绍什么是魔笔低代码应用开发平台。 魔笔是一款面向全端&#xff08;Web、H5、全平台小程序、App&#xff09;场景的模型驱动低代码开发平台&#xff0c;提供一站式的应用全生命周期管理&#xff0c;包括可视化开发…

A Survey on Mixture of Experts 混合专家模型综述(第二部分:混合专家系统设计)

A Survey on Mixture of Experts 混合专家模型综述 (第一部分&#xff1a;混合专家算法设计) A Survey on Mixture of Experts arxiv github&#xff1a;A-Survey-on-Mixture-of-Experts-in-LLMs ​ ​ ​ 5 System Design of Mixture of Experts While ​Mixture of Exper…

docker python:latest镜像 允许ssh远程

跳转到家目录 cd创建pythonsshdockerfile mkdir pythonsshdockerfile跳转pythonsshdockerfile cd pythonsshdockerfile创建Dockerfile文件 vim Dockerfile将Dockerfile的指令复制到文件中 # 使用 python:latest 作为基础镜像 # 如果我的镜像列表中没有python:latest镜像&…

Aim Robotics电动胶枪:机器人涂胶点胶的高效解决方案

在自动化和智能制造领域&#xff0c;机器人技术的应用越来越广泛&#xff0c;而涂胶和点胶作为生产过程中的重要环节&#xff0c;也逐渐实现了自动化和智能化。Aim Robotics作为一家专注于机器人技术的公司&#xff0c;其推出的电动胶枪为这一领域带来了高效、灵活且易于操作的…

【HDLbits--分支预测器简单实现】

HDLbits--分支预测器简单实现 1 timer2.branche predicitors3.Branch history shift4.Branch direction predictor 以下是分支预测器的简单其实现&#xff1b; 1 timer 实现一个计时器&#xff0c;当load1’b1时&#xff0c;加载data进去&#xff0c;当load1’b0时进行倒计时&…

Linux--操作系统/进程

ok&#xff0c;我们今天学习linux中的操作系统和进程 1. 冯诺依曼体系 我们常⻅的计算机&#xff0c;如笔记本。我们不常⻅的计算机&#xff0c;如服务器&#xff0c;⼤部分都遵守冯诺依曼体系。 内存是CPU和外设之间的一个巨大的缓存&#xff01; 截⾄⽬前&#xff0c;我们…

Java面试八股—Redis篇

一、Redis的使用场景 &#xff08;一&#xff09;缓存 1.Redis使用场景缓存 场景&#xff1a;缓存热点数据&#xff08;如用户信息、商品详情&#xff09;&#xff0c;减少数据库访问压力&#xff0c;提升响应速度。 2.缓存穿透 正常的访问是&#xff1a;根据ID查询文章&…

Web后端开发之Maven

Maven Mven是apache旗下的一个开源项目&#xff0c;用来管理和构建java项目的工具。 通过一小段描述信息来管理项目。 Maven的作用 1.依赖管理&#xff1a;方便快捷的管理项目依赖的资源&#xff08;jar包&#xff09;&#xff0c;避免版本冲突问题 以前用某个jar包需要下载…

there are no enabled repos

我做了两个操作 第一个操作&#xff1a; 1.先在本地电脑&#xff0c;也就是在我们电脑的桌面上下载 https://repo.huaweicloud.com/repository/conf/CentOS-7-reg.repo 2.在CentOS 创建etc文件夹 3在etc文件夹内创建yum.repos.d文件夹 4.将下载好的repo 黏贴到yum.repos.d…