C++之文字修仙小游戏
1 效果
1.1 截图
游戏运行:

存档:

1.2 游玩警告
注意!不要修改装备概率,装备的概率都是凑好的数字。如果想要速升,修改灵石数量
2 代码
2.1 代码大纲
1. 游戏框架与初始化
-
控制台操作:通过
gotoxy()和hide_cursor()控制光标位置与可见性,color()函数设置颜色,实现动态界面。 -
全局变量:管理玩家等级(
Lv)、经验(Exp)、关卡(G)、灵石(SpiritStone)等核心数据,以及装备稀有度概率(如Grey、Green)。 -
初始化函数
init():重置装备数据、加载存档、设置控制台颜色并隐藏光标。
2. 装备系统
-
结构体
equipment:-
属性 稀有度(
rare)、等级(lv)、类型(type)、名称(name)、伤害(damage)、生命值(HP)和威力(power)。 -
动态颜色 (
ecolor()):根据稀有度显示不同颜色(如灰色、绿色),高稀有度装备(如红色、彩虹)使用 HSL 动态渐变。 -
装备生成 (
init()):基于类型和稀有度生成名称(如“玄铁重剑”)、计算属性,稀有度越高加成越大(如彩虹装备伤害+80%)。
-
3. 战斗与关卡
-
战斗循环:玩家与敌人轮流攻击,血量(
HPnow、MHPnow)实时更新,伤害由装备属性累加计算。 -
关卡推进:击败敌人后关卡(
G)递增,敌人血量根据公式MHP = G * G动态增长。 -
装备掉落:击败敌人随机生成新装备,玩家可选择替换或分解,分解获得灵石和经验。
4. 成长与升级
-
角色升级:经验值(
Exp)满后提升等级,解锁更高境界(如筑基期、金丹期)。 -
仙树升级:消耗灵石升级仙树(
TreeLV),调用TreeUP()调整稀有度概率(如减少灰色装备概率,增加橙色概率)。 -
属性计算:玩家总血量(
HP)和伤害(damage)由装备属性累加,功力(power)进行装备战力估算。
5. 存档与颜色处理
-
存档机制:
SaveRecord()和LoadRecord()将装备数据、等级、灵石等保存至文件(equipment.save和Tree.save)。 -
HSL转RGB:
HSLtoRGB()函数实现动态颜色效果(如至宝装备颜色渐变),增强视觉表现。
6. 关键逻辑细节
-
装备生成概率:根据
Grey、Green等全局变量加权随机,高关卡解锁更稀有装备。 -
时间控制:
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 12using 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);}
}
相关文章:
C++之文字修仙小游戏
1 效果 1.1 截图 游戏运行: 存档: 1.2 游玩警告 注意!不要修改装备概率,装备的概率都是凑好的数字。如果想要速升,修改灵石数量 2 代码 2.1 代码大纲 1. 游戏框架与初始化 控制台操作:通过 gotoxy() …...
C++ vector 核心知识:常用操作与示例详解
在C编程中,vector 是标准模板库(STL)中最常用的容器之一。它以其动态数组的特性、高效的尾部操作和便捷的随机访问能力,成为处理动态数据的首选工具。无论是初学者还是经验丰富的开发者,掌握 vector 的使用方法和性能优…...
结构型模式之适配器模式:让不兼容的接口兼容
在软件开发中,经常会遇到这样一种情况:系统的不同部分需要进行交互,但由于接口不兼容,导致无法直接使用。这时,适配器模式(Adapter Pattern)就能派上用场。适配器模式是设计模式中的结构型模式&…...
从零开始探索C++游戏开发:性能、控制与无限可能
一、为何选择C开发游戏? 在虚幻引擎5渲染的次世代画面背后,在《巫师3》的庞大开放世界中,在《毁灭战士》的丝滑60帧战斗里,C始终扮演着核心技术角色。这门诞生于1983年的语言,至今仍占据着游戏引擎开发语言使用率榜首…...
使用mvn archetype命令,构建自定义springboot archetype脚手架创建工程的方法
使用mvn archetype命令,构建自定义springboot archetype脚手架创建工程的方法 文章目录 使用mvn archetype命令,构建自定义springboot archetype脚手架创建工程的方法一、背景二、环境三、archetype插件配置四、基于项目构建脚手架archetype包五、检查模…...
Hutool RedisDS:Java开发中的Redis极简集成与高阶应用
在Java开发中,Redis作为高性能内存数据库,广泛应用于缓存、分布式锁等场景。然而原生的客户端操作涉及连接管理、序列化等繁琐细节。Hutool工具包提供的RedisDS模块,通过高度封装显著简化了这一过程。本文从实战角度解析其核心特性与使用技巧…...
MacOS 15.3.1 安装 GPG 提示Error: unknown or unsupported macOS version: :dunno
目录 1. 问题锁定 2. 更新 Homebrew 3. 切换到新的 Homebrew 源 4. 安装 GPG 5. 检查 macOS 版本兼容性 6. 使用 MacPorts 或其他包管理器 7. 创建密钥(生成 GPG 签名) 往期推荐 1. 问题锁定 通常是因为你的 Homebrew 版本较旧,或者你…...
Sqlmap注入工具简单解释
安装 1. 安装 Python SQLMap 是基于 Python 开发的,所以要先安装 Python 环境。建议安装 Python 3.9 或更高版本,可从 Python 官方网站 下载对应操作系统的安装包,然后按照安装向导完成安装。 2. 获取 SQLMap 可以从 SQLMap 的官方 GitHu…...
硬件驱动——51单片机:独立按键、中断、定时器/计数器
目录 一、独立按键 1.原理 2.封装函数 3.按键控制点灯 数码管 二、中断 1.原理 2.步骤 3.中断寄存器IE 4.控制寄存器TCON 5.打开外部中断0和1 三、定时器/计数器 1.原理 2.控制寄存器TCON 3.工作模式寄存器TMOD 4.按键控制频率的动态闪烁 一、独立按键 1…...
语文-文言文
文章目录 短歌行归园田居梦游天姥吟留别 / 别东鲁诸公 学习文言文,适当个人分析; 短歌行 曹操 对酒当歌,人生几何(主题,人生很短暂); 譬如朝露,去日苦多(比喻,…...
P1259 黑白棋子的移动【java】【AC代码】
有 2n 个棋子排成一行,开始为位置白子全部在左边,黑子全部在右边,如下图为 n5 的情况: 移动棋子的规则是:每次必须同时移动相邻的两个棋子,颜色不限,可以左移也可以右移到空位上去,但…...
【极光 Orbit·STC8AH】04. 深度探索 GPIO 底层逻辑
【极光 OrbitSTC8A&H】04. 深度探索 GPIO 底层逻辑 引言:当代码遇见硬件 上周我看着学生调试的工控产品,他们困惑地盯着自己编写的代码:“老师,这段C语言明明在PC上跑得没问题啊!” ,让我想起自己初学…...
67.Harmonyos NEXT 图片预览组件之性能优化策略
温馨提示:本篇博客的详细代码已发布到 git : https://gitcode.com/nutpi/HarmonyosNext 可以下载运行哦! Harmonyos NEXT 图片预览组件之性能优化策略 文章目录 Harmonyos NEXT 图片预览组件之性能优化策略效果预览一、性能优化概述1. 性能优化的关键指标…...
uni-app+SpringBoot: 前端传参,后端如何接收参数
做项目中的一些小经验,方便后续 (1)前端代码中,请求的 URL 是通过查询参数(?id${articleId})传递的 后端接口: GetMapping("/knowledgeDetail") public Result getKnowledgeByid(R…...
【Vue.js】
一、简介 1、概述 官网GitHub - Vuejs Vue 是一款用于构建用户界面的 JavaScript 框架。它基于标准 HTML、CSS 和 JavaScript 构建,并提供了一套声明式的、组件化的编程模型,帮助你高效地开发用户界面。 Vue.js作为一个渐进式框架,其设计理…...
正则表达式入门及常用的正则表达式
正则表达式(Regular Expression,简称 Regex)是一种强大的文本处理工具,用于匹配、查找和替换字符串中的特定模式。以下是入门指南和常用正则表达式示例: 一、正则表达式入门 1. 基本语法 符号说明示例.匹配任意单个字…...
Windows下安装Git客户端
① 官网地址:https://git-scm.com/。 ② Git的优势 大部分操作在本地完成,不需要联网;完整性保证;尽可能添加数据而不是删除或修改数据;分支操作非常快捷流畅;与Linux 命令全面兼容。 ③ Git的安装 从官网…...
SAP IBP for Supply Chain Certification Guide (Parag Bakde, Rishabh Gupta)
SAP IBP for Supply Chain Certification Guide (Parag Bakde, Rishabh Gupta)...
【计算机网络通信 AMQP】使用 Qt 调用 qamqp 库进行 AMQP 通信
以下是一个使用 Qt 实现 AMQP 通信的代码示例。为了实现这个功能,我们可以使用 qamqp 库,它是一个基于 Qt 的 AMQP 客户端库。首先,你需要将 qamqp 库添加到你的 Qt 项目中,可以通过 qmake 或 CMake 进行配置。 #include <QCo…...
C语言中的指针与数组:概念、关系与应用
指针和数组都是C语言中极其重要的概念,本文将分步骤深入分析指针和数组在C语言中的概念、它们之间的关系以及它们在实际编程中的应用。 一、指针与数组的基本概念详解 1.1 指针详解 指针是一个变量,它存储的是另一个变量的内存地址。理解指针的核心就是“内存地址”,指针…...
如何处理PHP中的日期和时间问题
如何处理PHP中的日期和时间问题 在PHP开发中,日期和时间的处理是一个常见且重要的任务。无论是记录用户操作时间、生成时间戳,还是进行日期计算,PHP提供了丰富的函数和类来帮助开发者高效处理这些需求。本文将详细介绍如何在PHP中处理日期和…...
TDengine 使用最佳实践
简介 阅读本文档需要具备的基础知识: Linux系统的基础知识,及基本命令网络基础知识:TCP/UDP、http、RESTful、域名解析、FQDN/hostname、hosts、防火墙、四层/七层负载均衡 本文档的阅读对象有:架构师、研发工程师,…...
Spring、Spring Boot、Spring Cloud 的区别与联系
1. Spring 框架 定位:轻量级的企业级应用开发框架,核心是 IoC(控制反转) 和 AOP(面向切面编程)。 核心功能: 依赖注入(DI):通过 Autowired、Component 等注解…...
AutoGen-构建问答智能体
概述 如https://github.com/microsoft/autogen所述,autogen是一多智能体的框架,属于微软旗下的产品。 依靠AutoGen我们可以快速构建出一个多智能体应用,以满足我们各种业务场景。 环境说明 python,3.10AutoGen,0.4.2…...
C语言实现括号匹配检查及栈的应用详解
目录 栈数据结构简介 C语言实现栈 栈的初始化 栈的销毁 栈的插入 栈的删除 栈的判空 获取栈顶数据 利用栈实现括号匹配检查 总结 在编程中,经常会遇到需要检查括号是否匹配的问题,比如在编译器中检查代码的语法正确性,或者在…...
C语言中的字符串与数组的关系
在C语言中,字符串和数组之间有着紧密的关系。理解它们的区别和联系对于编写高效且可靠的代码至关重要。在本篇博文中,我们将详细分析字符串和数组在C语言中的概念、它们的关系以及如何在编程中应用它们。 一、字符串与数组的基础知识 1.1 数组概念 在C语言中,数组是一组相…...
阿里云魔笔低代码应用开发平台快速搭建教程
AI低代码,大模型时代应用开发新范式 什么是魔笔 介绍什么是魔笔低代码应用开发平台。 魔笔是一款面向全端(Web、H5、全平台小程序、App)场景的模型驱动低代码开发平台,提供一站式的应用全生命周期管理,包括可视化开发…...
A Survey on Mixture of Experts 混合专家模型综述(第二部分:混合专家系统设计)
A Survey on Mixture of Experts 混合专家模型综述 (第一部分:混合专家算法设计) A Survey on Mixture of Experts arxiv github: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镜像&…...
通过 CSS 的 命名页面(Named Pages) 技术实现作用域隔离,实现 @page 样式仅影响当前组件
以下是实现 page 样式仅影响当前组件的完整解决方案,通过 CSS 的 命名页面(Named Pages) 技术实现作用域隔离: vue <template><div><button v-print"printOptions">打印当前报表</button><…...
