跳到正文

个人记录

CryWorldRPG V1.0.0~V1.1.x

DrearySun约 268 分钟
原文
文章信息与版本

文章信息

收录
2026年7月20日
更新
2026年8月4日
篇幅
约 268 分钟

版本

  1. v1当前

在上课的时候无聊和AI手搓了一个本地小游戏。

windows10 + C++14即可运行

v1.0.0

INFO
C++
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <conio.h>
#include <Windows.h>
#include <algorithm>
#include <fstream>
#include <cstring>
using namespace std;

// ===================== 全局共用常量 =====================
#define ROW_MINE 12
#define COL_MINE 20
#define MINE_CNT 30
#define SNAKE_W 30
#define SNAKE_H 20
#define GAME2048_SIZE 4
#define DARKROOM_SLOT_NUM 3
// 贪吃蛇速度:单位ms,数字越小越快,直接修改此常量调速
const int SNAKE_SPEED = 80;
// 猜数字范围上下限,修改可调整难度
const int GUESS_MIN = 1;
const int GUESS_MAX = 100;
// 存档文件名
const char SNAKE_SAVE_FILE[] = "snake_save.dat";
const char GAME2048_SAVE_FILE[] = "2048_save.dat";
const char DARKROOM_SAVE_PREFIX[] = "darkroom_slot";
const char RPG_SAVE_FILE[] = "rpg_save.dat";
const char RPG_SAVE_PREFIX[] = "rpg_slot";



const int RPG_SLOT_MAX = 5;
//技能品质枚举 白0 绿1 蓝2 紫3
enum SkillQuality{WHITE, GREEN, BLUE, PURPLE};

int dx8[] = {-1,-1,-1,0,0,1,1,1};
int dy8[] = {-1,0,1,-1,1,-1,0,1};

// ===================== 存档读写通用函数 =====================
// 读单个整数存档
int LoadIntSave(const char* filename) {
	ifstream fin(filename, ios::binary);
	if (!fin.is_open()) return 0;
	int val;
	fin.read((char*)&val, sizeof(int));
	fin.close();
	return val;
}
// 写入单个整数存档
void SaveIntFile(const char* filename, int data) {
	ofstream fout(filename, ios::binary);
	fout.write((char*)&data, sizeof(int));
	fout.close();
}
// 检查存档槽是否存在
bool SlotExist(int id) {
	char buf[64];
	sprintf(buf, "%s%d.dat", DARKROOM_SAVE_PREFIX, id);
	ifstream f(buf, ios::binary);
	bool res = f.is_open();
	f.close();
	return res;
}

// ===================== 1. 扫雷模块 =====================
struct MineBlock {
	bool is_mine;
	bool open;
	bool flag;
	int mine_around;
} mine_map[ROW_MINE][COL_MINE];
int mine_state;
int mine_open_cnt;

void MineInit() {
	for (int i = 0; i < ROW_MINE; i++)
		for (int j = 0; j < COL_MINE; j++)
			mine_map[i][j] = {false, false, false, 0};
	srand((unsigned)time(nullptr));
	int cnt = 0;
	while (cnt < MINE_CNT) {
		int r = rand() % ROW_MINE;
		int c = rand() % COL_MINE;
		if (!mine_map[r][c].is_mine) {
			mine_map[r][c].is_mine = true;
			cnt++;
		}
	}
	for (int i = 0; i < ROW_MINE; i++) {
		for (int j = 0; j < COL_MINE; j++) {
			if (mine_map[i][j].is_mine) continue;
			int s = 0;
			for (int d = 0; d < 8; d++) {
				int nr = i + dx8[d], nc = j + dy8[d];
				if (nr >= 0 && nr < ROW_MINE && nc >=0 && nc < COL_MINE && mine_map[nr][nc].is_mine) s++;
			}
			mine_map[i][j].mine_around = s;
		}
	}
	mine_state = 0;
	mine_open_cnt = 0;
}

void MineDraw(int cr, int cc) {
	system("cls");
	cout << "=== 扫雷 W/A/S/D移动 空格翻开 Q插旗 ESC返回菜单 ===\n\n";
	cout << "  ";
	for (int j = 0; j < COL_MINE; j++) cout << setw(2) << j;
	cout << "\n";
	for (int i = 0; i < ROW_MINE; i++) {
		cout << setw(2) << i;
		for (int j = 0; j < COL_MINE; j++) {
			if (i == cr && j == cc) cout << "[";
			else cout << " ";
			if (!mine_map[i][j].open) {
				if (mine_map[i][j].flag) cout << "F";
				else cout << "#";
			} else {
				if (mine_map[i][j].is_mine) cout << "*";
				else if (mine_map[i][j].mine_around == 0) cout << " ";
				else cout << mine_map[i][j].mine_around;
			}
			if (i == cr && j == cc) cout << "]";
			else cout << " ";
		}
		cout << "\n";
	}
	if (mine_state == 1) cout << "\n恭喜!扫雷成功!\n";
	if (mine_state == 2) cout << "\n踩到地雷,游戏结束!\n";
}

void MineDfs(int r, int c) {
	if (r <0 || r >= ROW_MINE || c <0 || c >= COL_MINE) return;
	if (mine_map[r][c].open || mine_map[r][c].flag) return;
	mine_map[r][c].open = true;
	mine_open_cnt++;
	if (mine_map[r][c].mine_around != 0) return;
	for (int d = 0; d <8; d++) MineDfs(r+dx8[d], c+dy8[d]);
}

void MineCheckWin() {
	if (mine_open_cnt == ROW_MINE*COL_MINE - MINE_CNT) mine_state = 1;
}

void MineGame() {
	int cr = 0, cc = 0;
	MineInit();
	while (true) {
		MineDraw(cr, cc);
		if (mine_state != 0) {
			cout << "\n按任意键返回菜单...";
			_getch();
			return;
		}
		char op = _getch();
		if (op == 27) return;
		if (op == 'w' && cr > 0) cr--;
		if (op == 's' && cr < ROW_MINE-1) cr++;
		if (op == 'a' && cc > 0) cc--;
		if (op == 'd' && cc < COL_MINE-1) cc++;
		if (op == ' ') {
			if (mine_map[cr][cc].flag || mine_map[cr][cc].open) continue;
			if (mine_map[cr][cc].is_mine) {
				mine_state = 2;
				continue;
			}
			MineDfs(cr, cc);
			MineCheckWin();
		}
		if (op == 'q') {
			if (!mine_map[cr][cc].open) mine_map[cr][cc].flag = !mine_map[cr][cc].flag;
		}
	}
}

// ===================== 2. 贪吃蛇模块(穿墙、可调速度、最高分存档) =====================
struct Point { int x,y; };
vector<Point> snake;
Point food;
int dir; //0上1右2下3左
int snake_score;
bool snake_over;
int snake_high;

void SnakeInit() {
	snake.clear();
	snake.push_back({SNAKE_W/2, SNAKE_H/2});
	snake.push_back({SNAKE_W/2-1, SNAKE_H/2});
	snake.push_back({SNAKE_W/2-2, SNAKE_H/2});
	dir = 1;
	snake_score = 0;
	snake_over = false;
	snake_high = LoadIntSave(SNAKE_SAVE_FILE);
	srand((unsigned)time(nullptr));
}

void SpawnFood() {
	bool ok;
	do {
		ok = true;
		food.x = rand() % SNAKE_W;
		food.y = rand() % SNAKE_H;
		for (auto p : snake)
			if (p.x == food.x && p.y == food.y) { ok = false; break; }
	} while (!ok);
}

void SnakeDraw() {
	system("cls");
	cout << "=== 贪吃蛇 W/A/S/D控制 ESC返回 当前:" << snake_score << " 历史最高:" << snake_high << " | 穿墙模式 ===\n";
	for (int y = 0; y < SNAKE_H; y++) {
		for (int x = 0; x < SNAKE_W; x++) {
			if (x == food.x && y == food.y) { cout << "●"; continue; }
			bool body = false;
			for (int i = 0; i < snake.size(); i++) {
				if (snake[i].x == x && snake[i].y == y) {
					if (i == 0) cout << "■";
					else cout << "□";
					body = true;
					break;
				}
			}
			if (!body) cout << " ";
		}
		cout << "\n";
	}
	if (snake_over) cout << "\n撞到自身,游戏结束!\n";
}

void SnakeMove() {
	Point head = snake[0];
	if (dir == 0) head.y--;
	if (dir == 1) head.x++;
	if (dir == 2) head.y++;
	if (dir == 3) head.x--;
	// 穿墙逻辑,删除以下四行即可关闭穿墙
	if (head.x < 0) head.x = SNAKE_W - 1;
	if (head.x >= SNAKE_W) head.x = 0;
	if (head.y < 0) head.y = SNAKE_H - 1;
	if (head.y >= SNAKE_H) head.y = 0;
	// 撞自身判定
	for (auto p : snake)
		if (p.x == head.x && p.y == head.y) {
			snake_over = true;
			return;
		}
	snake.insert(snake.begin(), head);
	if (head.x == food.x && head.y == food.y) {
		snake_score += 10;
		SpawnFood();
	} else {
		snake.pop_back();
	}
}

void SnakeGame() {
	SnakeInit();
	SpawnFood();
	while (true) {
		SnakeDraw();
		if (snake_over) {
			if (snake_score > snake_high) {
				snake_high = snake_score;
				SaveIntFile(SNAKE_SAVE_FILE, snake_high);
				cout << "新纪录!已自动保存最高分\n";
			}
			cout << "\n按任意键返回菜单...";
			_getch();
			return;
		}
		if (_kbhit()) {
			char c = _getch();
			if (c == 27) return;
			if (c == 'w' && dir != 2) dir = 0;
			if (c == 'd' && dir != 3) dir = 1;
			if (c == 's' && dir != 0) dir = 2;
			if (c == 'a' && dir != 1) dir = 3;
		}
		SnakeMove();
		Sleep(SNAKE_SPEED);
	}
}

// ===================== 3. 猜数字小游戏 =====================
void GuessGame() {
	system("cls");
	cout << "===== 猜数字游戏 输入-1随时退出 =====\n";
	cout << "系统随机生成 " << GUESS_MIN << "~" << GUESS_MAX << " 之间数字\n";
	int target = rand() % (GUESS_MAX - GUESS_MIN + 1) + GUESS_MIN;
	int input, cnt = 0;
	while (true) {
		cout << "请输入你猜的数字:";
		cin >> input;
		if (input == -1) break;
		cnt++;
		if (input > target) {
			cout << "太大了!\n";
		} else if (input < target) {
			cout << "太小了!\n";
		} else {
			cout << "恭喜猜对!一共猜了" << cnt << "次\n";
			break;
		}
	}
	cout << "按任意键返回菜单...";
	_getch();
}

// ===================== 4. 简易控制台2048 =====================
int board[GAME2048_SIZE][GAME2048_SIZE];
int score_2048, high_2048;
void RandomSpawn2048() {
	vector<pair<int,int>> empty;
	for(int i=0;i<GAME2048_SIZE;i++)
		for(int j=0;j<GAME2048_SIZE;j++)
			if(board[i][j]==0) empty.emplace_back(i,j);
	if(empty.empty()) return;
	auto pos = empty[rand()%empty.size()];
	int x=pos.first,y=pos.second;
	board[x][y] = (rand()%10 == 1) ? 4 : 2;
}
void Init2048() {
	score_2048 = 0;
	memset(board,0,sizeof(board));
	high_2048 = LoadIntSave(GAME2048_SAVE_FILE);
	RandomSpawn2048();
	RandomSpawn2048();
}
void Draw2048() {
	system("cls");
	cout << "===== 2048 W/A/S/D移动 ESC返回 | 当前分数:" << score_2048 << " 历史最高:" << high_2048 << " =====\n";
	for(int i=0;i<GAME2048_SIZE;i++){
		for(int j=0;j<GAME2048_SIZE;j++){
			cout << setw(4) << board[i][j];
		}
		cout << "\n";
	}
}
bool SlideLeft(int line[GAME2048_SIZE]) {
	bool change = false;
	int tmp[GAME2048_SIZE] = {0}, pos=0;
	for(int i=0;i<GAME2048_SIZE;i++)
		if(line[i]!=0) tmp[pos++] = line[i];
	for(int i=0;i<GAME2048_SIZE;i++){
		if(tmp[i]==tmp[i+1]&&tmp[i]!=0){
			tmp[i]*=2;
			score_2048 += tmp[i];
			tmp[i+1]=0;
			change=true;
		}
	}
	pos=0;
	memset(line,0,sizeof(int)*GAME2048_SIZE);
	for(int i=0;i<GAME2048_SIZE;i++)
		if(tmp[i]!=0) line[pos++] = tmp[i];
	return change;
}
void Rotate(int mat[GAME2048_SIZE][GAME2048_SIZE]){
	int tmp[GAME2048_SIZE][GAME2048_SIZE];
	for(int i=0;i<GAME2048_SIZE;i++)
		for(int j=0;j<GAME2048_SIZE;j++)
			tmp[i][j] = mat[GAME2048_SIZE-j-1][i];
	memcpy(mat,tmp,sizeof(tmp));
}
bool Move2048(int op) {
	bool flag = false;
	int rot = 0;
	if(op=='w') rot=3;
	if(op=='s') rot=1;
	if(op=='d') rot=2;
	for(int i=0;i<rot;i++) Rotate(board);
	for(int i=0;i<GAME2048_SIZE;i++)
		if(SlideLeft(board[i])) flag=true;
	for(int i=0;i<(4-rot)%4;i++) Rotate(board);
	if(flag) RandomSpawn2048();
	return flag;
}
void Game2048() {
	Init2048();
	while(true) {
		Draw2048();
		char c = _getch();
		if(c == 27) {
			if(score_2048 > high_2048) SaveIntFile(GAME2048_SAVE_FILE, score_2048);
			return;
		}
		if(c=='w'||c=='a'||c=='s'||c=='d') Move2048(c);
	}
}

// ===================== 5. 小黑屋 A Dark Room 模块(3存档槽) =====================
struct DarkRoomData {
	int wood;
	int fur;
	int meat;
	int villager;
	int trap;
	int fire;
} dr_data;
// 存档二进制读写
void SaveDarkRoom(int slot) {
	char buf[64];
	sprintf(buf, "%s%d.dat", DARKROOM_SAVE_PREFIX, slot);
	ofstream f(buf, ios::binary);
	f.write((char*)&dr_data, sizeof(DarkRoomData));
	f.close();
}
bool LoadDarkRoom(int slot) {
	char buf[64];
	sprintf(buf, "%s%d.dat", DARKROOM_SAVE_PREFIX, slot);
	ifstream f(buf, ios::binary);
	if(!f.is_open()) return false;
	f.read((char*)&dr_data, sizeof(DarkRoomData));
	f.close();
	return true;
}
void DarkRoomNewGame() {
	dr_data.wood = 0;
	dr_data.fur = 0;
	dr_data.meat = 0;
	dr_data.villager = 0;
	dr_data.trap = 0;
	dr_data.fire = 1;
}
void DarkRoomDraw() {
	system("cls");
	cout << "===== A Dark Room 小黑屋 挂机经营 | ESC退出 ====\n";
	cout << "木材:" << dr_data.wood << " 皮毛:" << dr_data.fur << " 肉:" << dr_data.meat << "\n";
	cout << "村民:" << dr_data.villager << " 陷阱:" << dr_data.trap << " 火焰等级:" << dr_data.fire << "\n";
	cout << "\n操作:\n";
	cout << "1. 生火收集木材  2. 建造陷阱  3. 派遣村民狩猎\n";
	cout << "4. 扩建小屋吸引村民\n";
}
void DarkRoomTick() {
	dr_data.wood += dr_data.fire;
	for(int i=1;i<=dr_data.trap;i++) {
		dr_data.fur += 1;
		dr_data.meat += 1;
	}
}
void DarkRoomGame() {
	int use_slot = -1;
	while(true) {
		system("cls");
		cout << "===== 小黑屋存档选择 =====\n";
		cout << "1. 新建存档\n";
		for(int i=1;i<=DARKROOM_SLOT_NUM;i++) {
			if(SlotExist(i)) cout << i+1 << ". 读取存档" << i << "\n";
			else cout << i+1 << ". 存档" << i << "(空)\n";
		}
		cout << "请输入选项:";
		int op;
		cin >> op;
		if(op == 1) {
			DarkRoomNewGame();
			use_slot = -1;
			break;
		} else if(op >=2 && op <= DARKROOM_SLOT_NUM+1) {
			int sid = op - 1;
			if(LoadDarkRoom(sid)) {
				use_slot = sid;
				break;
			} else {
				cout << "该存档为空!按任意键重新选择\n";
				_getch();
			}
		} else {
			cout << "输入错误!\n";
			_getch();
		}
	}
	// 主循环挂机经营
	while(true) {
		DarkRoomDraw();
		char c = _getch();
		if(c == 27) break;
		DarkRoomTick();
		if(c == '1') {
			dr_data.wood += 5;
		} else if(c == '2') {
			if(dr_data.wood >= 10) {
				dr_data.wood -= 10;
				dr_data.trap += 1;
			}
		} else if(c == '3') {
			if(dr_data.villager >= 1) {
				dr_data.meat += 4;
				dr_data.fur += 2;
			}
		} else if(c == '4') {
			if(dr_data.wood >= 30 && dr_data.meat >= 10) {
				dr_data.wood -= 30;
				dr_data.meat -= 10;
				dr_data.villager += 1;
			}
		}
		Sleep(400);
	}
	// 退出存档处理
	int empty_slot = -1;
	for(int i=1;i<=DARKROOM_SLOT_NUM;i++) {
		if(!SlotExist(i)) {
			empty_slot = i;
			break;
		}
	}
	if(empty_slot != -1) {
		SaveDarkRoom(empty_slot);
		cout << "检测到空存档槽,自动保存至存档" << empty_slot << "\n";
	} else {
		while(true) {
			system("cls");
			cout << "三个存档已满,请选择:\n";
			cout << "1. 放弃本次进度不保存\n";
			cout << "2. 覆盖存档1\n";
			cout << "3. 覆盖存档2\n";
			cout << "4. 覆盖存档3\n";
			int sel;
			cin >> sel;
			if(sel == 1) break;
			else if(sel >=2 && sel <=4) {
				SaveDarkRoom(sel-1);
				cout << "已覆盖存档" << sel-1 << "\n";
				break;
			} else {
				cout << "输入错误!\n";
				_getch();
			}
		}
	}
	cout << "按任意键返回主菜单...";
	_getch();
}
// ===================== 6. 原创简易控制台RPG(单存档位 rpg_save.dat) =====================
//15种原创技能ID
enum SkillID{
	SKILL_NONE, //空
	SKILL_POWERUP,SKILL_SHIELD,SKILL_LIFESTEAL,SKILL_SWAPHP,SKILL_BLOODDRAIN,
	SKILL_STUN,SKILL_CRIT,SKILL_POISON,SKILL_REFLECT,SKILL_RUSH,
	SKILL_HEALSELF,SKILL_WEAKEN,SKILL_SILENCE,SKILL_DOUBLEHIT,SKILL_IMMUNE
};
//技能结构体
struct Skill{
	int id;
	int quality;
	Skill() : id(SKILL_NONE), quality(0){}
	Skill(int i,int q):id(i),quality(q){}
};
//存档完整数据结构体
struct RpgSaveData{
	char name[32];//存档自定义名称
	int hp,maxhp,atk,def,gold,stage;
	int skillCnt;
	Skill skills[20];//最多存20个技能
}rpg_data;
//怪物战斗临时数据
struct MonsterTemp{
	int hp,maxhp,atk,def;
	int imprisonTurn;//禁锢剩余回合
}monster;
//玩家战斗临时buff
int buffAtk,buffDef;
//获取存档文件名
void GetRpgFileName(int slot,char buf[64]){
	sprintf(buf,"%s%d.dat",RPG_SAVE_PREFIX,slot);
}
//检查存档是否存在
bool RpgSlotExist(int slot){
	char buf[64];
	GetRpgFileName(slot,buf);
	ifstream fin(buf,ios::binary);
	bool res=fin.is_open();
	fin.close();
	return res;
}
//读取指定槽存档
bool LoadRpg(int slot){
	char buf[64];
	GetRpgFileName(slot,buf);
	ifstream fin(buf,ios::binary);
	if(!fin.is_open()) return false;
	fin.read((char*)&rpg_data,sizeof(RpgSaveData));
	fin.close();
	return true;
}
//写入指定槽存档
void SaveRpg(int slot){
	char buf[64];
	GetRpgFileName(slot,buf);
	ofstream fout(buf,ios::binary);
	fout.write((char*)&rpg_data,sizeof(RpgSaveData));
	fout.close();
}
//新建空白角色
void RpgNewChar(){
	memset(rpg_data.name,0,sizeof(rpg_data.name));
	strcpy(rpg_data.name,"");
	rpg_data.hp=100;
	rpg_data.maxhp=100;
	rpg_data.atk=10;
	rpg_data.def=5;
	rpg_data.gold=0;
	rpg_data.stage=1;
	rpg_data.skillCnt=0;
	memset(rpg_data.skills,0,sizeof(rpg_data.skills));
}
//品质文字转换
string GetQualityStr(int q){
	if(q==WHITE) return "白色";
	if(q==GREEN) return "绿色";
	if(q==BLUE) return "蓝色";
	return "紫色";
}
//技能名称转换
string GetSkillName(int id){
	switch(id){
		case SKILL_NONE:return "空技能";
		case SKILL_POWERUP:return "狂怒增幅";
		case SKILL_SHIELD:return "钢铁壁垒";
		case SKILL_LIFESTEAL:return "吸血打击";
		case SKILL_SWAPHP:return "生命置换";
		case SKILL_BLOODDRAIN:return "鲜血窃取";
		case SKILL_STUN:return "眩晕重击";
		case SKILL_CRIT:return "致命暴击";
		case SKILL_POISON:return "剧毒侵蚀";
		case SKILL_REFLECT:return "伤害反弹";
		case SKILL_RUSH:return "冲锋突袭";
		case SKILL_HEALSELF:return "自愈术";
		case SKILL_WEAKEN:return "衰弱诅咒";
		case SKILL_SILENCE:return "缄默封印";
		case SKILL_DOUBLEHIT:return "二段连击";
		case SKILL_IMMUNE:return "伤害免疫";
		default:return "未知技能";
	}
}
//抽取技能逻辑
void DrawSkill(){
	system("cls");
	cout<<"===== 技能抽取(30金币一次,可能抽空) =====\n";
	cout<<"当前金币:"<<rpg_data.gold<<"\n";
	if(rpg_data.gold<30){
		cout<<"金币不足,无法抽取!按任意键返回\n";
		_getch();
		return;
	}
	rpg_data.gold-=30;
	int randChance=rand()%100;
	Skill getSk;
	if(randChance<20){
		getSk.id=SKILL_NONE;
		cout<<"本次抽取落空!什么都没获得\n";
	}else{
		//随机技能ID
		getSk.id=rand()%14+1;
		//随机品质
		int qr=rand()%100;
		if(qr<50) getSk.quality=WHITE;
		else if(qr<80) getSk.quality=GREEN;
		else if(qr<95) getSk.quality=BLUE;
		else getSk.quality=PURPLE;
		cout<<"抽到【"<<GetQualityStr(getSk.quality)<<"】"<<GetSkillName(getSk.id)<<"\n";
		//遍历已有技能处理覆盖/进阶
		bool haveSame=false;
		for(int i=0;i<rpg_data.skillCnt;i++){
			if(rpg_data.skills[i].id==getSk.id){
				haveSame=true;
				//高品质直接覆盖低品质
				if(getSk.quality>rpg_data.skills[i].quality){
					rpg_data.skills[i].quality=getSk.quality;
					cout<<"高品质覆盖原有低品质!\n";
				}else if(getSk.quality==rpg_data.skills[i].quality){
					//同品质进阶一级,最高紫色
					if(rpg_data.skills[i].quality<PURPLE){
						rpg_data.skills[i].quality++;
						cout<<"同品质进阶,品质提升!\n";
					}else{
						cout<<"已满级紫色,无变化\n";
					}
				}
				break;
			}
		}
		//无同名则新增
		if(!haveSame&&rpg_data.skillCnt<20){
			rpg_data.skills[rpg_data.skillCnt++]=getSk;
			cout<<"已收入技能栏\n";
		}else if(!haveSame){
			cout<<"技能栏已满,无法获取\n";
		}
	}
	cout<<"按任意键返回\n";
	_getch();
}
//商店界面
void RpgShop(){
	system("cls");
	cout<<"===== RPG商店 =====\n";
	cout<<"1. 回满全部血量 消耗30金币\n";
	cout<<"2. 永久攻击+5 消耗50金币\n";
	cout<<"3. 永久防御+3 消耗40金币\n";
	cout<<"4. 抽取随机技能 消耗30金币\n";
	cout<<"请输入选项:";
	int op;
	cin>>op;
	if(op==1){
		if(rpg_data.gold>=30){
			rpg_data.gold-=30;
			rpg_data.hp=rpg_data.maxhp;
			cout<<"已回血至满血\n";
		}else cout<<"金币不足!\n";
	}else if(op==2){
		if(rpg_data.gold>=50){
			rpg_data.gold-=50;
			rpg_data.atk+=5;
			cout<<"攻击永久+5\n";
		}else cout<<"金币不足!\n";
	}else if(op==3){
		if(rpg_data.gold>=40){
			rpg_data.gold-=40;
			rpg_data.def+=3;
			cout<<"防御永久+3\n";
		}else cout<<"金币不足!\n";
	}else if(op==4){
		DrawSkill();
		return;
	}
	cout<<"按任意键返回\n";
	_getch();
}
//绘制角色总面板
void RpgDrawMain(){
	system("cls");
	cout<<"===== 原创回合RPG ESC退出自动存档 =====\n";
	cout<<"存档名称:"<<rpg_data.name<<"\n";
	cout<<"生命:"<<rpg_data.hp<<"/"<<rpg_data.maxhp<<" 攻击:"<<rpg_data.atk<<" 防御:"<<rpg_data.def<<"\n";
	cout<<"金币:"<<rpg_data.gold<<" 当前关卡:"<<rpg_data.stage<<"\n";
	cout<<"持有技能数量:"<<rpg_data.skillCnt<<"\n";
	cout<<"【操作】1开始战斗 2商店 3查看全部技能\n";
}
//展示所有技能
void ShowAllSkill(){
	system("cls");
	cout<<"===== 全部持有技能 =====\n";
	if(rpg_data.skillCnt==0){
		cout<<"暂无任何技能\n";
	}
	for(int i=0;i<rpg_data.skillCnt;i++){
		Skill s=rpg_data.skills[i];
		cout<<i+1<<"."<<GetQualityStr(s.quality)<<" "<<GetSkillName(s.id)<<"\n";
	}
	cout<<"按任意键返回\n";
	_getch();
}
//释放玩家技能战斗效果
void CastSkillEffect(int sid,int q,int &pHP,int &mHP,int mMaxHp){
	int mul=1;
	if(q==GREEN) mul=1.2;
	if(q==BLUE) mul=1.4;
	if(q==PURPLE) mul=1.8;
	int dmg=(rpg_data.atk+buffAtk)*mul;
	switch(sid){
		case SKILL_POWERUP:buffAtk+=10*mul;cout<<"狂怒增幅:临时攻击大幅提升\n";break;
		case SKILL_SHIELD:buffDef+=8*mul;cout<<"钢铁壁垒:临时防御大幅提升\n";break;
		case SKILL_LIFESTEAL:{
			int heal=dmg*0.4;
			mHP-=dmg;
			pHP+=heal;
			cout<<"吸血打击:造成伤害并回复"<<heal<<"血量\n";
			break;
		}
		case SKILL_SWAPHP:{
			int t=pHP;
			pHP=mHP;
			mHP=t;
			cout<<"生命置换:与怪物互换当前血量\n";
			break;
		}
		case SKILL_BLOODDRAIN:{
			int steal=mHP*0.3*mul;
			mHP-=steal;
			pHP+=steal;
			cout<<"鲜血窃取:直接窃取怪物30%当前血量\n";
			break;
		}
		case SKILL_STUN:monster.imprisonTurn+=2;cout<<"眩晕重击:怪物禁锢2回合无法行动\n";mHP-=dmg;break;
		case SKILL_CRIT:mHP-=dmg*2;cout<<"致命暴击:双倍伤害\n";break;
		case SKILL_POISON:mHP-=dmg*0.3;cout<<"剧毒侵蚀:怪物每回合持续掉血\n";break;
		case SKILL_REFLECT:buffDef+=15*mul;cout<<"伤害反弹:大幅防御并反弹伤害\n";break;
		case SKILL_RUSH:mHP-=dmg*1.5;cout<<"冲锋突袭:1.5倍伤害\n";break;
		case SKILL_HEALSELF:{
			int h=rpg_data.maxhp*0.3*mul;
			pHP=min(pHP+h,rpg_data.maxhp);
			cout<<"自愈术:回复30%最大生命值\n";
			break;
		}
		case SKILL_WEAKEN:buffAtk-=5;cout<<"衰弱诅咒:降低怪物输出\n";mHP-=dmg;break;
		case SKILL_DOUBLEHIT:mHP-=dmg;mHP-=dmg*0.5;cout<<"二段连击:两段伤害\n";break;
		case SKILL_IMMUNE:buffDef+=30;cout<<"伤害免疫:本回合大幅减伤\n";break;
		default:mHP-=dmg;cout<<"普通技能攻击\n";
	}
}
//单场回合制战斗
void RpgBattle(){
	//初始化怪物
	monster.maxhp=20+rpg_data.stage*12;
	monster.hp=monster.maxhp;
	monster.atk=4+rpg_data.stage*3;
	monster.def=3+rpg_data.stage*2;
	monster.imprisonTurn=0;
	int playerHp=rpg_data.hp;
	buffAtk=0;buffDef=0;
	bool battleOver=false;
	while(!battleOver){
		system("cls");
		cout<<"===== 第"<<rpg_data.stage<<"关战斗 =====\n";
		cout<<"你的血量:"<<playerHp<<"/"<<rpg_data.maxhp<<" 临时攻+"<<buffAtk<<" 防+"<<buffDef<<"\n";
		cout<<"怪物血量:"<<monster.hp<<"/"<<monster.maxhp;
		if(monster.imprisonTurn>0) cout<<" 禁锢剩余"<<monster.imprisonTurn<<"回合";
		cout<<"\n";
		cout<<"1.普通攻击 2.释放技能 3.逃跑\n";
		char op=_getch();
		if(op=='3'){
			cout<<"逃跑成功,本场无奖励\n";
			Sleep(1200);
			return;
		}
		//玩家行动
		if(op=='1'){
			int dmg=max(1,(rpg_data.atk+buffAtk)-monster.def);
			monster.hp-=dmg;
			cout<<"你普攻造成"<<dmg<<"点伤害\n";
		}else if(op=='2'){
			system("cls");
			cout<<"===== 选择释放技能 =====\n";
			for(int i=0;i<rpg_data.skillCnt;i++){
				Skill s=rpg_data.skills[i];
				cout<<i+1<<"."<<GetQualityStr(s.quality)<<GetSkillName(s.id)<<"\n";
			}
			cout<<"输入数字释放,0返回战斗:";
			int sid;
			cin>>sid;
			if(sid>=1&&sid<=rpg_data.skillCnt){
				Skill sel=rpg_data.skills[sid-1];
				CastSkillEffect(sel.id,sel.quality,playerHp,monster.hp,monster.maxhp);
			}
		}
		Sleep(1000);
		if(monster.hp<=0){
			battleOver=true;
			break;
		}
		//怪物行动 禁锢判定
		if(monster.imprisonTurn>0){
			cout<<"怪物被禁锢,本回合无法行动\n";
			monster.imprisonTurn--;
			Sleep(1200);
			continue;
		}
		//怪物随机技能
		int mr=rand()%100;
		if(mr<25){
			monster.imprisonTurn+=2;
			cout<<"怪物释放禁锢!你接下来两回合无法行动\n";
		}
		int mDmg=max(1,monster.atk-buffDef);
		playerHp-=mDmg;
		cout<<"怪物攻击你,受到"<<mDmg<<"点伤害\n";
		Sleep(1000);
		if(playerHp<=0){
			battleOver=true;
			break;
		}
	}
	//战斗结算停留界面
	system("cls");
	if(playerHp<=0){
		cout<<"你战败倒下,关卡重置,血量回满\n";
		rpg_data.stage=1;
		rpg_data.hp=rpg_data.maxhp;
	}else{
		int reward=15+rpg_data.stage*8;
		rpg_data.gold+=reward;
		rpg_data.stage++;
		cout<<"战斗胜利!获得"<<reward<<"金币,进入下一关\n";
		rpg_data.hp=playerHp;
	}
	cout<<"按任意键继续...";
	_getch();
}
//存档选择入口
void RpgGame(){
	int useSlot=-1;
	while(true){
		system("cls");
		cout<<"===== RPG存档选择(共5个存档位) =====\n";
		cout<<"1.新建空白存档\n";
		for(int i=1;i<=RPG_SLOT_MAX;i++){
			if(RpgSlotExist(i)){
				LoadRpg(i);
				cout<<i+1<<"."<<"存档"<<i<<"【"<<rpg_data.name<<"】\n";
			}else{
				cout<<i+1<<"."<<"存档"<<i<<"(空)\n";
			}
		}
		cout<<"输入选择:";
		int sel;
		cin>>sel;
		if(sel==1){
			RpgNewChar();
			cout<<"请输入自定义存档名称(直接回车默认存档X):";
			cin.get();
			char nm[32];
			cin.getline(nm,30);
			if(strlen(nm)>0) strcpy(rpg_data.name,nm);
			useSlot=-1;
			break;
		}else if(sel>=2&&sel<=RPG_SLOT_MAX+1){
			int sid=sel-1;
			if(LoadRpg(sid)){
				useSlot=sid;
				break;
			}else{
				cout<<"该存档为空,重新选择\n";
				_getch();
			}
		}else{
			cout<<"输入错误\n";
			_getch();
		}
	}
	//主循环
	while(true){
		RpgDrawMain();
		char c=_getch();
		if(c==27){
			//退出存档逻辑
			int emptySlot=-1;
			for(int i=1;i<=RPG_SLOT_MAX;i++){
				if(!RpgSlotExist(i)){
					emptySlot=i;
					break;
				}
			}
			if(emptySlot!=-1){
				SaveRpg(emptySlot);
				cout<<"存在空存档位,自动保存至存档"<<emptySlot<<"\n";
			}else{
				while(true){
					system("cls");
					cout<<"5个存档全部占满,请选择:\n";
					cout<<"1.放弃本次进度不保存\n";
					cout<<"2.覆盖存档1 3.覆盖存档2 4.覆盖存档3 5.覆盖存档4 6.覆盖存档5\n";
					int op;
					cin>>op;
					if(op==1) break;
					else if(op>=2&&op<=6){
						SaveRpg(op-1);
						cout<<"已覆盖存档"<<op-1<<"\n";
						break;
					}else cout<<"输入错误\n";
				}
			}
			cout<<"按任意键返回主菜单\n";
			_getch();
			return;
		}
		if(c=='1') RpgBattle();
		if(c=='2') RpgShop();
		if(c=='3') ShowAllSkill();
	}
}
// ===================== 主菜单 =====================
void ShowMenu() {
	system("cls");
	cout << "========== 多功能小游戏合集(带多存档) ==========\n";
	cout << "1. 扫雷(无存档)\n";
	cout << "2. 穿墙贪吃蛇(自动保存最高分)\n";
	cout << "3. 猜数字(无存档)\n";
	cout << "4. 简易2048(自动保存最高分)\n";
	cout << "5. 小黑屋 A Dark Room(3独立存档槽)\n";
	cout << "6. 原创闯关RPG(5自动存档)\n";
	cout << "===============================================\n";
	cout << "请输入数字选择游戏:";
}
void init();
signed main() {
	srand((unsigned)time(nullptr));
	while (true) {
		ShowMenu();
		int op;
		cin >> op;
		if (op == 1) MineGame();
		else if (op == 2) SnakeGame();
		else if (op == 3) GuessGame();
		else if (op == 4) Game2048();
		else if (op == 5) DarkRoomGame();
		else if (op == 6) RpgGame();
		else {
			cout << "输入错误,按任意键重新选择\n";
			_getch();
		}
	}
	return 0;
}
void init(){
	return ;
}

v1.1.0

更新了新的货币机制,使金币爆率随怪物难度提高。
优化了怪物技能。
增加了技能耗蓝。
增加了怪物的[精英值],精英值由怪物的技能数与品质决定,精英值大于3为精英怪,击败掉落0 ~ 2宝石,大于5为领主,击败掉落1 ~ 3宝石,大于10为BOSS,击败掉落 55 ~ min(5,精英值/3)min(5,精英值/3)宝石。
更新商店。

INFO
C++
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <conio.h>
#include <Windows.h>
#include <algorithm>
#include <fstream>
#include <cstring>
using namespace std;
		
// ===================== 全局共用常量 =====================
#define ROW_MINE 12
#define COL_MINE 20
#define MINE_CNT 30
#define SNAKE_W 30
#define SNAKE_H 20
#define GAME2048_SIZE 4
#define DARKROOM_SLOT_NUM 3
const int SNAKE_SPEED = 80;
const int GUESS_MIN = 1;
const int GUESS_MAX = 100;
		
const char SNAKE_SAVE_FILE[] = "snake_save.dat";
const char GAME2048_SAVE_FILE[] = "2048_save.dat";
const char DARKROOM_SAVE_PREFIX[] = "darkroom_slot";
const char RPG_SAVE_PREFIX[] = "rpg_slot";
		
const int RPG_SLOT_MAX = 5;
const int SKILL_PAGE_CNT = 8;
enum SkillQuality { WHITE, GREEN, BLUE, PURPLE };
enum SkillID {
	SKILL_NONE,
	SKILL_POWERUP, SKILL_SHIELD, SKILL_LIFESTEAL, SKILL_SWAPHP, SKILL_BLOODDRAIN,
	SKILL_STUN, SKILL_CRIT, SKILL_POISON, SKILL_REFLECT, SKILL_RUSH,
	SKILL_HEALSELF, SKILL_WEAKEN, SKILL_SILENCE, SKILL_DOUBLEHIT, SKILL_IMMUNE
};
enum MonsterSkillID {
	MSKILL_NONE, MSKILL_IMPRISON_PLAYER, MSKILL_POISON, MSKILL_WEAK, MSKILL_DOUBLE_ATK
};
		
int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};
		
// ===================== 通用存档工具 =====================
int LoadIntSave(const char* filename) {
	ifstream fin(filename, ios::binary);
	if (!fin.is_open()) return 0;
	int val;
	fin.read((char*)&val, sizeof(int));
	fin.close();
	return val;
}
void SaveIntFile(const char* filename, int data) {
	ofstream fout(filename, ios::binary);
	fout.write((char*)&data, sizeof(int));
	fout.close();
}
bool SlotExist(int id) {
	char buf[64];
	sprintf(buf, "%s%d.dat", DARKROOM_SAVE_PREFIX, id);
	ifstream f(buf, ios::binary);
	bool res = f.is_open();
	f.close();
	return res;
}
		
// ===================== 1. 扫雷 =====================
struct MineBlock {
	bool is_mine;
	bool open;
	bool flag;
	int mine_around;
} mine_map[ROW_MINE][COL_MINE];
int mine_state;
int mine_open_cnt;
		
void MineInit() {
	memset(mine_map, 0, sizeof(mine_map));
	srand((unsigned)time(nullptr));
	int cnt = 0;
	while (cnt < MINE_CNT) {
		int r = rand() % ROW_MINE;
		int c = rand() % COL_MINE;
		if (!mine_map[r][c].is_mine) {
			mine_map[r][c].is_mine = true;
			cnt++;
		}
	}
	for (int i = 0; i < ROW_MINE; i++) {
		for (int j = 0; j < COL_MINE; j++) {
			if (mine_map[i][j].is_mine) continue;
			int s = 0;
			for (int d = 0; d < 8; d++) {
				int nr = i + dx8[d], nc = j + dy8[d];
				if (nr >= 0 && nr < ROW_MINE && nc >= 0 && nc < COL_MINE && mine_map[nr][nc].is_mine) s++;
			}
			mine_map[i][j].mine_around = s;
		}
	}
	mine_state = 0;
	mine_open_cnt = 0;
}
void MineDraw(int cr, int cc) {
	system("cls");
	cout << "=== 扫雷 W/A/S/D移动 空格翻开 Q插旗 ESC返回菜单 ===\n\n";
	cout << "  ";
	for (int j = 0; j < COL_MINE; j++) cout << setw(2) << j;
	cout << "\n";
	for (int i = 0; i < ROW_MINE; i++) {
		cout << setw(2) << i;
		for (int j = 0; j < COL_MINE; j++) {
			if (i == cr && j == cc) cout << "[";
			else cout << " ";
			if (!mine_map[i][j].open) {
				if (mine_map[i][j].flag) cout << "F";
				else cout << "#";
			} else {
				if (mine_map[i][j].is_mine) cout << "*";
				else if (mine_map[i][j].mine_around == 0) cout << " ";
				else cout << mine_map[i][j].mine_around;
			}
			if (i == cr && j == cc) cout << "]";
			else cout << " ";
		}
		cout << "\n";
	}
	if (mine_state == 1) cout << "\n恭喜!扫雷成功!\n";
	if (mine_state == 2) cout << "\n踩到地雷,游戏结束!\n";
}
void MineDfs(int r, int c) {
	if (r < 0 || r >= ROW_MINE || c < 0 || c >= COL_MINE) return;
	if (mine_map[r][c].open || mine_map[r][c].flag) return;
	mine_map[r][c].open = true;
	mine_open_cnt++;
	if (mine_map[r][c].mine_around != 0) return;
	for (int d = 0; d < 8; d++) MineDfs(r + dx8[d], c + dy8[d]);
}
void MineCheckWin() {
	if (mine_open_cnt == ROW_MINE * COL_MINE - MINE_CNT) mine_state = 1;
}
void MineGame() {
	int cr = 0, cc = 0;
	MineInit();
	while (true) {
		MineDraw(cr, cc);
		if (mine_state != 0) {
			cout << "\n按任意键返回菜单...";
			_getch();
			return;
		}
		char op = _getch();
		if (op == 27) return;
		if (op == 'w' && cr > 0) cr--;
		if (op == 's' && cr < ROW_MINE - 1) cr++;
		if (op == 'a' && cc > 0) cc--;
		if (op == 'd' && cc < COL_MINE - 1) cc++;
		if (op == ' ') {
			if (mine_map[cr][cc].flag || mine_map[cr][cc].open) continue;
			if (mine_map[cr][cc].is_mine) {
				mine_state = 2;
				continue;
			}
			MineDfs(cr, cc);
			MineCheckWin();
		}
		if (op == 'q') {
			if (!mine_map[cr][cc].open) mine_map[cr][cc].flag = !mine_map[cr][cc].flag;
		}
	}
}
		
// ===================== 2. 贪吃蛇 =====================
struct Point { int x, y; };
vector<Point> snake;
Point food;
int dir;
int snake_score;
bool snake_over;
int snake_high;
void SnakeInit() {
	snake.clear();
	snake.push_back({SNAKE_W / 2, SNAKE_H / 2});
	snake.push_back({SNAKE_W / 2 - 1, SNAKE_H / 2});
	snake.push_back({SNAKE_W / 2 - 2, SNAKE_H / 2});
	dir = 1;
	snake_score = 0;
	snake_over = false;
	snake_high = LoadIntSave(SNAKE_SAVE_FILE);
}
void SpawnFood() {
	bool ok;
	do {
		ok = true;
		food.x = rand() % SNAKE_W;
		food.y = rand() % SNAKE_H;
		for (auto p : snake)
			if (p.x == food.x && p.y == food.y) { ok = false; break; }
	} while (!ok);
}
void SnakeDraw() {
	system("cls");
	cout << "=== 贪吃蛇 W/A/S/D控制 ESC返回 当前:" << snake_score << " 历史最高:" << snake_high << " | 穿墙模式 ===\n";
	for (int y = 0; y < SNAKE_H; y++) {
		for (int x = 0; x < SNAKE_W; x++) {
			if (x == food.x && y == food.y) { cout << "●"; continue; }
			bool body = false;
			for (int i = 0; i < snake.size(); i++) {
				if (snake[i].x == x && snake[i].y == y) {
					cout << (i == 0 ? "■" : "□");
					body = true;
					break;
				}
			}
			if (!body) cout << " ";
		}
		cout << "\n";
	}
	if (snake_over) cout << "\n撞到自身,游戏结束!\n";
}
void SnakeMove() {
	Point head = snake[0];
	if (dir == 0) head.y--;
	if (dir == 1) head.x++;
	if (dir == 2) head.y++;
	if (dir == 3) head.x--;
	if (head.x < 0) head.x = SNAKE_W - 1;
	if (head.x >= SNAKE_W) head.x = 0;
	if (head.y < 0) head.y = SNAKE_H - 1;
	if (head.y >= SNAKE_H) head.y = 0;
	for (auto p : snake)
		if (p.x == head.x && p.y == head.y) {
			snake_over = true;
			return;
		}
	snake.insert(snake.begin(), head);
	if (head.x == food.x && head.y == food.y) SpawnFood();
	else snake.pop_back();
}
void SnakeGame() {
	SnakeInit();
	SpawnFood();
	while (true) {
		SnakeDraw();
		if (snake_over) {
			if (snake_score > snake_high) {
				snake_high = snake_score;
				SaveIntFile(SNAKE_SAVE_FILE, snake_high);
				cout << "新纪录!已自动保存最高分\n";
			}
			cout << "\n按任意键返回菜单...";
			_getch();
			return;
		}
		if (_kbhit()) {
			char c = _getch();
			if (c == 27) return;
			if (c == 'w' && dir != 2) dir = 0;
			if (c == 'd' && dir != 3) dir = 1;
			if (c == 's' && dir != 0) dir = 2;
			if (c == 'a' && dir != 1) dir = 3;
		}
		SnakeMove();
		Sleep(SNAKE_SPEED);
	}
}
		
// ===================== 3. 猜数字 =====================
void GuessGame() {
	system("cls");
	cout << "===== 猜数字游戏 输入-1随时退出 =====\n";
	cout << "随机生成 " << GUESS_MIN << "~" << GUESS_MAX << " 数字\n";
	int target = rand() % (GUESS_MAX - GUESS_MIN + 1) + GUESS_MIN;
	int input, cnt = 0;
	while (true) {
		cout << "请输入数字:";
		cin >> input;
		if (input == -1) break;
		cnt++;
		if (input > target) cout << "太大了!\n";
		else if (input < target) cout << "太小了!\n";
		else {
			cout << "猜对!共猜" << cnt << "次\n";
			break;
		}
	}
	cout << "按任意键返回菜单...";
	_getch();
}
		
// ===================== 4. 2048 =====================
int board[GAME2048_SIZE][GAME2048_SIZE];
int score_2048, high_2048;
void RandomSpawn2048() {
	vector<pair<int, int>> empty;
	for (int i = 0; i < GAME2048_SIZE; i++)
		for (int j = 0; j < GAME2048_SIZE; j++)
			if (board[i][j] == 0) empty.emplace_back(i, j);
	if (empty.empty()) return;
	auto pos = empty[rand() % empty.size()];
	board[pos.first][pos.second] = (rand() % 10 == 1) ? 4 : 2;
}
void Init2048() {
	score_2048 = 0;
	memset(board, 0, sizeof(board));
	high_2048 = LoadIntSave(GAME2048_SAVE_FILE);
	RandomSpawn2048();
	RandomSpawn2048();
}
void Draw2048() {
	system("cls");
	cout << "===== 2048 W/A/S/D ESC退出 当前:" << score_2048 << " 最高:" << high_2048 << " =====\n";
	for (int i = 0; i < GAME2048_SIZE; i++) {
		for (int j = 0; j < GAME2048_SIZE; j++) cout << setw(4) << board[i][j];
		cout << "\n";
	}
}
bool SlideLeft(int line[GAME2048_SIZE]) {
	bool change = false;
	int tmp[GAME2048_SIZE] = {0}, pos = 0;
	for (int i = 0; i < GAME2048_SIZE; i++) if (line[i]) tmp[pos++] = line[i];
	for (int i = 0; i < GAME2048_SIZE - 1; i++) {
		if (tmp[i] == tmp[i + 1] && tmp[i]) {
			tmp[i] *= 2;
			score_2048 += tmp[i];
			tmp[i + 1] = 0;
			change = true;
		}
	}
	pos = 0;
	memset(line, 0, sizeof(int) * GAME2048_SIZE);
	for (int i = 0; i < GAME2048_SIZE; i++) if (tmp[i]) line[pos++] = tmp[i];
	return change;
}
void Rotate(int mat[GAME2048_SIZE][GAME2048_SIZE]) {
	int tmp[GAME2048_SIZE][GAME2048_SIZE];
	for (int i = 0; i < GAME2048_SIZE; i++)
		for (int j = 0; j < GAME2048_SIZE; j++)
			tmp[i][j] = mat[GAME2048_SIZE - j - 1][i];
	memcpy(mat, tmp, sizeof(tmp));
}
bool Move2048(char op) {
	bool flag = false;
	int rot = 0;
	if (op == 'w') rot = 3;
	if (op == 's') rot = 1;
	if (op == 'd') rot = 2;
	for (int i = 0; i < rot; i++) Rotate(board);
	for (int i = 0; i < GAME2048_SIZE; i++) if (SlideLeft(board[i])) flag = true;
	for (int i = 0; i < (4 - rot) % 4; i++) Rotate(board);
	if (flag) RandomSpawn2048();
	return flag;
}
void Game2048() {
	Init2048();
	while (true) {
		Draw2048();
		char c = _getch();
		if (c == 27) {
			if (score_2048 > high_2048) SaveIntFile(GAME2048_SAVE_FILE, score_2048);
			return;
		}
		if (c == 'w' || c == 'a' || c == 's' || c == 'd') Move2048(c);
	}
}
		
// ===================== 5. 小黑屋 =====================
struct DarkRoomData {
	int wood, fur, meat, villager, trap, fire;
} dr_data;
void SaveDarkRoom(int slot) {
	char buf[64];
	sprintf(buf, "%s%d.dat", DARKROOM_SAVE_PREFIX, slot);
	ofstream f(buf, ios::binary);
	f.write((char*)&dr_data, sizeof(DarkRoomData));
	f.close();
}
bool LoadDarkRoom(int slot) {
	char buf[64];
	sprintf(buf, "%s%d.dat", DARKROOM_SAVE_PREFIX, slot);
	ifstream f(buf, ios::binary);
	if (!f.is_open()) return false;
	f.read((char*)&dr_data, sizeof(DarkRoomData));
	f.close();
	return true;
}
void DarkRoomNewGame() {
	dr_data.wood = dr_data.fur = dr_data.meat = dr_data.villager = dr_data.trap = 0;
	dr_data.fire = 1;
}
void DarkRoomDraw() {
	system("cls");
	cout << "===== A Dark Room 小黑屋 ESC退出 ====\n";
	cout << "木材:" << dr_data.wood << " 皮毛:" << dr_data.fur << " 肉:" << dr_data.meat << "\n";
	cout << "村民:" << dr_data.villager << " 陷阱:" << dr_data.trap << " 火焰:" << dr_data.fire << "\n";
	cout << "1收集木 2造陷阱 3狩猎 4扩建小屋\n";
}
void DarkRoomTick() {
	dr_data.wood += dr_data.fire;
	for (int i = 1; i <= dr_data.trap; i++) dr_data.fur++, dr_data.meat++;
}
void DarkRoomGame() {
	int use_slot = -1;
	while (true) {
		system("cls");
		cout << "===== 小黑屋存档选择 =====\n1新建\n";
		for (int i = 1; i <= DARKROOM_SLOT_NUM; i++)
			cout << i + 1 << "." << (SlotExist(i) ? "读取存档" : "空存档") << i << "\n";
		cout << "输入:";
		int op; cin >> op;
		if (op == 1) { DarkRoomNewGame(); break; }
		else if (op >= 2 && op <= DARKROOM_SLOT_NUM + 1) {
			int sid = op - 1;
			if (LoadDarkRoom(sid)) { use_slot = sid; break; }
			cout << "空存档,重选\n"; _getch();
		} else { cout << "错误\n"; _getch(); }
	}
	while (true) {
		DarkRoomDraw();
		char c = _getch();
		if (c == 27) break;
		DarkRoomTick();
		if (c == '1') dr_data.wood += 5;
		if (c == '2' && dr_data.wood >= 10) { dr_data.wood -= 10; dr_data.trap++; }
		if (c == '3' && dr_data.villager) { dr_data.meat += 4; dr_data.fur += 2; }
		if (c == '4' && dr_data.wood >= 30 && dr_data.meat >= 10) {
			dr_data.wood -= 30; dr_data.meat -= 10; dr_data.villager++;
		}
		Sleep(400);
	}
	int empty_slot = -1;
	for (int i = 1; i <= DARKROOM_SLOT_NUM; i++) if (!SlotExist(i)) { empty_slot = i; break; }
	if (empty_slot != -1) SaveDarkRoom(empty_slot);
	else {
		while (true) {
			system("cls");
			cout << "存档已满 1放弃 2-4覆盖1-3\n";
			int sel; cin >> sel;
			if (sel == 1) break;
			if (sel >= 2 && sel <= 4) { SaveDarkRoom(sel - 1); break; }
		}
	}
	cout << "按任意键返回菜单..."; _getch();
}
		
// ===================== 6. RPG v1.1.0(兼容v1.0) =====================
struct Skill {
	int id, quality;
	Skill() : id(SKILL_NONE), quality(WHITE) {}
	Skill(int i, int q) : id(i), quality(q) {}
};
struct RpgSaveData {
	char name[32];
	int hp, maxhp, atk, def, gold, stage;
	int skillCnt;
	Skill skills[20];
	int mp, maxMp, gem;
	int godSkillId;
} rpg_data;
struct MonsterSkill { int id, quality; MonsterSkill() : id(MSKILL_NONE), quality(WHITE) {} };
struct MonsterTemp {
	int hp, maxhp, atk, def;
	int playerImprisonTurn;
	vector<MonsterSkill> ms;
	int eliteVal;
} monster;
int buffAtk, buffDef, poisonDmg;
int SkillMpBase[16] = {0,8,7,10,12,11,13,9,6,14,10,12,7,11,15,16};
		
void GetRpgFileName(int slot, char buf[64]) { sprintf(buf, "%s%d.dat", RPG_SAVE_PREFIX, slot); }
bool RpgSlotExist(int slot) {
	char buf[64]; GetRpgFileName(slot, buf);
	ifstream f(buf, ios::binary); bool res = f.is_open(); f.close(); return res;
}
bool LoadRpg(int slot) {
	char buf[64]; GetRpgFileName(slot, buf);
	ifstream fin(buf, ios::binary);
	if (!fin.is_open()) return false;
	memset(&rpg_data, 0, sizeof(rpg_data));
	fin.read((char*)&rpg_data.name, 32);
	fin.read((char*)&rpg_data.hp, sizeof(int) * 7);
	fin.read((char*)&rpg_data.skills, sizeof(Skill) * 20);
	fin.close();
	if (rpg_data.maxMp == 0) rpg_data.maxMp = 50;
	rpg_data.mp = rpg_data.maxMp;
	return true;
}
void SaveRpg(int slot) {
	char buf[64]; GetRpgFileName(slot, buf);
	ofstream f(buf, ios::binary); f.write((char*)&rpg_data, sizeof(rpg_data)); f.close();
}
void RpgNewChar() {
	memset(rpg_data.name, 0, 32);
	rpg_data.hp = rpg_data.maxhp = 100;
	rpg_data.atk = 10; rpg_data.def = 5;
	rpg_data.gold = rpg_data.gem = rpg_data.stage = rpg_data.skillCnt = rpg_data.godSkillId = 0;
	memset(rpg_data.skills, 0, sizeof(rpg_data.skills));
	rpg_data.maxMp = rpg_data.mp = 50;
}
string GetQualityStr(int q) {
	if(q==WHITE)return"白色";if(q==GREEN)return"绿色";if(q==BLUE)return"蓝色";return"紫色";
}
string GetSkillName(int id) {
	switch(id){
		case SKILL_POWERUP:return"狂怒增幅";case SKILL_SHIELD:return"钢铁壁垒";
		case SKILL_LIFESTEAL:return"吸血打击";case SKILL_SWAPHP:return"生命置换";
		case SKILL_BLOODDRAIN:return"鲜血窃取";case SKILL_STUN:return"眩晕重击";
		case SKILL_CRIT:return"致命暴击";case SKILL_POISON:return"剧毒侵蚀";
		case SKILL_REFLECT:return"伤害反弹";case SKILL_RUSH:return"冲锋突袭";
		case SKILL_HEALSELF:return"自愈术";case SKILL_WEAKEN:return"衰弱诅咒";
		case SKILL_SILENCE:return"缄默封印";case SKILL_DOUBLEHIT:return"二段连击";
		case SKILL_IMMUNE:return"伤害免疫";default:return"未知";
	}
}
string GetMonsterSkillName(int id) {
	switch(id){
		case MSKILL_IMPRISON_PLAYER:return"禁锢(锁玩家2回合)";
		case MSKILL_POISON:return"毒伤";case MSKILL_WEAK:return"削弱攻防";
		case MSKILL_DOUBLE_ATK:return"双倍普攻";default:return"无";
	}
}
int GetSkillMpCost(Skill s) {
	int base = SkillMpBase[s.id];
	return max(2, base - s.quality);
}
void DrawSkill() {
	system("cls");
	cout << "抽技能 30金币/次,可能落空 金币:" << rpg_data.gold << "\n";
	if (rpg_data.gold < 30) { cout << "不足,任意键返回\n"; _getch(); return; }
	rpg_data.gold -= 30;
	Skill sk;
	if (rand() % 100 < 20) { cout << "抽空!\n"; }
	else {
		sk.id = rand() % 14 + 1;
		int r = rand() % 100;
		if(r<50)sk.quality=WHITE;else if(r<80)sk.quality=GREEN;else if(r<95)sk.quality=BLUE;else sk.quality=PURPLE;
		cout << "抽到【" << GetQualityStr(sk.quality) << "】" << GetSkillName(sk.id) << "\n";
		bool same = false;
		for (int i = 0; i < rpg_data.skillCnt; i++) {
			if (rpg_data.skills[i].id == sk.id) {
				same = true;
				if (sk.quality > rpg_data.skills[i].quality) {
					rpg_data.skills[i].quality = sk.quality;
					cout << "高品质覆盖\n";
				} else if (sk.quality == rpg_data.skills[i].quality && sk.quality < PURPLE) {
					rpg_data.skills[i].quality++;
					cout << "同品质进阶\n";
				} break;
			}
		}
		if (!same && rpg_data.skillCnt < 20) rpg_data.skills[rpg_data.skillCnt++] = sk;
		else if (!same) cout << "技能栏已满\n";
	}
	cout << "任意键返回\n"; _getch();
}
void ShowAllSkill() {
	int page = 0;
	while (true) {
		system("cls");
		cout << "技能列表 A上 D下 0退出 每页" << SKILL_PAGE_CNT << "\n";
		int st = page * SKILL_PAGE_CNT, ed = min(st + SKILL_PAGE_CNT, rpg_data.skillCnt);
		for (int i = st; i < ed; i++) {
			Skill s = rpg_data.skills[i];
			cout << i + 1 << "." << GetQualityStr(s.quality) << GetSkillName(s.id) << " 蓝耗:" << GetSkillMpCost(s) << "\n";
		}
		cout << "页" << page + 1 << " 按键:";
		char c = _getch();
		if (c == '0') break;
		if (c == 'a' && page > 0) page--;
		if (c == 'd' && ed < rpg_data.skillCnt) page++;
	}
}
int RefreshGemShopItem() { return rand() % 3; }
void RpgShop() {
	system("cls");
	int gemItem = RefreshGemShopItem();
	cout << "===== RPG商店 宝石:" << rpg_data.gem << " =====\n";
	cout << "[金币]\n1回满血30金 2攻+5(50) 3防+3(40) 4抽技能(30) 5蓝上限+20(80)\n";
	cout << "[宝石限购]\n";
	if(gemItem==0)cout<<"6最大蓝+50 消耗3宝石\n";
	else if(gemItem==1)cout<<"6随机神技 消耗5宝石\n";
	else cout<<"6全部技能品质+1 消耗4宝石\n";
	cout << "输入编号购买,0退出:";
	int op; cin >> op;
	if(op==1&&rpg_data.gold>=30){rpg_data.gold-=30;rpg_data.hp=rpg_data.maxhp;cout<<"满血\n";}
	else if(op==2&&rpg_data.gold>=50){rpg_data.gold-=50;rpg_data.atk+=5;cout<<"攻击+5\n";}
	else if(op==3&&rpg_data.gold>=40){rpg_data.gold-=40;rpg_data.def+=3;cout<<"防御+3\n";}
	else if(op==4){DrawSkill();return;}
	else if(op==5&&rpg_data.gold>=80){rpg_data.gold-=80;rpg_data.maxMp+=20;rpg_data.mp=rpg_data.maxMp;cout<<"蓝上限+20\n";}
	else if(op==6){
		if(gemItem==0&&rpg_data.gem>=3){rpg_data.gem-=3;rpg_data.maxMp+=50;cout<<"蓝上限+50\n";}
		else if(gemItem==1&&rpg_data.gem>=5){rpg_data.gem-=5;rpg_data.godSkillId=rand()%14+1;cout<<"获得神技:"<<GetSkillName(rpg_data.godSkillId)<<"\n";}
		else if(gemItem==2&&rpg_data.gem>=4){
			rpg_data.gem-=4;
			for(int i=0;i<rpg_data.skillCnt;i++)if(rpg_data.skills[i].quality<PURPLE)rpg_data.skills[i].quality++;
			cout<<"全技能升品质\n";
		}else cout<<"宝石不足\n";
	}else if(op!=0)cout<<"金币不足\n";
	cout << "任意键返回\n"; _getch();
}
void RpgDrawMain() {
	system("cls");
	cout << "RPG v1.1 ESC保存退出 存档名:" << rpg_data.name << "\n";
	cout << "HP:" << rpg_data.hp << "/" << rpg_data.maxhp << " MP:" << rpg_data.mp << "/" << rpg_data.maxMp << "\n";
	cout << "ATK:" << rpg_data.atk << " DEF:" << rpg_data.def << " GEM:" << rpg_data.gem << "\n";
	cout << "GOLD:" << rpg_data.gold << " STAGE:" << rpg_data.stage << " 技能数:" << rpg_data.skillCnt;
	if(rpg_data.godSkillId)cout<<" 神技:"<<GetSkillName(rpg_data.godSkillId);
	cout << "\n1战斗 2商店 3查看技能\n";
}
void CastSkillEffect(int sid, int q, int &pHP, int &mHP, int mMaxHp) {
	double mul = 1;
	if(q==GREEN)mul=1.2;if(q==BLUE)mul=1.4;if(q==PURPLE)mul=1.8;
	int dmg = (rpg_data.atk + buffAtk) * mul;
	switch(sid){
		case SKILL_POWERUP:buffAtk+=10*mul;cout<<"狂怒增幅 临时攻击提升\n";break;
		case SKILL_SHIELD:buffDef+=8*mul;cout<<"钢铁壁垒 临时防御提升\n";break;
		case SKILL_LIFESTEAL:{int h=dmg*0.4;mHP-=dmg;pHP+=h;cout<<"吸血打击 回"<<h<<"血\n";break;}
		case SKILL_SWAPHP:{int t=pHP;pHP=mHP;mHP=t;cout<<"生命置换 互换血量\n";break;}
		case SKILL_BLOODDRAIN:{int steal=mHP*0.3*mul;mHP-=steal;pHP+=steal;cout<<"窃取30%怪物血量\n";break;}
		case SKILL_STUN:monster.playerImprisonTurn+=2;mHP-=dmg;cout<<"眩晕 怪物禁锢2回合\n";break;
		case SKILL_CRIT:mHP-=dmg*2;cout<<"暴击双倍伤害\n";break;
		case SKILL_POISON:poisonDmg+=dmg*0.3;mHP-=dmg;cout<<"附加持续毒伤\n";break;
		case SKILL_REFLECT:{int ref=dmg*0.6;buffDef+=15*mul;mHP-=ref;cout<<"反弹"<<ref<<"伤害,防御提升\n";break;}
		case SKILL_RUSH:mHP-=dmg*1.5;cout<<"冲锋1.5倍伤\n";break;
		case SKILL_HEALSELF:{int h=rpg_data.maxhp*0.3*mul;pHP=min(pHP+h,rpg_data.maxhp);cout<<"自愈回复\n";break;}
		case SKILL_WEAKEN:monster.atk-=3;mHP-=dmg;cout<<"削弱怪物攻击\n";break;
		case SKILL_DOUBLEHIT:mHP-=dmg;mHP-=dmg*0.5;cout<<"二段连击\n";break;
		case SKILL_IMMUNE:buffDef+=30;cout<<"高额减伤\n";break;
		default:mHP-=dmg;
	}
}
void SpawnMonster() {
	monster.ms.clear();
	monster.playerImprisonTurn = poisonDmg = 0;
	monster.maxhp = 20 + rpg_data.stage * 12;
	monster.hp = monster.maxhp;
	monster.atk = 4 + rpg_data.stage * 3;
	monster.def = 3 + rpg_data.stage * 2;
	int skCnt = rand() % 4;
	monster.eliteVal = 0;
	for(int i=0;i<skCnt;i++){
		MonsterSkill s;
		s.id = rand() % 4 + 1;
		int r = rand() % 100;
		if(r<60){s.quality=WHITE;monster.eliteVal+=1;}
		else if(r<85){s.quality=GREEN;monster.eliteVal+=2;}
		else if(r<97){s.quality=BLUE;monster.eliteVal+=3;}
		else{s.quality=PURPLE;monster.eliteVal+=5;}
		monster.ms.push_back(s);
	}
}
void RpgBattle() {
	SpawnMonster();
	int playerHp = rpg_data.hp;
	buffAtk = buffDef = 0;
	bool over = false;
	while (!over) {
		system("cls");
		cout << "第" << rpg_data.stage << "关战斗\n";
		cout << "你 HP:" << playerHp << "/" << rpg_data.maxhp << " MP:" << rpg_data.mp << "/" << rpg_data.maxMp << "\n";
		cout << "临时攻+" << buffAtk << " 防+" << buffDef << "\n";
		cout << "怪物 HP:" << monster.hp << "/" << monster.maxhp;
		if(monster.playerImprisonTurn>0)cout<<" 你禁锢"<<monster.playerImprisonTurn<<"回合";
		cout << "\n精英值:" << monster.eliteVal;
		if(monster.eliteVal>10)cout<<"【BOSS】";
		else if(monster.eliteVal>5)cout<<"【领主】";
		else if(monster.eliteVal>3)cout<<"【精英】";
		cout << "\n怪物技能:";
		for(auto &s:monster.ms)cout<<GetMonsterSkillName(s.id)<<" ";
		cout << "\n1普攻 2放技能 3逃跑\n";
		char op = _getch();
		if(op=='3'){cout<<"逃跑无奖励,任意键返回\n";_getch();return;}
		if(monster.playerImprisonTurn>0){
			cout<<"你被禁锢无法行动,任意键跳过\n";_getch();
			monster.playerImprisonTurn--;
		}else if(op=='1'){
			int dmg = max(1, (rpg_data.atk + buffAtk) - monster.def);
			monster.hp -= dmg;
			cout<<"普攻造成"<<dmg<<"伤害\n";
		}else if(op=='2'){
			system("cls");
			cout<<"选择释放技能\n";
			for(int i=0;i<rpg_data.skillCnt;i++){
				Skill s=rpg_data.skills[i];
				cout<<i+1<<"."<<GetQualityStr(s.quality)<<GetSkillName(s.id)<<" MP:"<<GetSkillMpCost(s)<<"\n";
			}
			if(rpg_data.godSkillId)cout<<"G释放神技(10MP)\n";
			cout<<"数字释放,0返回:";
			char sel; cin >> sel;
			if(sel=='g'||sel=='G'){
				if(rpg_data.mp>=10){
					rpg_data.mp -= 10;
					CastSkillEffect(rpg_data.godSkillId, PURPLE, playerHp, monster.hp, monster.maxhp);
				}else cout<<"蓝不足\n";
			}else{
				int sid = sel - '0';
				if(sid>=1&&sid<=rpg_data.skillCnt){
					Skill s = rpg_data.skills[sid-1];
					int cost = GetSkillMpCost(s);
					if(rpg_data.mp >= cost){
						rpg_data.mp -= cost;
						CastSkillEffect(s.id, s.quality, playerHp, monster.hp, monster.maxhp);
					}else cout<<"蓝不足\n";
				}
			}
		}
		cout << "\n任意键怪物行动..."; _getch();
		if(poisonDmg>0){monster.hp -= poisonDmg; cout<<"毒素伤害"<<poisonDmg<<"\n";}
		if(monster.hp <= 0){ over = true; break; }
		bool monsterUseSkill = false;
		if(!monster.ms.empty() && rand()%100 < 40){
			auto sk = monster.ms[rand()%monster.ms.size()];
			monsterUseSkill = true;
			if(sk.id == MSKILL_IMPRISON_PLAYER){
				monster.playerImprisonTurn += 2;
				cout<<"怪物禁锢你2回合\n";
			}else if(sk.id == MSKILL_POISON){
				playerHp -= monster.atk * 0.3;
				cout<<"怪物毒伤你\n";
			}else if(sk.id == MSKILL_WEAK){
				buffAtk -= 4; buffDef -= 4;
				cout<<"你的攻防被削弱\n";
			}else if(sk.id == MSKILL_DOUBLE_ATK){
				int dmg = max(1, monster.atk * 2 - buffDef);
				playerHp -= dmg;
				cout<<"怪物双倍攻击,受"<<dmg<<"伤\n";
			}
		}
		if(!monsterUseSkill){
			int dmg = max(1, monster.atk - buffDef);
			playerHp -= dmg;
			cout<<"怪物普攻,受"<<dmg<<"伤害\n";
		}
		cout << "\n任意键下一回合..."; _getch();
		if(playerHp <= 0){ over = true; break; }
	}
	system("cls");
	int baseGold = 15 + rpg_data.stage * 8;
	int gemDrop = 0;
	double goldRate = 1.0;
	if(playerHp <= 0){
		cout<<"战败!关卡重置,满血满蓝\n";
		rpg_data.stage = 1;
		rpg_data.hp = rpg_data.maxhp;
		rpg_data.mp = rpg_data.maxMp;
	}else{
		if(monster.eliteVal > 10){
			goldRate = 2.0;
			gemDrop = rand()%5 + 5;
			gemDrop = min(gemDrop, monster.eliteVal / 3);
		}else if(monster.eliteVal > 5){
			goldRate = 1.75;
			gemDrop = rand()%3 + 1;
		}else if(monster.eliteVal > 3){
			goldRate = 1.5;
			gemDrop = rand()%3;
		}
		int finalGold = baseGold * goldRate;
		rpg_data.gold += finalGold;
		rpg_data.gem += gemDrop;
		rpg_data.stage++;
		rpg_data.hp = playerHp;
		cout<<"胜利!基础金币"<<baseGold<<" 倍率"<<goldRate<<" 获得"<<finalGold<<"\n";
		if(gemDrop>0)cout<<"宝石×"<<gemDrop<<"\n";
		if(monster.eliteVal>10)cout<<"【BOSS双倍金币高额宝石】\n";
		else if(monster.eliteVal>5)cout<<"【领主1.75倍稳定宝石】\n";
		else if(monster.eliteVal>3)cout<<"【精英1.5倍概率宝石】\n";
	}
	cout << "任意键返回角色面板..."; _getch();
}
void RpgGame() {
	int useSlot = -1;
	while(true){
		system("cls");
		cout << "RPG存档选择(5个)\n1新建\n";
		for(int i=1;i<=RPG_SLOT_MAX;i++){
			if(RpgSlotExist(i)){
				LoadRpg(i);
				cout<<i+1<<".存档"<<i<<"【"<<rpg_data.name<<"】\n";
			}else cout<<i+1<<".存档"<<i<<"(空)\n";
		}
		cout<<"输入:";
		int sel; cin >> sel;
		if(sel == 1){
			RpgNewChar();
			cout<<"自定义存档名(回车默认):";
			cin.get();
			char nm[32]; cin.getline(nm,30);
			if(strlen(nm)) strcpy(rpg_data.name, nm);
			break;
		}else if(sel >= 2 && sel <= RPG_SLOT_MAX + 1){
			int sid = sel - 1;
			if(LoadRpg(sid)){ useSlot = sid; break; }
			cout<<"空存档,重选\n"; _getch();
		}else{ cout<<"输入错误\n"; _getch(); }
	}
	while(true){
		RpgDrawMain();
		char c = _getch();
		if(c == 27){
			int empty = -1;
			for(int i=1;i<=RPG_SLOT_MAX;i++) if(!RpgSlotExist(i)){empty=i;break;}
			if(empty != -1){
				SaveRpg(empty);
				cout<<"自动保存至存档"<<empty<<"\n";
			}else{
				while(true){
					system("cls");
					cout<<"存档已满 1放弃 2-6覆盖1-5\n";
					int op; cin >> op;
					if(op == 1) break;
					if(op >= 2 && op <= 6){ SaveRpg(op-1); cout<<"已覆盖\n"; break; }
				}
			}
			cout<<"任意键回主菜单\n"; _getch();
			return;
		}
		if(c == '1') RpgBattle();
		if(c == '2') RpgShop();
		if(c == '3') ShowAllSkill();
	}
}
		
// ===================== 主菜单与入口 =====================
void ShowMenu() {
	system("cls");
	cout << "===== 小游戏合集 =====\n";
	cout << "1扫雷 2穿墙贪吃蛇 3猜数字 42048 5小黑屋 6RPG v1.1\n";
	cout << "输入数字选择游戏:";
}
void init(){}
signed main() {
	srand((unsigned)time(nullptr));
	while(true){
		ShowMenu();
		int op; cin >> op;
		if(op == 1) MineGame();
		else if(op == 2) SnakeGame();
		else if(op == 3) GuessGame();
		else if(op == 4) Game2048();
		else if(op == 5) DarkRoomGame();
		else if(op == 6) RpgGame();
		else { cout<<"输入错误,任意键重选\n"; _getch(); }
	}
	return 0;
}

v1.1.1

小版本更新,修复了存档功能。
蓝量自动恢复。
依据蓝量新增了3个技能。
2048和仿小黑屋都有问题,尽量修复。

INFO
C++
//flpar
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <conio.h>
#include <Windows.h>
#include <algorithm>
#include <fstream>
#include <cstring>
using namespace std;

// ===================== 全局共用常量 =====================
#define ROW_MINE 12
#define COL_MINE 20
#define MINE_CNT 30
#define SNAKE_W 30
#define SNAKE_H 20
#define GAME2048_SIZE 4
#define DARKROOM_SLOT_NUM 3
const int SNAKE_SPEED = 80;
const int GUESS_MIN = 1;
const int GUESS_MAX = 100;

const char SNAKE_SAVE_FILE[] = "snake_save.dat";
const char GAME2048_SAVE_FILE[] = "2048_save.dat";
const char DARKROOM_SAVE_PREFIX[] = "darkroom_slot";
const char RPG_SAVE_PREFIX[] = "rpg_slot";

const int RPG_SLOT_MAX = 5;
const int SKILL_PAGE_CNT = 8;
enum SkillQuality { WHITE, GREEN, BLUE, PURPLE };
enum SkillID {
	SKILL_NONE,
	SKILL_POWERUP, SKILL_SHIELD, SKILL_LIFESTEAL, SKILL_SWAPHP, SKILL_BLOODDRAIN,
	SKILL_STUN, SKILL_CRIT, SKILL_POISON, SKILL_REFLECT, SKILL_RUSH,
	SKILL_HEALSELF, SKILL_WEAKEN, SKILL_SILENCE, SKILL_DOUBLEHIT, SKILL_IMMUNE,
	// v1.1.1新增回蓝相关技能
	SKILL_DRAIN_MP,    // 吸能打击,偷蓝
	SKILL_MEDITATE,    // 冥想跳过回合大量回蓝
	SKILL_OVERCHARGE   // 超负荷耗蓝增伤
};
enum MonsterSkillID {
	MSKILL_NONE, MSKILL_IMPRISON_PLAYER, MSKILL_POISON, MSKILL_WEAK, MSKILL_DOUBLE_ATK
};

int dx8[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[] = {-1, 0, 1, -1, 1, -1, 0, 1};

// ===================== 通用存档工具 =====================
int LoadIntSave(const char* filename) {
	ifstream fin(filename, ios::binary);
	if (!fin.is_open()) return 0;
	int val;
	fin.read((char*)&val, sizeof(int));
	fin.close();
	return val;
}
void SaveIntFile(const char* filename, int data) {
	ofstream fout(filename, ios::binary);
	fout.write((char*)&data, sizeof(int));
	fout.close();
}
bool SlotExist(int id) {
	char buf[64];
	sprintf(buf, "%s%d.dat", DARKROOM_SAVE_PREFIX, id);
	ifstream f(buf, ios::binary);
	bool res = f.is_open();
	f.close();
	return res;
}

// ===================== 1. 扫雷 =====================
struct MineBlock {
	bool is_mine;
	bool open;
	bool flag;
	int mine_around;
} mine_map[ROW_MINE][COL_MINE];
int mine_state;
int mine_open_cnt;

void MineInit() {
	memset(mine_map, 0, sizeof(mine_map));
	srand((unsigned)time(nullptr));
	int cnt = 0;
	while (cnt < MINE_CNT) {
		int r = rand() % ROW_MINE;
		int c = rand() % COL_MINE;
		if (!mine_map[r][c].is_mine) {
			mine_map[r][c].is_mine = true;
			cnt++;
		}
	}
	for (int i = 0; i < ROW_MINE; i++) {
		for (int j = 0; j < COL_MINE; j++) {
			if (mine_map[i][j].is_mine) continue;
			int s = 0;
			for (int d = 0; d < 8; d++) {
				int nr = i + dx8[d], nc = j + dy8[d];
				if (nr >= 0 && nr < ROW_MINE && nc >= 0 && nc < COL_MINE && mine_map[nr][nc].is_mine) s++;
			}
			mine_map[i][j].mine_around = s;
		}
	}
	mine_state = 0;
	mine_open_cnt = 0;
}
void MineDraw(int cr, int cc) {
	system("cls");
	cout << "=== 扫雷 W/A/S/D移动 空格翻开 Q插旗 ESC返回菜单 ===\n\n";
	cout << "  ";
	for (int j = 0; j < COL_MINE; j++) cout << setw(2) << j;
	cout << "\n";
	for (int i = 0; i < ROW_MINE; i++) {
		cout << setw(2) << i;
		for (int j = 0; j < COL_MINE; j++) {
			if (i == cr && j == cc) cout << "[";
			else cout << " ";
			if (!mine_map[i][j].open) {
				if (mine_map[i][j].flag) cout << "F";
				else cout << "#";
			} else {
				if (mine_map[i][j].is_mine) cout << "*";
				else if (mine_map[i][j].mine_around == 0) cout << " ";
				else cout << mine_map[i][j].mine_around;
			}
			if (i == cr && j == cc) cout << "]";
			else cout << " ";
		}
		cout << "\n";
	}
	if (mine_state == 1) cout << "\n恭喜!扫雷成功!\n";
	if (mine_state == 2) cout << "\n踩到地雷,游戏结束!\n";
}
void MineDfs(int r, int c) {
	if (r < 0 || r >= ROW_MINE || c < 0 || c >= COL_MINE) return;
	if (mine_map[r][c].open || mine_map[r][c].flag) return;
	mine_map[r][c].open = true;
	mine_open_cnt++;
	if (mine_map[r][c].mine_around != 0) return;
	for (int d = 0; d < 8; d++) MineDfs(r + dx8[d], c + dy8[d]);
}
void MineCheckWin() {
	if (mine_open_cnt == ROW_MINE * COL_MINE - MINE_CNT) mine_state = 1;
}
void MineGame() {
	int cr = 0, cc = 0;
	MineInit();
	while (true) {
		MineDraw(cr, cc);
		if (mine_state != 0) {
			cout << "\n按任意键返回菜单...";
			_getch();
			return;
		}
		char op = _getch();
		if (op == 27) return;
		if (op == 'w' && cr > 0) cr--;
		if (op == 's' && cr < ROW_MINE - 1) cr++;
		if (op == 'a' && cc > 0) cc--;
		if (op == 'd' && cc < COL_MINE - 1) cc++;
		if (op == ' ') {
			if (mine_map[cr][cc].flag || mine_map[cr][cc].open) continue;
			if (mine_map[cr][cc].is_mine) {
				mine_state = 2;
				continue;
			}
			MineDfs(cr, cc);
			MineCheckWin();
		}
		if (op == 'q') {
			if (!mine_map[cr][cc].open) mine_map[cr][cc].flag = !mine_map[cr][cc].flag;
		}
	}
}

// ===================== 2. 贪吃蛇 =====================
struct Point { int x, y; };
vector<Point> snake;
Point food;
int dir;
int snake_score;
bool snake_over;
int snake_high;
void SnakeInit() {
	snake.clear();
	snake.push_back({SNAKE_W / 2, SNAKE_H / 2});
	snake.push_back({SNAKE_W / 2 - 1, SNAKE_H / 2});
	snake.push_back({SNAKE_W / 2 - 2, SNAKE_H / 2});
	dir = 1;
	snake_score = 0;
	snake_over = false;
	snake_high = LoadIntSave(SNAKE_SAVE_FILE);
}
void SpawnFood() {
	bool ok;
	do {
		ok = true;
		food.x = rand() % SNAKE_W;
		food.y = rand() % SNAKE_H;
		for (auto p : snake)
			if (p.x == food.x && p.y == food.y) { ok = false; break; }
	} while (!ok);
}
void SnakeDraw() {
	system("cls");
	cout << "=== 贪吃蛇 W/A/S/D控制 ESC返回 当前:" << snake_score << " 历史最高:" << snake_high << " | 穿墙模式 ===\n";
	for (int y = 0; y < SNAKE_H; y++) {
		for (int x = 0; x < SNAKE_W; x++) {
			if (x == food.x && y == food.y) { cout << "●"; continue; }
			bool body = false;
			for (int i = 0; i < snake.size(); i++) {
				if (snake[i].x == x && snake[i].y == y) {
					cout << (i == 0 ? "■" : "□");
					body = true;
					break;
				}
			}
			if (!body) cout << " ";
		}
		cout << "\n";
	}
	if (snake_over) cout << "\n撞到自身,游戏结束!\n";
}
void SnakeMove() {
	Point head = snake[0];
	if (dir == 0) head.y--;
	if (dir == 1) head.x++;
	if (dir == 2) head.y++;
	if (dir == 3) head.x--;
	if (head.x < 0) head.x = SNAKE_W - 1;
	if (head.x >= SNAKE_W) head.x = 0;
	if (head.y < 0) head.y = SNAKE_H - 1;
	if (head.y >= SNAKE_H) head.y = 0;
	for (auto p : snake)
		if (p.x == head.x && p.y == head.y) {
			snake_over = true;
			return;
		}
	snake.insert(snake.begin(), head);
	if (head.x == food.x && head.y == food.y) SpawnFood();
	else snake.pop_back();
}
void SnakeGame() {
	SnakeInit();
	SpawnFood();
	while (true) {
		SnakeDraw();
		if (snake_over) {
			if (snake_score > snake_high) {
				snake_high = snake_score;
				SaveIntFile(SNAKE_SAVE_FILE, snake_high);
				cout << "新纪录!已自动保存最高分\n";
			}
			cout << "\n按任意键返回菜单...";
			_getch();
			return;
		}
		if (_kbhit()) {
			char c = _getch();
			if (c == 27) return;
			if (c == 'w' && dir != 2) dir = 0;
			if (c == 'd' && dir != 3) dir = 1;
			if (c == 's' && dir != 0) dir = 2;
			if (c == 'a' && dir != 1) dir = 3;
		}
		SnakeMove();
		Sleep(SNAKE_SPEED);
	}
}

// ===================== 3. 猜数字 =====================
void GuessGame() {
	system("cls");
	cout << "===== 猜数字游戏 输入-1随时退出 =====\n";
	cout << "随机生成 " << GUESS_MIN << "~" << GUESS_MAX << " 数字\n";
	int target = rand() % (GUESS_MAX - GUESS_MIN + 1) + GUESS_MIN;
	int input, cnt = 0;
	while (true) {
		cout << "请输入数字:";
		cin >> input;
		if (input == -1) break;
		cnt++;
		if (input > target) cout << "太大了!\n";
		else if (input < target) cout << "太小了!\n";
		else {
			cout << "猜对!共猜" << cnt << "次\n";
			break;
		}
	}
	cout << "按任意键返回菜单...";
	_getch();
}

// ===================== 4. 2048 =====================
int board[GAME2048_SIZE][GAME2048_SIZE];
int score_2048, high_2048;
void RandomSpawn2048() {
	vector<pair<int, int>> empty;
	for (int i = 0; i < GAME2048_SIZE; i++)
		for (int j = 0; j < GAME2048_SIZE; j++)
			if (board[i][j] == 0) empty.emplace_back(i, j);
	if (empty.empty()) return;
	auto pos = empty[rand() % empty.size()];
	board[pos.first][pos.second] = (rand() % 10 == 1) ? 4 : 2;
}
void Init2048() {
	score_2048 = 0;
	memset(board, 0, sizeof(board));
	high_2048 = LoadIntSave(GAME2048_SAVE_FILE);
	RandomSpawn2048();
	RandomSpawn2048();
}
void Draw2048() {
	system("cls");
	cout << "===== 2048 W/A/S/D ESC退出 当前:" << score_2048 << " 最高:" << high_2048 << " =====\n";
	for (int i = 0; i < GAME2048_SIZE; i++) {
		for (int j = 0; j < GAME2048_SIZE; j++) cout << setw(4) << board[i][j];
		cout << "\n";
	}
}
bool SlideLeft(int line[GAME2048_SIZE]) {
	bool change = false;
	int tmp[GAME2048_SIZE] = {0}, pos = 0;
	for (int i = 0; i < GAME2048_SIZE; i++) if (line[i]) tmp[pos++] = line[i];
	for (int i = 0; i < GAME2048_SIZE - 1; i++) {
		if (tmp[i] == tmp[i + 1] && tmp[i]) {
			tmp[i] *= 2;
			score_2048 += tmp[i];
			tmp[i + 1] = 0;
			change = true;
		}
	}
	pos = 0;
	memset(line, 0, sizeof(int) * GAME2048_SIZE);
	for (int i = 0; i < GAME2048_SIZE; i++) if (tmp[i]) line[pos++] = tmp[i];
	return change;
}
void Rotate(int mat[GAME2048_SIZE][GAME2048_SIZE]) {
	int tmp[GAME2048_SIZE][GAME2048_SIZE];
	for (int i = 0; i < GAME2048_SIZE; i++)
		for (int j = 0; j < GAME2048_SIZE; j++)
			tmp[i][j] = mat[GAME2048_SIZE - j - 1][i];
	memcpy(mat, tmp, sizeof(tmp));
}
bool Move2048(char op) {
	bool flag = false;
	int rot = 0;
	if (op == 'w') rot = 3;
	if (op == 's') rot = 1;
	if (op == 'd') rot = 2;
	for (int i = 0; i < rot; i++) Rotate(board);
	for (int i = 0; i < GAME2048_SIZE; i++) if (SlideLeft(board[i])) flag = true;
	for (int i = 0; i < (4 - rot) % 4; i++) Rotate(board);
	if (flag) RandomSpawn2048();
	return flag;
}
void Game2048() {
	Init2048();
	while (true) {
		Draw2048();
		char c = _getch();
		if (c == 27) {
			if (score_2048 > high_2048) SaveIntFile(GAME2048_SAVE_FILE, score_2048);
			return;
		}
		if (c == 'w' || c == 'a' || c == 's' || c == 'd') Move2048(c);
	}
}

// ===================== 5. 小黑屋 =====================
struct DarkRoomData {
	int wood, fur, meat, villager, trap, fire;
} dr_data;
void SaveDarkRoom(int slot) {
	char buf[64];
	sprintf(buf, "%s%d.dat", DARKROOM_SAVE_PREFIX, slot);
	ofstream f(buf, ios::binary);
	f.write((char*)&dr_data, sizeof(DarkRoomData));
	f.close();
}
bool LoadDarkRoom(int slot) {
	char buf[64];
	sprintf(buf, "%s%d.dat", DARKROOM_SAVE_PREFIX, slot);
	ifstream f(buf, ios::binary);
	if (!f.is_open()) return false;
	f.read((char*)&dr_data, sizeof(DarkRoomData));
	f.close();
	return true;
}
void DarkRoomNewGame() {
	dr_data.wood = dr_data.fur = dr_data.meat = dr_data.villager = dr_data.trap = 0;
	dr_data.fire = 1;
}
void DarkRoomDraw() {
	system("cls");
	cout << "===== A Dark Room 小黑屋 ESC退出 ====\n";
	cout << "木材:" << dr_data.wood << " 皮毛:" << dr_data.fur << " 肉:" << dr_data.meat << "\n";
	cout << "村民:" << dr_data.villager << " 陷阱:" << dr_data.trap << " 火焰:" << dr_data.fire << "\n";
	cout << "1收集木 2造陷阱 3狩猎 4扩建小屋\n";
}
void DarkRoomTick() {
	dr_data.wood += dr_data.fire;
	for (int i = 1; i <= dr_data.trap; i++) dr_data.fur++, dr_data.meat++;
}
void DarkRoomGame() {
	int use_slot = -1;
	while (true) {
		system("cls");
		cout << "===== 小黑屋存档选择 =====\n1新建\n";
		for (int i = 1; i <= DARKROOM_SLOT_NUM; i++)
			cout << i + 1 << "." << (SlotExist(i) ? "读取存档" : "空存档") << i << "\n";
		cout << "输入:";
		int op; cin >> op;
		if (op == 1) { DarkRoomNewGame(); break; }
		else if (op >= 2 && op <= DARKROOM_SLOT_NUM + 1) {
			int sid = op - 1;
			if (LoadDarkRoom(sid)) { use_slot = sid; break; }
			cout << "空存档,重选\n"; _getch();
		} else { cout << "错误\n"; _getch(); }
	}
	while (true) {
		DarkRoomDraw();
		char c = _getch();
		if (c == 27) break;
		DarkRoomTick();
		if (c == '1') dr_data.wood += 5;
		if (c == '2' && dr_data.wood >= 10) { dr_data.wood -= 10; dr_data.trap++; }
		if (c == '3' && dr_data.villager) { dr_data.meat += 4; dr_data.fur += 2; }
		if (c == '4' && dr_data.wood >= 30 && dr_data.meat >= 10) {
			dr_data.wood -= 30; dr_data.meat -= 10; dr_data.villager++;
		}
		Sleep(400);
	}
	int empty_slot = -1;
	for (int i = 1; i <= DARKROOM_SLOT_NUM; i++) if (!SlotExist(i)) { empty_slot = i; break; }
	if (empty_slot != -1) SaveDarkRoom(empty_slot);
	else {
		while (true) {
			system("cls");
			cout << "存档已满 1放弃 2-4覆盖1-3\n";
			int sel; cin >> sel;
			if (sel == 1) break;
			if (sel >= 2 && sel <= 4) { SaveDarkRoom(sel - 1); break; }
		}
	}
	cout << "按任意键返回菜单..."; _getch();
}

// ===================== 6. RPG v1.1.1(修复存档+回蓝机制+新增技能) =====================
struct Skill {
	int id, quality;
	Skill() : id(SKILL_NONE), quality(WHITE) {}
	Skill(int i, int q) : id(i), quality(q) {}
};
struct RpgSaveData {
	char name[32];
	int hp, maxhp, atk, def, gold, stage;
	int skillCnt;
	Skill skills[20];
	int mp, maxMp, gem;
	int godSkillId;
} rpg_data;
struct MonsterSkill { int id, quality; MonsterSkill() : id(MSKILL_NONE), quality(WHITE) {} };
struct MonsterTemp {
	int hp, maxhp, atk, def;
	int playerImprisonTurn;
	vector<MonsterSkill> ms;
	int eliteVal;
} monster;
int buffAtk, buffDef, poisonDmg;
int SkillMpBase[20] = {0,8,7,10,12,11,13,9,6,14,10,12,7,11,15,16,13,20,18};

// 当前游玩存档槽(修复存档乱存BUG)
int rpgCurrentSlot = -1;

void GetRpgFileName(int slot, char buf[64]) { sprintf(buf, "%s%d.dat", RPG_SAVE_PREFIX, slot); }
bool RpgSlotExist(int slot) {
	char buf[64]; GetRpgFileName(slot, buf);
	ifstream f(buf, ios::binary); bool res = f.is_open(); f.close(); return res;
}
bool LoadRpg(int slot) {
	char buf[64]; GetRpgFileName(slot, buf);
	ifstream fin(buf, ios::binary);
	if (!fin.is_open()) return false;
	memset(&rpg_data, 0, sizeof(rpg_data));
	fin.read((char*)&rpg_data.name, 32);
	fin.read((char*)&rpg_data.hp, sizeof(int) * 7);
	fin.read((char*)&rpg_data.skills, sizeof(Skill) * 20);
	fin.close();
	if (rpg_data.maxMp == 0) rpg_data.maxMp = 50;
	rpg_data.mp = rpg_data.maxMp;
	return true;
}
void SaveRpg(int slot) {
	char buf[64]; GetRpgFileName(slot, buf);
	ofstream f(buf, ios::binary); f.write((char*)&rpg_data, sizeof(rpg_data)); f.close();
}
void RpgNewChar() {
	memset(rpg_data.name, 0, 32);
	rpg_data.hp = rpg_data.maxhp = 100;
	rpg_data.atk = 10; rpg_data.def = 5;
	rpg_data.gold = rpg_data.gem = rpg_data.stage = rpg_data.skillCnt = rpg_data.godSkillId = 0;
	memset(rpg_data.skills, 0, sizeof(rpg_data.skills));
	rpg_data.maxMp = rpg_data.mp = 50;
}
string GetQualityStr(int q) {
	if(q==WHITE)return"白色";if(q==GREEN)return"绿色";if(q==BLUE)return"蓝色";return"紫色";
}
string GetSkillName(int id) {
	switch(id){
		case SKILL_POWERUP:return"狂怒增幅";case SKILL_SHIELD:return"钢铁壁垒";
		case SKILL_LIFESTEAL:return"吸血打击";case SKILL_SWAPHP:return"生命置换";
		case SKILL_BLOODDRAIN:return"鲜血窃取";case SKILL_STUN:return"眩晕重击";
		case SKILL_CRIT:return"致命暴击";case SKILL_POISON:return"剧毒侵蚀";
		case SKILL_REFLECT:return"伤害反弹";case SKILL_RUSH:return"冲锋突袭";
		case SKILL_HEALSELF:return"自愈术";case SKILL_WEAKEN:return"衰弱诅咒";
		case SKILL_SILENCE:return"缄默封印";case SKILL_DOUBLEHIT:return"二段连击";
		case SKILL_IMMUNE:return"伤害免疫";
		case SKILL_DRAIN_MP:return"吸能打击";
		case SKILL_MEDITATE:return"静心冥想";
		case SKILL_OVERCHARGE:return"超负荷";
		default:return"未知";
	}
}
string GetMonsterSkillName(int id) {
	switch(id){
		case MSKILL_IMPRISON_PLAYER:return"禁锢(锁玩家2回合)";
		case MSKILL_POISON:return"毒伤";case MSKILL_WEAK:return"削弱攻防";
		case MSKILL_DOUBLE_ATK:return"双倍普攻";default:return"无";
	}
}
int GetSkillMpCost(Skill s) {
	int base = SkillMpBase[s.id];
	return max(2, base - s.quality);
}
void DrawSkill() {
	system("cls");
	cout << "抽技能 30金币/次,可能落空 金币:" << rpg_data.gold << "\n";
	if (rpg_data.gold < 30) { cout << "不足,任意键返回\n"; _getch(); return; }
	rpg_data.gold -= 30;
	Skill sk;
	if (rand() % 100 < 20) { cout << "抽空!\n"; }
	else {
		sk.id = rand() % 18 + 1; // 包含新增3个回蓝技能
		int r = rand() % 100;
		if(r<50)sk.quality=WHITE;else if(r<80)sk.quality=GREEN;else if(r<95)sk.quality=BLUE;else sk.quality=PURPLE;
		cout << "抽到【" << GetQualityStr(sk.quality) << "】" << GetSkillName(sk.id) << "\n";
		bool same = false;
		for (int i = 0; i < rpg_data.skillCnt; i++) {
			if (rpg_data.skills[i].id == sk.id) {
				same = true;
				if (sk.quality > rpg_data.skills[i].quality) {
					rpg_data.skills[i].quality = sk.quality;
					cout << "高品质覆盖\n";
				} else if (sk.quality == rpg_data.skills[i].quality && sk.quality < PURPLE) {
					rpg_data.skills[i].quality++;
					cout << "同品质进阶\n";
				} break;
			}
		}
		if (!same && rpg_data.skillCnt < 20) rpg_data.skills[rpg_data.skillCnt++] = sk;
		else if (!same) cout << "技能栏已满\n";
	}
	cout << "任意键返回\n"; _getch();
}
void ShowAllSkill() {
	int page = 0;
	while (true) {
		system("cls");
		cout << "技能列表 A上 D下 0退出 每页" << SKILL_PAGE_CNT << "\n";
		int st = page * SKILL_PAGE_CNT, ed = min(st + SKILL_PAGE_CNT, rpg_data.skillCnt);
		for (int i = st; i < ed; i++) {
			Skill s = rpg_data.skills[i];
			cout << i + 1 << "." << GetQualityStr(s.quality) << GetSkillName(s.id) << " 蓝耗:" << GetSkillMpCost(s) << "\n";
		}
		cout << "页" << page + 1 << " 按键:";
		char c = _getch();
		if (c == '0') break;
		if (c == 'a' && page > 0) page--;
		if (c == 'd' && ed < rpg_data.skillCnt) page++;
	}
}
int RefreshGemShopItem() { return rand() % 3; }
void RpgShop() {
	system("cls");
	int gemItem = RefreshGemShopItem();
	cout << "===== RPG商店 宝石:" << rpg_data.gem << " =====\n";
	cout << "[金币]\n1回满血30金 2攻+5(50) 3防+3(40) 4抽技能(30) 5蓝上限+20(80)\n";
	cout << "[宝石限购]\n";
	if(gemItem==0)cout<<"6最大蓝+50 消耗3宝石\n";
	else if(gemItem==1)cout<<"6随机神技 消耗5宝石\n";
	else cout<<"6全部技能品质+1 消耗4宝石\n";
	cout << "输入编号购买,0退出:";
	int op; cin >> op;
	if(op==1&&rpg_data.gold>=30){rpg_data.gold-=30;rpg_data.hp=rpg_data.maxhp;cout<<"满血\n";}
	else if(op==2&&rpg_data.gold>=50){rpg_data.gold-=50;rpg_data.atk+=5;cout<<"攻击+5\n";}
	else if(op==3&&rpg_data.gold>=40){rpg_data.gold-=40;rpg_data.def+=3;cout<<"防御+3\n";}
	else if(op==4){DrawSkill();return;}
	else if(op==5&&rpg_data.gold>=80){rpg_data.gold-=80;rpg_data.maxMp+=20;rpg_data.mp=rpg_data.maxMp;cout<<"蓝上限+20\n";}
	else if(op==6){
		if(gemItem==0&&rpg_data.gem>=3){rpg_data.gem-=3;rpg_data.maxMp+=50;cout<<"蓝上限+50\n";}
		else if(gemItem==1&&rpg_data.gem>=5){rpg_data.gem-=5;rpg_data.godSkillId=rand()%18+1;cout<<"获得神技:"<<GetSkillName(rpg_data.godSkillId)<<"\n";}
		else if(gemItem==2&&rpg_data.gem>=4){
			rpg_data.gem-=4;
			for(int i=0;i<rpg_data.skillCnt;i++)if(rpg_data.skills[i].quality<PURPLE)rpg_data.skills[i].quality++;
			cout<<"全技能升品质\n";
		}else cout<<"宝石不足\n";
	}else if(op!=0)cout<<"金币不足\n";
	cout << "任意键返回\n"; _getch();
}
void RpgDrawMain() {
	system("cls");
	cout << "RPG v1.1.1 ESC保存退出 存档名:" << rpg_data.name << "\n";
	cout << "HP:" << rpg_data.hp << "/" << rpg_data.maxhp << " MP:" << rpg_data.mp << "/" << rpg_data.maxMp << "\n";
	cout << "ATK:" << rpg_data.atk << " DEF:" << rpg_data.def << " GEM:" << rpg_data.gem << "\n";
	cout << "GOLD:" << rpg_data.gold << " STAGE:" << rpg_data.stage << " 技能数:" << rpg_data.skillCnt;
	if(rpg_data.godSkillId)cout<<" 神技:"<<GetSkillName(rpg_data.godSkillId);
	cout << "\n1战斗 2商店 3查看技能\n";
}
void CastSkillEffect(int sid, int q, int &pHP, int &mHP, int mMaxHp) {
	double mul = 1;
	if(q==GREEN)mul=1.2;if(q==BLUE)mul=1.4;if(q==PURPLE)mul=1.8;
	int dmg = (rpg_data.atk + buffAtk) * mul;
	switch(sid){
		case SKILL_POWERUP:buffAtk+=10*mul;cout<<"狂怒增幅 临时攻击提升\n";break;
		case SKILL_SHIELD:buffDef+=8*mul;cout<<"钢铁壁垒 临时防御提升\n";break;
		case SKILL_LIFESTEAL:{int h=dmg*0.4;mHP-=dmg;pHP+=h;cout<<"吸血打击 回"<<h<<"血\n";break;}
		case SKILL_SWAPHP:{int t=pHP;pHP=mHP;mHP=t;cout<<"生命置换 互换血量\n";break;}
		case SKILL_BLOODDRAIN:{int steal=mHP*0.3*mul;mHP-=steal;pHP+=steal;cout<<"窃取30%怪物血量\n";break;}
		case SKILL_STUN:monster.playerImprisonTurn+=2;mHP-=dmg;cout<<"眩晕 怪物禁锢2回合\n";break;
		case SKILL_CRIT:mHP-=dmg*2;cout<<"暴击双倍伤害\n";break;
		case SKILL_POISON:poisonDmg+=dmg*0.3;mHP-=dmg;cout<<"附加持续毒伤\n";break;
		case SKILL_REFLECT:{int ref=dmg*0.6;buffDef+=15*mul;mHP-=ref;cout<<"反弹"<<ref<<"伤害,防御提升\n";break;}
		case SKILL_RUSH:mHP-=dmg*1.5;cout<<"冲锋1.5倍伤\n";break;
		case SKILL_HEALSELF:{int h=rpg_data.maxhp*0.3*mul;pHP=min(pHP+h,rpg_data.maxhp);cout<<"自愈回复\n";break;}
		case SKILL_WEAKEN:monster.atk-=3;mHP-=dmg;cout<<"削弱怪物攻击\n";break;
		case SKILL_DOUBLEHIT:mHP-=dmg;mHP-=dmg*0.5;cout<<"二段连击\n";break;
		case SKILL_IMMUNE:buffDef+=30;cout<<"高额减伤\n";break;
		// v1.1.1新增技能逻辑
		case SKILL_DRAIN_MP:{
			int stealMp = 8 * mul;
			rpg_data.mp = min(rpg_data.mp + stealMp, rpg_data.maxMp);
			mHP -= dmg;
			cout<<"吸能打击,造成伤害并恢复"<<stealMp<<"法力\n";
			break;
		}
		case SKILL_MEDITATE:{
			int medRecover = 25 * mul;
			rpg_data.mp = min(rpg_data.mp + medRecover, rpg_data.maxMp);
			cout<<"静心冥想,跳过本回合,恢复"<<medRecover<<"法力\n";
			break;
		}
		case SKILL_OVERCHARGE:{
			int extraCost = 12;
			rpg_data.mp -= extraCost;
			mHP -= dmg * 2.5;
			cout<<"超负荷,额外消耗"<<extraCost<<"蓝,打出2.5倍伤害\n";
			break;
		}
		default:mHP-=dmg;
	}
}
void SpawnMonster() {
	monster.ms.clear();
	monster.playerImprisonTurn = poisonDmg = 0;
	monster.maxhp = 20 + rpg_data.stage * 12;
	monster.hp = monster.maxhp;
	monster.atk = 4 + rpg_data.stage * 3;
	monster.def = 3 + rpg_data.stage * 2;
	int skCnt = rand() % 4;
	monster.eliteVal = 0;
	for(int i=0;i<skCnt;i++){
		MonsterSkill s;
		s.id = rand() % 4 + 1;
		int r = rand() % 100;
		if(r<60){s.quality=WHITE;monster.eliteVal+=1;}
		else if(r<85){s.quality=GREEN;monster.eliteVal+=2;}
		else if(r<97){s.quality=BLUE;monster.eliteVal+=3;}
		else{s.quality=PURPLE;monster.eliteVal+=5;}
		monster.ms.push_back(s);
	}
}
void RpgBattle() {
	SpawnMonster();
	int playerHp = rpg_data.hp;
	buffAtk = buffDef = 0;
	bool over = false;
	while (!over) {
		system("cls");
		cout << "第" << rpg_data.stage << "关战斗\n";
		cout << "你 HP:" << playerHp << "/" << rpg_data.maxhp << " MP:" << rpg_data.mp << "/" << rpg_data.maxMp << "\n";
		cout << "临时攻+" << buffAtk << " 防+" << buffDef << "\n";
		cout << "怪物 HP:" << monster.hp << "/" << monster.maxhp;
		if(monster.playerImprisonTurn>0)cout<<" 你禁锢"<<monster.playerImprisonTurn<<"回合";
		cout << "\n精英值:" << monster.eliteVal;
		if(monster.eliteVal>10)cout<<"【BOSS】";
		else if(monster.eliteVal>5)cout<<"【领主】";
		else if(monster.eliteVal>3)cout<<"【精英】";
		cout << "\n怪物技能:";
		for(auto &s:monster.ms)cout<<GetMonsterSkillName(s.id)<<" ";
		cout << "\n1普攻 2放技能 3逃跑\n";
		char op = _getch();
		bool skipTurn = false;
		if(op=='3'){cout<<"逃跑无奖励,任意键返回\n";_getch();return;}
		if(monster.playerImprisonTurn>0){
			cout<<"你被禁锢无法行动,任意键跳过\n";_getch();
			monster.playerImprisonTurn--;
		}else if(op=='1'){
			int dmg = max(1, (rpg_data.atk + buffAtk) - monster.def);
			monster.hp -= dmg;
			cout<<"普攻造成"<<dmg<<"伤害\n";
		}else if(op=='2'){
			system("cls");
			cout<<"选择释放技能\n";
			for(int i=0;i<rpg_data.skillCnt;i++){
				Skill s=rpg_data.skills[i];
				cout<<i+1<<"."<<GetQualityStr(s.quality)<<GetSkillName(s.id)<<" MP:"<<GetSkillMpCost(s)<<"\n";
			}
			if(rpg_data.godSkillId)cout<<"G释放神技(10MP)\n";
			cout<<"数字释放,0返回:";
			char sel; cin >> sel;
			if(sel=='g'||sel=='G'){
				if(rpg_data.mp>=10){
					rpg_data.mp -= 10;
					CastSkillEffect(rpg_data.godSkillId, PURPLE, playerHp, monster.hp, monster.maxhp);
				}else cout<<"蓝不足\n";
			}else{
				int sid = sel - '0';
				if(sid>=1&&sid<=rpg_data.skillCnt){
					Skill s = rpg_data.skills[sid-1];
					int cost = GetSkillMpCost(s);
					if(rpg_data.mp >= cost){
						rpg_data.mp -= cost;
						CastSkillEffect(s.id, s.quality, playerHp, monster.hp, monster.maxhp);
						// 冥想标记跳过回合
						if(s.id == SKILL_MEDITATE) skipTurn = true;
					}else cout<<"蓝不足\n";
				}
			}
		}
		// 每回合固定回5蓝
		rpg_data.mp = min(rpg_data.mp + 5, rpg_data.maxMp);
		cout << "\n回合结束,法力恢复5点 | 任意键怪物行动..."; _getch();
		if(poisonDmg>0){monster.hp -= poisonDmg; cout<<"毒素伤害"<<poisonDmg<<"\n";}
		if(monster.hp <= 0){ over = true; break; }
		// 冥想跳过玩家回合,怪物不攻击
		if(skipTurn){
			cout<<"冥想跳过本回合怪物行动\n";
			cout << "\n任意键下一回合..."; _getch();
			continue;
		}
		bool monsterUseSkill = false;
		if(!monster.ms.empty() && rand()%100 < 40){
			auto sk = monster.ms[rand()%monster.ms.size()];
			monsterUseSkill = true;
			if(sk.id == MSKILL_IMPRISON_PLAYER){
				monster.playerImprisonTurn += 2;
				cout<<"怪物禁锢你2回合\n";
			}else if(sk.id == MSKILL_POISON){
				playerHp -= monster.atk * 0.3;
				cout<<"怪物毒伤你\n";
			}else if(sk.id == MSKILL_WEAK){
				buffAtk -= 4; buffDef -= 4;
				cout<<"你的攻防被削弱\n";
			}else if(sk.id == MSKILL_DOUBLE_ATK){
				int dmg = max(1, monster.atk * 2 - buffDef);
				playerHp -= dmg;
				cout<<"怪物双倍攻击,受"<<dmg<<"伤\n";
			}
		}
		if(!monsterUseSkill){
			int dmg = max(1, monster.atk - buffDef);
			playerHp -= dmg;
			cout<<"怪物普攻,受"<<dmg<<"伤害\n";
		}
		cout << "\n任意键下一回合..."; _getch();
		if(playerHp <= 0){ over = true; break; }
	}
	system("cls");
	int baseGold = 15 + rpg_data.stage * 8;
	int gemDrop = 0;
	double goldRate = 1.0;
	if(playerHp <= 0){
		cout<<"战败!关卡重置,满血满蓝\n";
		rpg_data.stage = 1;
		rpg_data.hp = rpg_data.maxhp;
		rpg_data.mp = rpg_data.maxMp;
	}else{
		// 战斗胜利退出战斗,蓝量回满
		rpg_data.mp = rpg_data.maxMp;
		if(monster.eliteVal > 10){
			goldRate = 2.0;
			gemDrop = rand()%5 + 5;
			gemDrop = min(gemDrop, monster.eliteVal / 3);
		}else if(monster.eliteVal > 5){
			goldRate = 1.75;
			gemDrop = rand()%3 + 1;
		}else if(monster.eliteVal > 3){
			goldRate = 1.5;
			gemDrop = rand()%3;
		}
		int finalGold = baseGold * goldRate;
		rpg_data.gold += finalGold;
		rpg_data.gem += gemDrop;
		rpg_data.stage++;
		rpg_data.hp = playerHp;
		cout<<"胜利!法力已完全恢复\n";
		cout<<"基础金币"<<baseGold<<" 倍率"<<goldRate<<" 获得"<<finalGold<<"\n";
		if(gemDrop>0)cout<<"宝石×"<<gemDrop<<"\n";
		if(monster.eliteVal>10)cout<<"【BOSS双倍金币高额宝石】\n";
		else if(monster.eliteVal>5)cout<<"【领主1.75倍稳定宝石】\n";
		else if(monster.eliteVal>3)cout<<"【精英1.5倍概率宝石】\n";
	}
	cout << "任意键返回角色面板..."; _getch();
}
void RpgGame() {
	rpgCurrentSlot = -1;
	int useSlot = -1;
	while(true){
		system("cls");
		cout << "RPG存档选择(5个)v1.1.1\n1新建\n";
		for(int i=1;i<=RPG_SLOT_MAX;i++){
			if(RpgSlotExist(i)){
				LoadRpg(i);
				cout<<i+1<<".存档"<<i<<"【"<<rpg_data.name<<"】\n";
			}else cout<<i+1<<".存档"<<i<<"(空)\n";
		}
		cout<<"输入:";
		int sel; cin >> sel;
		if(sel == 1){
			RpgNewChar();
			cout<<"自定义存档名(回车默认):";
			cin.get();
			char nm[32]; cin.getline(nm,30);
			if(strlen(nm)) strcpy(rpg_data.name, nm);
			rpgCurrentSlot = -1; // 新建存档,退出时自动找空位
			break;
		}else if(sel >= 2 && sel <= RPG_SLOT_MAX + 1){
			int sid = sel - 1;
			if(LoadRpg(sid)){
				useSlot = sid;
				rpgCurrentSlot = sid; // 记录当前游玩槽,修复存档乱存BUG
				break;
			}
			cout<<"空存档,重选\n"; _getch();
		}else{ cout<<"输入错误\n"; _getch(); }
	}
	while(true){
		RpgDrawMain();
		char c = _getch();
		if(c == 27){
			// 修复:固定保存当前游玩槽,不再乱存
			if(rpgCurrentSlot != -1){
				SaveRpg(rpgCurrentSlot);
				cout<<"已保存至存档"<<rpgCurrentSlot<<"\n";
			}else{
				// 新建无编号存档,寻找空位
				int empty = -1;
				for(int i=1;i<=RPG_SLOT_MAX;i++) if(!RpgSlotExist(i)){empty=i;break;}
				if(empty != -1){
					SaveRpg(empty);
					cout<<"自动保存至存档"<<empty<<"\n";
				}else{
					while(true){
						system("cls");
						cout<<"存档已满 1放弃 2-6覆盖1-5\n";
						int op; cin >> op;
						if(op == 1) break;
						if(op >= 2 && op <= 6){ SaveRpg(op-1); cout<<"已覆盖\n"; break; }
					}
				}
			}
			cout<<"任意键回主菜单\n"; _getch();
			return;
		}
		if(c == '1') RpgBattle();
		if(c == '2') RpgShop();
		if(c == '3') ShowAllSkill();
	}
}

// ===================== 主菜单与入口 =====================
void ShowMenu() {
	system("cls");
	cout << "===== 小游戏合集 =====\n";
	cout << "1扫雷 2穿墙贪吃蛇 3猜数字 42048 5小黑屋 6Crystal Skill Expedition v1.1.1\n";
	cout << "输入数字选择游戏:";
}
void init(){}
signed main() {
	srand((unsigned)time(nullptr));
	while(true){
		ShowMenu();
		int op; cin >> op;
		if(op == 1) MineGame();
		else if(op == 2) SnakeGame();
		else if(op == 3) GuessGame();
		else if(op == 4) Game2048();
		else if(op == 5) DarkRoomGame();
		else if(op == 6) RpgGame();
		else { cout<<"输入错误,任意键重选\n"; _getch(); }
	}
	return 0;
}

v1.1.2

也就游戏6好玩点了,于是把它拿出来独立做成一个游戏,命名 CryWorldRPG,CWR。
修复了读入bug。
游戏大部分不是我写的,我只是改了很多参数,然后测试,手写建议给AI(要给AI解释清楚真的要写很多字),如果有什么建议可以跟我说,同时代码就在这,想拿走就拿走。

INFO
C++
//flpar
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <conio.h>
#include <Windows.h>
#include <algorithm>
#include <fstream>
#include <cstring>
#include <string>
using namespace std;

// ===================== RPG全局常量 =====================
const char RPG_SAVE_PREFIX[] = "rpg_slot";
const int RPG_SLOT_MAX = 10; // 存档扩充至10个
const int SKILL_PAGE_CNT = 8;

enum SkillQuality { WHITE, GREEN, BLUE, PURPLE };
enum SkillID {
	SKILL_NONE,
	SKILL_POWERUP, SKILL_SHIELD, SKILL_LIFESTEAL, SKILL_SWAPHP, SKILL_BLOODDRAIN,
	SKILL_STUN, SKILL_CRIT, SKILL_POISON, SKILL_REFLECT, SKILL_RUSH,
	SKILL_HEALSELF, SKILL_WEAKEN, SKILL_SILENCE, SKILL_DOUBLEHIT, SKILL_IMMUNE,
	// v1.1.1新增回蓝相关技能
	SKILL_DRAIN_MP,    // 吸能打击,偷蓝
	SKILL_MEDITATE,    // 冥想跳过回合大量回蓝
	SKILL_OVERCHARGE   // 超负荷耗蓝增伤
};
enum MonsterSkillID {
	MSKILL_NONE, MSKILL_IMPRISON_PLAYER, MSKILL_POISON, MSKILL_WEAK, MSKILL_DOUBLE_ATK
};

// ===================== 存档工具 =====================
void GetRpgFileName(int slot, char buf[64]) { sprintf(buf, "%s%d.dat", RPG_SAVE_PREFIX, slot); }
bool RpgSlotExist(int slot) {
	char buf[64]; GetRpgFileName(slot, buf);
	ifstream f(buf, ios::binary); bool res = f.is_open(); f.close(); return res;
}

// ===================== 数据结构体 =====================
struct Skill {
	int id, quality;
	Skill() : id(SKILL_NONE), quality(WHITE) {}
	Skill(int i, int q) : id(i), quality(q) {}
};
struct RpgSaveData {
	char name[32];
	int hp, maxhp, atk, def, gold, stage;
	int skillCnt;
	Skill skills[20];
	int mp, maxMp, gem;
	int godSkillId;
} rpg_data;
struct MonsterSkill { int id, quality; MonsterSkill() : id(MSKILL_NONE), quality(WHITE) {} };
struct MonsterTemp {
	int hp, maxhp, atk, def;
	int playerImprisonTurn;
	vector<MonsterSkill> ms;
	int eliteVal;
} monster;

// 全局战斗变量
int buffAtk, buffDef, poisonDmg;
int SkillMpBase[20] = {0,8,7,10,12,11,13,9,6,14,10,12,7,11,15,16,13,20,18};
int rpgCurrentSlot = -1; // 当前游玩存档槽

// ===================== 存档读写 =====================
bool LoadRpg(int slot) {
	char buf[64]; GetRpgFileName(slot, buf);
	ifstream fin(buf, ios::binary);
	if (!fin.is_open()) return false;
	memset(&rpg_data, 0, sizeof(rpg_data));
	fin.read((char*)&rpg_data.name, 32);
	fin.read((char*)&rpg_data.hp, sizeof(int) * 7);
	fin.read((char*)&rpg_data.skills, sizeof(Skill) * 20);
	fin.close();
	if (rpg_data.maxMp == 0) rpg_data.maxMp = 50;
	rpg_data.mp = rpg_data.maxMp;
	return true;
}
void SaveRpg(int slot) {
	char buf[64]; GetRpgFileName(slot, buf);
	ofstream f(buf, ios::binary); f.write((char*)&rpg_data, sizeof(rpg_data)); f.close();
}
void RpgNewChar() {
	memset(rpg_data.name, 0, 32);
	rpg_data.hp = rpg_data.maxhp = 100;
	rpg_data.atk = 10; rpg_data.def = 5;
	rpg_data.gold = rpg_data.gem = rpg_data.stage = rpg_data.skillCnt = rpg_data.godSkillId = 0;
	memset(rpg_data.skills, 0, sizeof(rpg_data.skills));
	rpg_data.maxMp = rpg_data.mp = 50;
}

// ===================== 文本转换工具 =====================
string GetQualityStr(int q) {
	if(q==WHITE)return"白色";if(q==GREEN)return"绿色";if(q==BLUE)return"蓝色";return"紫色";
}
string GetSkillName(int id) {
	switch(id){
		case SKILL_POWERUP:return"狂怒增幅";case SKILL_SHIELD:return"钢铁壁垒";
		case SKILL_LIFESTEAL:return"吸血打击";case SKILL_SWAPHP:return"生命置换";
		case SKILL_BLOODDRAIN:return"鲜血窃取";case SKILL_STUN:return"眩晕重击";
		case SKILL_CRIT:return"致命暴击";case SKILL_POISON:return"剧毒侵蚀";
		case SKILL_REFLECT:return"伤害反弹";case SKILL_RUSH:return"冲锋突袭";
		case SKILL_HEALSELF:return"自愈术";case SKILL_WEAKEN:return"衰弱诅咒";
		case SKILL_SILENCE:return"缄默封印";case SKILL_DOUBLEHIT:return"二段连击";
		case SKILL_IMMUNE:return"伤害免疫";
		case SKILL_DRAIN_MP:return"吸能打击";
		case SKILL_MEDITATE:return"静心冥想";
		case SKILL_OVERCHARGE:return"超负荷";
		default:return"未知";
	}
}
string GetMonsterSkillName(int id) {
	switch(id){
		case MSKILL_IMPRISON_PLAYER:return"禁锢(锁玩家2回合)";
		case MSKILL_POISON:return"毒伤";case MSKILL_WEAK:return"削弱攻防";
		case MSKILL_DOUBLE_ATK:return"双倍普攻";default:return"无";
	}
}
int GetSkillMpCost(Skill s) {
	int base = SkillMpBase[s.id];
	return max(2, base - s.quality);
}

// ===================== 抽卡/商店/技能列表 =====================
void DrawSkill() {
	system("cls");
	cout << "抽技能 30金币/次,可能落空 金币:" << rpg_data.gold << "\n";
	if (rpg_data.gold < 30) { cout << "金币不足,任意键返回\n"; _getch(); return; }
	rpg_data.gold -= 30;
	Skill sk;
	if (rand() % 100 < 20) { cout << "抽空!本次无新技能\n"; }
	else {
		sk.id = rand() % 18 + 1;
		int r = rand() % 100;
		if(r<50)sk.quality=WHITE;else if(r<80)sk.quality=GREEN;else if(r<95)sk.quality=BLUE;else sk.quality=PURPLE;
		cout << "抽到【" << GetQualityStr(sk.quality) << "】" << GetSkillName(sk.id) << "\n";
		bool same = false;
		for (int i = 0; i < rpg_data.skillCnt; i++) {
			if (rpg_data.skills[i].id == sk.id) {
				same = true;
				if (sk.quality > rpg_data.skills[i].quality) {
					rpg_data.skills[i].quality = sk.quality;
					cout << "高品质覆盖原有技能\n";
				} else if (sk.quality == rpg_data.skills[i].quality && sk.quality < PURPLE) {
					rpg_data.skills[i].quality++;
					cout << "同品质技能进阶\n";
				} break;
			}
		}
		if (!same && rpg_data.skillCnt < 20) rpg_data.skills[rpg_data.skillCnt++] = sk;
		else if (!same) cout << "技能栏已满,无法获取\n";
	}
	cout << "任意键返回\n"; _getch();
}
void ShowAllSkill() {
	int page = 0;
	while (true) {
		system("cls");
		cout << "技能列表 A上一页 D下一页 0退出 每页" << SKILL_PAGE_CNT << "个\n";
		int st = page * SKILL_PAGE_CNT, ed = min(st + SKILL_PAGE_CNT, rpg_data.skillCnt);
		for (int i = st; i < ed; i++) {
			Skill s = rpg_data.skills[i];
			cout << i + 1 << "." << GetQualityStr(s.quality) << GetSkillName(s.id) << " 蓝耗:" << GetSkillMpCost(s) << "\n";
		}
		cout << "当前页" << page + 1 << " 输入按键:";
		char c = _getch();
		if (c == '0') break;
		if (c == 'a' && page > 0) page--;
		if (c == 'd' && ed < rpg_data.skillCnt) page++;
	}
}
int RefreshGemShopItem() { return rand() % 3; }
void RpgShop() {
	system("cls");
	int gemItem = RefreshGemShopItem();
	cout << "===== RPG商店 宝石:" << rpg_data.gem << " =====\n";
	cout << "[金币道具]\n1回满血(30金) 2攻击+5(50金) 3防御+3(40金) 4抽取技能(30金) 5蓝上限+20(80金)\n";
	cout << "[宝石限定道具]\n";
	if(gemItem==0)cout<<"6永久最大蓝量+50 消耗3宝石\n";
	else if(gemItem==1)cout<<"6随机神级技能 消耗5宝石\n";
	else cout<<"6全部技能品质+1 消耗4宝石\n";
	cout << "输入编号购买,0关闭商店:";
	int op; cin >> op;
	if(op==1&&rpg_data.gold>=30){rpg_data.gold-=30;rpg_data.hp=rpg_data.maxhp;cout<<"已回满生命值\n";}
	else if(op==2&&rpg_data.gold>=50){rpg_data.gold-=50;rpg_data.atk+=5;cout<<"攻击力永久+5\n";}
	else if(op==3&&rpg_data.gold>=40){rpg_data.gold-=40;rpg_data.def+=3;cout<<"防御力永久+3\n";}
	else if(op==4){DrawSkill();return;}
	else if(op==5&&rpg_data.gold>=80){rpg_data.gold-=80;rpg_data.maxMp+=20;rpg_data.mp=rpg_data.maxMp;cout<<"法力上限+20\n";}
	else if(op==6){
		if(gemItem==0&&rpg_data.gem>=3){rpg_data.gem-=3;rpg_data.maxMp+=50;cout<<"法力上限+50\n";}
		else if(gemItem==1&&rpg_data.gem>=5){rpg_data.gem-=5;rpg_data.godSkillId=rand()%18+1;cout<<"获得神技:"<<GetSkillName(rpg_data.godSkillId)<<"\n";}
		else if(gemItem==2&&rpg_data.gem>=4){
			rpg_data.gem-=4;
			for(int i=0;i<rpg_data.skillCnt;i++)if(rpg_data.skills[i].quality<PURPLE)rpg_data.skills[i].quality++;
			cout<<"所有技能品质提升一级\n";
		}else cout<<"宝石数量不足\n";
	}else if(op!=0)cout<<"金币数量不足\n";
	cout << "任意键返回\n"; _getch();
}

// ===================== 主界面绘制 =====================
void RpgDrawMain() {
	system("cls");
	cout << "Crystal Skill Expedition RPG v1.1.2 | ESC保存并返回存档选择 存档名:" << rpg_data.name << "\n";
	cout << "HP:" << rpg_data.hp << "/" << rpg_data.maxhp << " MP:" << rpg_data.mp << "/" << rpg_data.maxMp << "\n";
	cout << "ATK:" << rpg_data.atk << " DEF:" << rpg_data.def << " GEM:" << rpg_data.gem << "\n";
	cout << "GOLD:" << rpg_data.gold << " STAGE:" << rpg_data.stage << " 技能数:" << rpg_data.skillCnt;
	if(rpg_data.godSkillId)cout<<" 神技:"<<GetSkillName(rpg_data.godSkillId);
	cout << "\n1进入战斗 2打开商店 3查看全部技能\n";
}

// ===================== 战斗逻辑 =====================
void CastSkillEffect(int sid, int q, int &pHP, int &mHP, int mMaxHp) {
	double mul = 1;
	if(q==GREEN)mul=1.2;if(q==BLUE)mul=1.4;if(q==PURPLE)mul=1.8;
	int dmg = (rpg_data.atk + buffAtk) * mul;
	switch(sid){
		case SKILL_POWERUP:buffAtk+=10*mul;cout<<"狂怒增幅 临时攻击力大幅提升\n";break;
		case SKILL_SHIELD:buffDef+=8*mul;cout<<"钢铁壁垒 临时防御力大幅提升\n";break;
		case SKILL_LIFESTEAL:{int h=dmg*0.4;mHP-=dmg;pHP+=h;cout<<"吸血打击 造成伤害并回复"<<h<<"生命值\n";break;}
		case SKILL_SWAPHP:{int t=pHP;pHP=mHP;mHP=t;cout<<"生命置换 与怪物互换当前血量\n";break;}
		case SKILL_BLOODDRAIN:{int steal=mHP*0.3*mul;mHP-=steal;pHP+=steal;cout<<"鲜血窃取 夺取怪物30%当前血量\n";break;}
		case SKILL_STUN:monster.playerImprisonTurn+=2;mHP-=dmg;cout<<"眩晕重击 禁锢怪物2回合\n";break;
		case SKILL_CRIT:mHP-=dmg*2;cout<<"致命暴击 双倍伤害\n";break;
		case SKILL_POISON:poisonDmg+=dmg*0.3;mHP-=dmg;cout<<"剧毒侵蚀 附加持续毒素伤害\n";break;
		case SKILL_REFLECT:{int ref=dmg*0.6;buffDef+=15*mul;mHP-=ref;cout<<"反弹"<<ref<<"伤害,防御提升\n";break;}
		case SKILL_RUSH:mHP-=dmg*1.5;cout<<"冲锋突袭 1.5倍伤害\n";break;
		case SKILL_HEALSELF:{int h=rpg_data.maxhp*0.3*mul;pHP=min(pHP+h,rpg_data.maxhp);cout<<"自愈术 回复大量生命值\n";break;}
		case SKILL_WEAKEN:monster.atk-=3;mHP-=dmg;cout<<"衰弱诅咒 永久降低怪物攻击力\n";break;
		case SKILL_DOUBLEHIT:mHP-=dmg;mHP-=dmg*0.5;cout<<"二段连击 两段连续伤害\n";break;
		case SKILL_IMMUNE:buffDef+=30;cout<<"伤害免疫 高额减伤buff\n";break;
		// v1.1.1新增技能逻辑
		case SKILL_DRAIN_MP:{
			int stealMp = 8 * mul;
			rpg_data.mp = min(rpg_data.mp + stealMp, rpg_data.maxMp);
			mHP -= dmg;
			cout<<"吸能打击,造成伤害并恢复"<<stealMp<<"法力\n";
			break;
		}
		case SKILL_MEDITATE:{
			int medRecover = 25 * mul;
			rpg_data.mp = min(rpg_data.mp + medRecover, rpg_data.maxMp);
			cout<<"静心冥想,跳过本回合行动,恢复"<<medRecover<<"法力\n";
			break;
		}
		case SKILL_OVERCHARGE:{
			int extraCost = 12;
			rpg_data.mp -= extraCost;
			mHP -= dmg * 2.5;
			cout<<"超负荷,额外消耗"<<extraCost<<"蓝,打出2.5倍高额伤害\n";
			break;
		}
		default:mHP-=dmg;
	}
}
void SpawnMonster() {
	monster.ms.clear();
	monster.playerImprisonTurn = poisonDmg = 0;
	monster.maxhp = 20 + rpg_data.stage * 12;
	monster.hp = monster.maxhp;
	monster.atk = 4 + rpg_data.stage * 3;
	monster.def = 3 + rpg_data.stage * 2;
	int skCnt = rand() % 4;
	monster.eliteVal = 0;
	for(int i=0;i<skCnt;i++){
		MonsterSkill s;
		s.id = rand() % 4 + 1;
		int r = rand() % 100;
		if(r<60){s.quality=WHITE;monster.eliteVal+=1;}
		else if(r<85){s.quality=GREEN;monster.eliteVal+=2;}
		else if(r<97){s.quality=BLUE;monster.eliteVal+=3;}
		else{s.quality=PURPLE;monster.eliteVal+=5;}
		monster.ms.push_back(s);
	}
}
void RpgBattle() {
	SpawnMonster();
	int playerHp = rpg_data.hp;
	buffAtk = buffDef = 0;
	bool over = false;
	while (!over) {
		system("cls");
		cout << "第" << rpg_data.stage << "关战斗\n";
		cout << "你 HP:" << playerHp << "/" << rpg_data.maxhp << " MP:" << rpg_data.mp << "/" << rpg_data.maxMp << "\n";
		cout << "临时攻+" << buffAtk << " 防+" << buffDef << "\n";
		cout << "怪物 HP:" << monster.hp << "/" << monster.maxhp;
		if(monster.playerImprisonTurn>0)cout<<" 你禁锢"<<monster.playerImprisonTurn<<"回合";
		cout << "\n精英值:" << monster.eliteVal;
		if(monster.eliteVal>10)cout<<"【BOSS】";
		else if(monster.eliteVal>5)cout<<"【领主】";
		else if(monster.eliteVal>3)cout<<"【精英】";
		cout << "\n怪物技能:";
		for(auto &s:monster.ms)cout<<GetMonsterSkillName(s.id)<<" ";
		cout << "\n1普攻 2放技能 3逃跑\n";
		char op = _getch();
		bool skipTurn = false;
		if(op=='3'){cout<<"逃跑无奖励,任意键返回\n";_getch();return;}
		if(monster.playerImprisonTurn>0){
			cout<<"禁锢无法行动,任意键跳过\n";_getch();
			monster.playerImprisonTurn--;
		}else if(op=='1'){
			int dmg = max(1, (rpg_data.atk + buffAtk) - monster.def);
			monster.hp -= dmg;
			cout<<"普攻造成"<<dmg<<"伤害\n";
		}else if(op=='2'){
			system("cls");
			cout<<"选择释放技能(支持1~20两位数编号)\n";
			for(int i=0;i<rpg_data.skillCnt;i++){
				Skill s=rpg_data.skills[i];
				cout<<i+1<<"."<<GetQualityStr(s.quality)<<GetSkillName(s.id)<<" MP:"<<GetSkillMpCost(s)<<"\n";
			}
			if(rpg_data.godSkillId)cout<<"G释放神技(固定10MP)\n";
			cout<<"输入编号,0返回战斗:";
			string selStr;
			cin >> selStr;
			if(selStr == "g" || selStr == "G"){
				if(rpg_data.mp>=10){
					rpg_data.mp -= 10;
					CastSkillEffect(rpg_data.godSkillId, PURPLE, playerHp, monster.hp, monster.maxhp);
				}else cout<<"法力不足\n";
			}else{
				// 修复:完整转换字符串为数字,支持两位数10、11…20
				int sid = stoi(selStr);
				if(sid>=1&&sid<=rpg_data.skillCnt){
					Skill s = rpg_data.skills[sid-1];
					int cost = GetSkillMpCost(s);
					if(rpg_data.mp >= cost){
						rpg_data.mp -= cost;
						CastSkillEffect(s.id, s.quality, playerHp, monster.hp, monster.maxhp);
						if(s.id == SKILL_MEDITATE) skipTurn = true;
					}else cout<<"法力不足\n";
				}else if(sid != 0){
					cout<<"不存在该技能\n";
				}
			}
		}
		// 每回合回5蓝
		rpg_data.mp = min(rpg_data.mp + 5, rpg_data.maxMp);
		cout << "\n回合结束,法力+5 | 任意键怪物行动..."; _getch();
		if(poisonDmg>0){monster.hp -= poisonDmg; cout<<"毒素伤害"<<poisonDmg<<"\n";}
		if(monster.hp <= 0){ over = true; break; }
		if(skipTurn){
			cout<<"冥想跳过怪物攻击\n";
			cout << "\n任意键下一回合..."; _getch();
			continue;
		}
		bool monsterUseSkill = false;
		if(!monster.ms.empty() && rand()%100 < 40){
			auto sk = monster.ms[rand()%monster.ms.size()];
			monsterUseSkill = true;
			if(sk.id == MSKILL_IMPRISON_PLAYER){
				monster.playerImprisonTurn += 2;
				cout<<"怪物禁锢你2回合\n";
			}else if(sk.id == MSKILL_POISON){
				playerHp -= monster.atk * 0.3;
				cout<<"怪物毒伤\n";
			}else if(sk.id == MSKILL_WEAK){
				buffAtk -= 4; buffDef -= 4;
				cout<<"攻防被削弱\n";
			}else if(sk.id == MSKILL_DOUBLE_ATK){
				int dmg = max(1, monster.atk * 2 - buffDef);
				playerHp -= dmg;
				cout<<"怪物双倍攻击,受"<<dmg<<"伤\n";
			}
		}
		if(!monsterUseSkill){
			int dmg = max(1, monster.atk - buffDef);
			playerHp -= dmg;
			cout<<"怪物普攻,受"<<dmg<<"伤害\n";
		}
		cout << "\n任意键下一回合..."; _getch();
		if(playerHp <= 0){ over = true; break; }
	}
	system("cls");
	int baseGold = 15 + rpg_data.stage * 8;
	int gemDrop = 0;
	double goldRate = 1.0;
	if(playerHp <= 0){
		cout<<"战败!关卡重置,满血满蓝\n";
		rpg_data.stage = 1;
		rpg_data.hp = rpg_data.maxhp;
		rpg_data.mp = rpg_data.maxMp;
	}else{
		rpg_data.mp = rpg_data.maxMp;
		if(monster.eliteVal > 10){
			goldRate = 2.0;
			gemDrop = rand()%5 + 5;
			gemDrop = min(gemDrop, monster.eliteVal / 3);
		}else if(monster.eliteVal > 5){
			goldRate = 1.75;
			gemDrop = rand()%3 + 1;
		}else if(monster.eliteVal > 3){
			goldRate = 1.5;
			gemDrop = rand()%3;
		}
		int finalGold = baseGold * goldRate;
		rpg_data.gold += finalGold;
		rpg_data.gem += gemDrop;
		rpg_data.stage++;
		rpg_data.hp = playerHp;
		cout<<"胜利!法力完全恢复\n";
		cout<<"基础金币"<<baseGold<<" 倍率"<<goldRate<<" 获得"<<finalGold<<"\n";
		if(gemDrop>0)cout<<"宝石×"<<gemDrop<<"\n";
		if(monster.eliteVal>10)cout<<"【BOSS双倍金币+高宝石】\n";
		else if(monster.eliteVal>5)cout<<"【领主1.75倍+稳定宝石】\n";
		else if(monster.eliteVal>3)cout<<"【精英1.5倍+概率宝石】\n";
	}
	cout << "任意键返回角色面板..."; _getch();
}

// ===================== RPG主流程 =====================
void RpgGame() {
	rpgCurrentSlot = -1;
	while(true){
		system("cls");
		cout << "===== Crystal Skill Expedition v1.1.2 存档选择(共"<<RPG_SLOT_MAX<<"个)=====\n";
		cout << "1 创建全新角色\n";
		for(int i=1;i<=RPG_SLOT_MAX;i++){
			if(RpgSlotExist(i)){
				LoadRpg(i);
				cout<<i+1<<".存档"<<i<<"【"<<rpg_data.name<<"】\n";
			}else cout<<i+1<<".存档"<<i<<"(空白)\n";
		}
		cout<<"输入数字选择:";
		int sel; cin >> sel;
		if(sel == 1){
			RpgNewChar();
			cout<<"自定义角色名(回车留空):";
			cin.get();
			char nm[32]; cin.getline(nm,30);
			if(strlen(nm)) strcpy(rpg_data.name, nm);
			rpgCurrentSlot = -1;
			break;
		}else if(sel >= 2 && sel <= RPG_SLOT_MAX + 1){
			int sid = sel - 1;
			if(LoadRpg(sid)){
				rpgCurrentSlot = sid;
				break;
			}
			cout<<"存档为空,重选\n"; _getch();
		}else{ cout<<"输入无效\n"; _getch(); }
	}
	while(true){
		RpgDrawMain();
		char c = _getch();
		if(c == 27){
			if(rpgCurrentSlot != -1){
				SaveRpg(rpgCurrentSlot);
				cout<<"已保存至存档"<<rpgCurrentSlot<<"\n";
			}else{
				int empty = -1;
				for(int i=1;i<=RPG_SLOT_MAX;i++) if(!RpgSlotExist(i)){empty=i;break;}
				if(empty != -1){
					SaveRpg(empty);
					cout<<"自动保存至空白存档"<<empty<<"\n";
				}else{
					while(true){
						system("cls");
						cout<<"存档已满\n1放弃保存 2-"<<RPG_SLOT_MAX+1<<"覆盖存档\n";
						int op; cin >> op;
						if(op == 1) break;
						if(op >= 2 && op <= RPG_SLOT_MAX + 1){ SaveRpg(op-1); cout<<"已覆盖存档"<<op-1<<"\n"; break; }
					}
				}
			}
			cout<<"任意键回到存档选择\n"; _getch();
			return;
		}
		if(c == '1') RpgBattle();
		if(c == '2') RpgShop();
		if(c == '3') ShowAllSkill();
	}
}

// ===================== 程序入口 =====================
void init(){}
signed main() {
	srand((unsigned)time(nullptr));
	RpgGame();
	return 0;
}

v1.1.3

增加三个新技能。
新增一个怪物技能。
进行一些优化。

INFO
C++
//flpar
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <conio.h>
#include <Windows.h>
#include <algorithm>
#include <fstream>
#include <cstring>
#include <string>
using namespace std;

// ===================== RPG全局常量 =====================
const char RPG_SAVE_PREFIX[] = "rpg_slot";
const int RPG_SLOT_MAX = 10;
const int SKILL_PAGE_CNT = 8;

// 品质枚举 新增GOD_SKILL神技专属倍率
enum SkillQuality { WHITE, GREEN, BLUE, PURPLE, GOD_SKILL };
enum SkillID {
	SKILL_NONE,
	SKILL_POWERUP, SKILL_SHIELD, SKILL_LIFESTEAL, SKILL_SWAPHP, SKILL_BLOODDRAIN,
	SKILL_STUN, SKILL_CRIT, SKILL_POISON, SKILL_REFLECT, SKILL_RUSH,
	SKILL_HEALSELF, SKILL_WEAKEN, SKILL_SILENCE, SKILL_DOUBLEHIT, SKILL_IMMUNE,
	SKILL_DRAIN_MP,SKILL_MEDITATE,SKILL_OVERCHARGE,
	// 新增3个玩家技能
	SKILL_STOP_SHORT,    // 点到为止
	SKILL_GOLD_BURST,    // 豪掷千金
	SKILL_MONEY_LOVER    // 拜金
};
enum MonsterSkillID {
	MSKILL_NONE, MSKILL_IMPRISON_PLAYER, MSKILL_POISON, MSKILL_WEAK, MSKILL_DOUBLE_ATK,
	MSKILL_REVIVE // 新增怪物技能:卷土重来
};

// ===================== 存档工具 =====================
void GetRpgFileName(int slot, char buf[64]) { sprintf(buf, "%s%d.dat", RPG_SAVE_PREFIX, slot); }
bool RpgSlotExist(int slot) {
	char buf[64]; GetRpgFileName(slot, buf);
	ifstream f(buf, ios::binary); bool res = f.is_open(); f.close(); return res;
}

// ===================== 数据结构体 =====================
struct Skill {
	int id, quality;
	Skill() : id(SKILL_NONE), quality(WHITE) {}
	Skill(int i, int q) : id(i), quality(q) {}
};
struct RpgSaveData {
	char name[32];
	int hp, maxhp, atk, def, gold, stage;
	int skillCnt;
	Skill skills[20];
	int mp, maxMp, gem;
	int godSkillId;
} rpg_data;
struct MonsterSkill {
	int id, quality;
	bool reviveUsed; // 卷土重来复活标记
	MonsterSkill() : id(MSKILL_NONE), quality(WHITE), reviveUsed(false) {}
	MonsterSkill(int i,int q):id(i),quality(q),reviveUsed(false){}
};
struct MonsterTemp {
	int hp, maxhp, atk, def;
	int playerImprisonTurn;
	vector<MonsterSkill> ms;
	int eliteVal;
	bool revived; // 是否触发过卷土重来
} monster;

// 全局战斗变量
int buffAtk, buffDef, poisonDmg;
// 扩充技能蓝耗数组 适配新增3技能
int SkillMpBase[22] = {0,8,7,10,12,11,13,9,6,14,10,12,7,11,15,16,13,20,18,12,22,14};
int rpgCurrentSlot = -1;

// ===================== 存档读写 =====================
bool LoadRpg(int slot) {
	char buf[64]; GetRpgFileName(slot, buf);
	ifstream fin(buf, ios::binary);
	if (!fin.is_open()) return false;
	memset(&rpg_data, 0, sizeof(rpg_data));
	fin.read((char*)&rpg_data.name, 32);
	fin.read((char*)&rpg_data.hp, sizeof(int) * 7);
	fin.read((char*)&rpg_data.skills, sizeof(Skill) * 20);
	fin.close();
	if (rpg_data.maxMp == 0) rpg_data.maxMp = 50;
	rpg_data.mp = rpg_data.maxMp;
	return true;
}
void SaveRpg(int slot) {
	char buf[64]; GetRpgFileName(slot, buf);
	ofstream f(buf, ios::binary); f.write((char*)&rpg_data, sizeof(rpg_data)); f.close();
}
void RpgNewChar() {
	memset(rpg_data.name, 0, 32);
	rpg_data.hp = rpg_data.maxhp = 100;
	rpg_data.atk = 10; rpg_data.def = 5;
	rpg_data.gold = rpg_data.gem = rpg_data.stage = rpg_data.skillCnt = rpg_data.godSkillId = 0;
	memset(rpg_data.skills, 0, sizeof(rpg_data.skills));
	rpg_data.maxMp = rpg_data.mp = 50;
}

// ===================== 文本转换工具 =====================
string GetQualityStr(int q) {
	if(q==WHITE)return"白色";if(q==GREEN)return"绿色";if(q==BLUE)return"蓝色";
	if(q==PURPLE)return"紫色";if(q==GOD_SKILL)return"神技";return"未知品质";
}
string GetSkillName(int id) {
	switch(id){
		case SKILL_POWERUP:return"狂怒增幅";case SKILL_SHIELD:return"钢铁壁垒";
		case SKILL_LIFESTEAL:return"吸血打击";case SKILL_SWAPHP:return"生命置换";
		case SKILL_BLOODDRAIN:return"鲜血窃取";case SKILL_STUN:return"眩晕重击";
		case SKILL_CRIT:return"致命暴击";case SKILL_POISON:return"剧毒侵蚀";
		case SKILL_REFLECT:return"伤害反弹";case SKILL_RUSH:return"冲锋突袭";
		case SKILL_HEALSELF:return"自愈术";case SKILL_WEAKEN:return"衰弱诅咒";
		case SKILL_SILENCE:return"缄默封印";case SKILL_DOUBLEHIT:return"二段连击";
		case SKILL_IMMUNE:return"伤害免疫";
		case SKILL_DRAIN_MP:return"吸能打击";
		case SKILL_MEDITATE:return"静心冥想";
		case SKILL_OVERCHARGE:return"超负荷";
		case SKILL_STOP_SHORT:return"点到为止";
		case SKILL_GOLD_BURST:return"豪掷千金";
		case SKILL_MONEY_LOVER:return"拜金";
		default:return"未知";
	}
}
string GetMonsterSkillName(int id) {
	switch(id){
		case MSKILL_IMPRISON_PLAYER:return"禁锢(锁玩家2回合)";
		case MSKILL_POISON:return"毒伤";case MSKILL_WEAK:return"削弱攻防";
		case MSKILL_DOUBLE_ATK:return"双倍普攻";
		case MSKILL_REVIVE:return"卷土重来";
		default:return"无";
	}
}
int GetSkillMpCost(Skill s) {
	int base = SkillMpBase[s.id];
	double rate;
	if(s.quality==WHITE)rate=1.0;
	else if(s.quality==GREEN)rate=0.9;
	else if(s.quality==BLUE)rate=0.8;
	else if(s.quality==PURPLE)rate=0.7;
	else rate=1.0; // 神技固定10蓝 不走此计算
	return max(2, (int)(base * rate));
}

// ===================== 抽卡/商店/技能列表 =====================
void DrawSkill() {
	system("cls");
	cout << "抽技能 30金币/次,可能落空 金币:" << rpg_data.gold << "\n";
	if (rpg_data.gold < 30) { cout << "金币不足,任意键返回\n"; _getch(); return; }
	rpg_data.gold -= 30;
	Skill sk;
	if (rand() % 100 < 20) { cout << "抽空!本次无新技能\n"; }
	else {
		// 包含全部21个普通技能ID
		sk.id = rand() % 21 + 1;
		int r = rand() % 100;
		if(r<50)sk.quality=WHITE;else if(r<80)sk.quality=GREEN;else if(r<95)sk.quality=BLUE;else sk.quality=PURPLE;
		cout << "抽到【" << GetQualityStr(sk.quality) << "】" << GetSkillName(sk.id) << "\n";
		bool same = false;
		for (int i = 0; i < rpg_data.skillCnt; i++) {
			if (rpg_data.skills[i].id == sk.id) {
				same = true;
				if (sk.quality > rpg_data.skills[i].quality) {
					rpg_data.skills[i].quality = sk.quality;
					cout << "高品质覆盖原有技能\n";
				} else if (sk.quality == rpg_data.skills[i].quality && sk.quality < PURPLE) {
					rpg_data.skills[i].quality++;
					cout << "同品质技能进阶\n";
				} break;
			}
		}
		if (!same && rpg_data.skillCnt < 20) rpg_data.skills[rpg_data.skillCnt++] = sk;
		else if (!same) cout << "技能栏已满,无法获取\n";
	}
	cout << "任意键返回\n"; _getch();
}
void ShowAllSkill() {
	int page = 0;
	while (true) {
		system("cls");
		cout << "技能列表 A上一页 D下一页 0退出 每页" << SKILL_PAGE_CNT << "个\n";
		int st = page * SKILL_PAGE_CNT, ed = min(st + SKILL_PAGE_CNT, rpg_data.skillCnt);
		for (int i = st; i < ed; i++) {
			Skill s = rpg_data.skills[i];
			cout << i + 1 << "." << GetQualityStr(s.quality) << GetSkillName(s.id) << " 蓝耗:" << GetSkillMpCost(s) << "\n";
		}
		cout << "当前页" << page + 1 << " 输入按键:";
		char c = _getch();
		if (c == '0') break;
		if (c == 'a' && page > 0) page--;
		if (c == 'd' && ed < rpg_data.skillCnt) page++;
	}
}
int RefreshGemShopItem() { return rand() % 3; }
void RpgShop() {
	system("cls");
	int gemItem = RefreshGemShopItem();
	cout << "===== RPG商店 宝石:" << rpg_data.gem << " =====\n";
	cout << "[金币道具]\n1回满血(30金) 2攻击+5(50金) 3防御+3(40金) 4抽取技能(30金) 5蓝上限+20(80金)\n";
	cout << "[宝石限定道具]\n";
	if(gemItem==0)cout<<"6永久最大蓝量+50 消耗3宝石\n";
	else if(gemItem==1)cout<<"6随机神级技能 消耗5宝石\n";
	else cout<<"6全部技能品质+1 消耗4宝石\n";
	cout << "输入编号购买,0关闭商店:";
	int op; cin >> op;
	if(op==1&&rpg_data.gold>=30){rpg_data.gold-=30;rpg_data.hp=rpg_data.maxhp;cout<<"已回满生命值\n";}
	else if(op==2&&rpg_data.gold>=50){rpg_data.gold-=50;rpg_data.atk+=5;cout<<"攻击力永久+5\n";}
	else if(op==3&&rpg_data.gold>=40){rpg_data.gold-=40;rpg_data.def+=3;cout<<"防御力永久+3\n";}
	else if(op==4){DrawSkill();return;}
	else if(op==5&&rpg_data.gold>=80){rpg_data.gold-=80;rpg_data.maxMp+=20;rpg_data.mp=rpg_data.maxMp;cout<<"法力上限+20\n";}
	else if(op==6){
		if(gemItem==0&&rpg_data.gem>=3){rpg_data.gem-=3;rpg_data.maxMp+=50;cout<<"法力上限+50\n";}
		else if(gemItem==1&&rpg_data.gem>=5){
			rpg_data.gem-=5;
			rpg_data.godSkillId=rand()%21+1;
			cout<<"获得神技:"<<GetSkillName(rpg_data.godSkillId)<<"\n";
		}
		else if(gemItem==2&&rpg_data.gem>=4){
			rpg_data.gem-=4;
			for(int i=0;i<rpg_data.skillCnt;i++)if(rpg_data.skills[i].quality<PURPLE)rpg_data.skills[i].quality++;
			cout<<"所有技能品质提升一级\n";
		}else cout<<"宝石数量不足\n";
	}else if(op!=0)cout<<"金币数量不足\n";
	cout << "任意键返回\n"; _getch();
}

// ===================== 主界面绘制 =====================
void RpgDrawMain() {
	system("cls");
	cout << "Crystal Skill Expedition RPG v1.1.3 | ESC保存并返回存档选择 存档名:" << rpg_data.name << "\n";
	cout << "HP:" << rpg_data.hp << "/" << rpg_data.maxhp << " MP:" << rpg_data.mp << "/" << rpg_data.maxMp << "\n";
	cout << "ATK:" << rpg_data.atk << " DEF:" << rpg_data.def << " GEM:" << rpg_data.gem << "\n";
	cout << "GOLD:" << rpg_data.gold << " STAGE:" << rpg_data.stage << " 技能数:" << rpg_data.skillCnt;
	if(rpg_data.godSkillId)cout<<" 神技:"<<GetSkillName(rpg_data.godSkillId);
	cout << "\n1进入战斗 2打开商店 3查看全部技能\n";
}

// ===================== 战斗核心函数 =====================
void CastSkillEffect(int sid, int q, int &pHP, int &mHP, int mMaxHp) {
	// 品质倍率 神技固定2.0
	double mul = 1;
	if(q==WHITE)mul=1.00;
	if(q==GREEN)mul=1.20;
	if(q==BLUE)mul=1.45;
	if(q==PURPLE)mul=1.80;
	if(q==GOD_SKILL)mul=2.00;
	int dmg = (rpg_data.atk + buffAtk) * mul;
	switch(sid){
		case SKILL_POWERUP:buffAtk+=10*mul;cout<<"狂怒增幅 临时攻击力大幅提升\n";break;
		case SKILL_SHIELD:buffDef+=8*mul;cout<<"钢铁壁垒 临时防御力大幅提升\n";break;
		case SKILL_LIFESTEAL:{int h=dmg*0.4;mHP-=dmg;pHP+=h;cout<<"吸血打击 造成伤害并回复"<<h<<"生命值\n";break;}
		case SKILL_SWAPHP:{int t=pHP;pHP=mHP;mHP=t;cout<<"生命置换 与怪物互换当前血量\n";break;}
		case SKILL_BLOODDRAIN:{int steal=mHP*0.3*mul;mHP-=steal;pHP+=steal;cout<<"鲜血窃取 夺取怪物30%当前血量\n";break;}
		case SKILL_STUN:monster.playerImprisonTurn+=2*mul;mHP-=dmg;cout<<"眩晕重击 禁锢怪物"<<2*mul<<"回合\n";break;
		case SKILL_CRIT:mHP-=dmg*2;cout<<"致命暴击 双倍伤害\n";break;
		case SKILL_POISON:poisonDmg+=dmg*0.3;mHP-=dmg;cout<<"剧毒侵蚀 附加持续毒素伤害\n";break;
		case SKILL_REFLECT:{int ref=dmg*0.6;buffDef+=15*mul;mHP-=ref;cout<<"伤害反弹 反弹"<<ref<<"伤害,防御提升\n";break;}
		case SKILL_RUSH:mHP-=dmg*1.5;cout<<"冲锋突袭 1.5倍伤害\n";break;
		case SKILL_HEALSELF:{int h=rpg_data.maxhp*0.3*mul;pHP=min(pHP+h,rpg_data.maxhp);cout<<"自愈术 回复大量生命值\n";break;}
		case SKILL_WEAKEN:monster.atk-=3*mul;mHP-=dmg;cout<<"衰弱诅咒 降低怪物攻击力\n";break;
		case SKILL_SILENCE:monster.playerImprisonTurn+=2*mul;mHP-=dmg;cout<<"缄默封印 禁锢怪物\n";break;
		case SKILL_DOUBLEHIT:mHP-=dmg;mHP-=dmg*0.5;cout<<"二段连击 两段连续伤害\n";break;
		case SKILL_IMMUNE:buffDef+=30*mul;cout<<"伤害免疫 高额减伤buff\n";break;
		case SKILL_DRAIN_MP:{
			int stealMp = 8 * mul;
			rpg_data.mp = min(rpg_data.mp + stealMp, rpg_data.maxMp);
			mHP -= dmg;
			cout<<"吸能打击,造成伤害并恢复"<<stealMp<<"法力\n";
			break;
		}
		case SKILL_MEDITATE:{
			int medRecover = 25 * mul;
			rpg_data.mp = min(rpg_data.mp + medRecover, rpg_data.maxMp);
			cout<<"静心冥想,跳过本回合行动,恢复"<<medRecover<<"法力\n";
			break;
		}
		case SKILL_OVERCHARGE:{
			int extraCost = 12;
			rpg_data.mp -= extraCost;
			mHP -= dmg * 2.5;
			cout<<"超负荷,额外消耗"<<extraCost<<"蓝,打出2.5倍高额伤害\n";
			break;
		}
		// 新增1:点到为止
		case SKILL_STOP_SHORT:{
			int trueDmg = rpg_data.atk * 0.05 * mul;
			int normalDmg = rpg_data.atk * 1.2 * mul;
			int total = normalDmg + trueDmg;
			int realHit = min(total, mHP - 1); // 强制剩余1血
			mHP -= realHit;
			cout<<"点到为止!最多仅能将怪物打到剩余1点血量,本次造成"<<realHit<<"伤害\n";
			break;
		}
		// 新增2:豪掷千金
		case SKILL_GOLD_BURST:{
			cout<<"输入你要消耗的金币数量:";
			int costGold;cin>>costGold;
			if(costGold <=0 || rpg_data.gold < costGold){
				cout<<"金币不足或数值无效,技能失效\n";
				break;
			}
			rpg_data.gold -= costGold;
			int hit = costGold * 1.5 * rpg_data.atk * mul;
			mHP -= hit;
			cout<<"豪掷千金!消耗"<<costGold<<"金币,造成"<<hit<<"巨额伤害\n";
			break;
		}
		// 新增3:拜金
		case SKILL_MONEY_LOVER:{
			mHP -= 1;
			cout<<"拜金!固定造成1点真实伤害,若击杀怪物收益翻倍\n";
			break;
		}
		default:mHP-=dmg;
	}
}
void SpawnMonster() {
	monster.ms.clear();
	monster.playerImprisonTurn = poisonDmg = 0;
	monster.revived = false;
	monster.maxhp = 20 + rpg_data.stage * 12;
	monster.hp = monster.maxhp;
	monster.atk = 4 + rpg_data.stage * 3;
	monster.def = 3 + rpg_data.stage * 2;
	int skCnt = rand() % 4;
	monster.eliteVal = 0;
	vector<int> usedSkill; // 去重,同种怪物技能不重复生成
	bool addRevive = (rand()%100 < 25); // 25%概率带卷土重来
	if(addRevive){
		monster.ms.emplace_back(MSKILL_REVIVE,WHITE);
		monster.eliteVal +=5;
		usedSkill.push_back(MSKILL_REVIVE);
	}
	for(int i=0;i<skCnt;i++){
		MonsterSkill s;
		int sid;
		// 不重复生成已有技能
		do{
			sid = rand() % 4 + 1;
		}while(find(usedSkill.begin(),usedSkill.end(),sid)!=usedSkill.end());
		usedSkill.push_back(sid);
		s.id = sid;
		int r = rand() % 100;
		if(r<60){s.quality=WHITE;monster.eliteVal+=1;}
		else if(r<85){s.quality=GREEN;monster.eliteVal+=2;}
		else if(r<97){s.quality=BLUE;monster.eliteVal+=3;}
		else{s.quality=PURPLE;monster.eliteVal+=5;}
		monster.ms.push_back(s);
	}
}
// 获取怪物技能品质倍率
double GetMonsterMul(int q){
	if(q==WHITE)return 1.0;
	if(q==GREEN)return 1.2;
	if(q==BLUE)return 1.45;
	return 1.8;
}
void RpgBattle() {
	SpawnMonster();
	int playerHp = rpg_data.hp;
	buffAtk = buffDef = 0;
	bool over = false;
	bool moneyLoverKill = false; // 拜金击杀标记
	while (!over) {
		system("cls");
		cout << "第" << rpg_data.stage << "关战斗\n";
		cout << "玩家 HP:" << playerHp << "/" << rpg_data.maxhp << " MP:" << rpg_data.mp << "/" << rpg_data.maxMp << "\n";
		cout << "临时攻击+" << buffAtk << " 临时防御+" << buffDef << "\n";
		cout << "怪物 HP:" << monster.hp << "/" << monster.maxhp;
		if(monster.playerImprisonTurn>0)cout<<" 你被禁锢"<<monster.playerImprisonTurn<<"回合无法行动";
		cout << "\n精英值:" << monster.eliteVal;
		if(monster.eliteVal>10)cout<<"【BOSS】";
		else if(monster.eliteVal>5)cout<<"【领主】";
		else if(monster.eliteVal>3)cout<<"【精英】";
		cout << "\n怪物技能:";
		for(auto &s:monster.ms)cout<<GetMonsterSkillName(s.id)<<"("<<GetQualityStr(s.quality)<<") ";
		cout << "\n1普通攻击 2释放技能 3逃跑\n";
		char op = _getch();
		bool skipTurn = false;
		if(op=='3'){cout<<"逃跑无任何奖励,任意键返回\n";_getch();return;}
		if(monster.playerImprisonTurn>0){
			cout<<"禁锢状态无法行动,任意键跳过本回合\n";_getch();
			monster.playerImprisonTurn--;
		}else if(op=='1'){
			int dmg = max(1, (rpg_data.atk + buffAtk) - monster.def);
			monster.hp -= dmg;
			cout<<"普攻造成"<<dmg<<"点伤害\n";
		}else if(op=='2'){
			system("cls");
			cout << "选择要释放的技能(支持1~21两位数编号)\n";
			for(int i=0;i<rpg_data.skillCnt;i++){
				Skill s=rpg_data.skills[i];
				cout<<i+1<<"."<<GetQualityStr(s.quality)<<GetSkillName(s.id)<<" 消耗MP:"<<GetSkillMpCost(s)<<"\n";
			}
			if(rpg_data.godSkillId)cout<<"G释放神技(固定消耗10MP,倍率2.0)\n";
			cout << "输入数字释放,0返回战斗界面:";
			string selStr;
			cin >> selStr;
			if(selStr == "g" || selStr == "G"){
				if(rpg_data.mp>=10){
					rpg_data.mp -= 10;
					CastSkillEffect(rpg_data.godSkillId, GOD_SKILL, playerHp, monster.hp, monster.maxhp);
				}else cout<<"法力不足\n";
			}else{
				int sid = stoi(selStr);
				if(sid>=1&&sid<=rpg_data.skillCnt){
					Skill s = rpg_data.skills[sid-1];
					int cost = GetSkillMpCost(s);
					if(rpg_data.mp >= cost){
						rpg_data.mp -= cost;
						CastSkillEffect(s.id, s.quality, playerHp, monster.hp, monster.maxhp);
						if(s.id == SKILL_MONEY_LOVER) moneyLoverKill = true;
						if(s.id == SKILL_MEDITATE) skipTurn = true;
					}else cout<<"法力不足\n";
				}else if(sid != 0){
					cout<<"不存在该技能\n";
				}
			}
		}
		// 每回合结束自动恢复5点蓝
		rpg_data.mp = min(rpg_data.mp + 5, rpg_data.maxMp);
		cout << "\n回合结束,法力恢复5点 | 任意键怪物行动..."; _getch();
		if(poisonDmg>0){monster.hp -= poisonDmg; cout<<"毒素持续造成"<<poisonDmg<<"伤害\n";}
		// 检测卷土重来复活
		if(monster.hp <= 0 && !monster.revived){
			// 触发复活
			for(auto &sk : monster.ms){
				if(sk.id == MSKILL_REVIVE && !sk.reviveUsed){
					sk.reviveUsed = true;
					monster.revived = true;
					monster.hp = monster.maxhp;
					monster.maxhp *= 1.5;
					monster.atk *= 1.5;
					monster.def *= 1.5;
					cout<<"【卷土重来】怪物浴火重生,全属性提升至1.5倍!\n";
					monster.hp = monster.maxhp;
					break;
				}
			}
			if(monster.hp >0) continue;
		}
		if(monster.hp <= 0){ over = true; break; }
		// 冥想跳过怪物行动
		if(skipTurn){
			cout<<"冥想状态跳过怪物攻击\n";
			cout << "\n任意键进入下一回合..."; _getch();
			continue;
		}
		bool monsterUseSkill = false;
		if(!monster.ms.empty() && rand()%100 < 40){
			auto sk = monster.ms[rand()%monster.ms.size()];
			if(sk.id == MSKILL_REVIVE) goto monsterNormalAtk; // 复活被动,不主动释放
			monsterUseSkill = true;
			double mMul = GetMonsterMul(sk.quality);
			if(sk.id == MSKILL_IMPRISON_PLAYER){
				monster.playerImprisonTurn += 2*mMul;
				cout<<"怪物禁锢你"<<2*mMul<<"回合\n";
			}else if(sk.id == MSKILL_POISON){
				int dmg = monster.atk * 0.3 * mMul;
				playerHp -= dmg;
				cout<<"怪物毒伤,损失"<<dmg<<"生命值\n";
			}else if(sk.id == MSKILL_WEAK){
				buffAtk -= 4*mMul; buffDef -= 4*mMul;
				cout<<"你的临时攻防被削弱\n";
			}else if(sk.id == MSKILL_DOUBLE_ATK){
				int dmg = max(1.0, monster.atk * 2 * mMul - buffDef);
				playerHp -= dmg;
				cout<<"怪物双倍攻击,受到"<<dmg<<"伤害\n";
			}
		}
		monsterNormalAtk:
		if(!monsterUseSkill){
			int dmg = max(1, monster.atk - buffDef);
			playerHp -= dmg;
			cout<<"怪物普通攻击,受到"<<dmg<<"伤害\n";
		}
		cout << "\n任意键下一回合..."; _getch();
		if(playerHp <= 0){ over = true; break; }
	}
	system("cls");
	int baseGold = 15 + rpg_data.stage * 8;
	int gemDrop = 0;
	double goldRate = 1.0;
	if(playerHp <= 0){
		cout<<"战败!关卡重置为第1关,血量、法力全部回满\n";
		rpg_data.stage = 1;
		rpg_data.hp = rpg_data.maxhp;
		rpg_data.mp = rpg_data.maxMp;
	}else{
		rpg_data.mp = rpg_data.maxMp;
		if(monster.eliteVal > 10){
			goldRate = 2.0;
			gemDrop = rand()%5 + 5;
			gemDrop = min(gemDrop, monster.eliteVal / 3);
		}else if(monster.eliteVal > 5){
			goldRate = 1.75;
			gemDrop = rand()%3 + 1;
		}else if(monster.eliteVal > 3){
			goldRate = 1.5;
			gemDrop = rand()%3;
		}
		// 卷土重来二次击杀收益翻倍
		if(monster.revived){
			goldRate *= 2;
		}
		// 拜金击杀再翻倍
		if(moneyLoverKill){
			goldRate *=2;
		}
		int finalGold = baseGold * goldRate;
		rpg_data.gold += finalGold;
		rpg_data.gem += gemDrop;
		rpg_data.stage++;
		rpg_data.hp = playerHp;
		cout<<"战斗胜利!法力已完全恢复\n";
		cout<<"基础金币"<<baseGold<<" 总收益倍率"<<goldRate<<" 本次获得"<<finalGold<<"金币\n";
		if(gemDrop>0)cout<<"掉落宝石×"<<gemDrop<<"\n";
		if(monster.eliteVal>10)cout<<"【BOSS:基础双倍金币+高额宝石】\n";
		else if(monster.eliteVal>5)cout<<"【领主:基础1.75倍金币+稳定宝石】\n";
		else if(monster.eliteVal>3)cout<<"【精英:基础1.5倍金币+概率宝石】\n";
		if(monster.revived)cout<<"【怪物触发卷土重来,二次击杀收益再翻倍】\n";
		if(moneyLoverKill)cout<<"【拜金效果触发,击杀收益额外×2】\n";
	}
	cout << "任意键返回角色主界面..."; _getch();
}

// ===================== RPG主流程 =====================
void RpgGame() {
	rpgCurrentSlot = -1;
	while(true){
		system("cls");
		cout << "===== Crystal Skill Expedition v1.1.3 存档选择(共"<<RPG_SLOT_MAX<<"个)=====\n";
		cout << "1 创建全新角色\n";
		for(int i=1;i<=RPG_SLOT_MAX;i++){
			if(RpgSlotExist(i)){
				LoadRpg(i);
				cout<<i+1<<".存档"<<i<<" 【"<<rpg_data.name<<"】\n";
			}else cout<<i+1<<".存档"<<i<<" (空白)\n";
		}
		cout<<"输入数字选择:";
		int sel; cin >> sel;
		if(sel == 1){
			RpgNewChar();
			cout<<"自定义角色名称(直接回车留空):";
			cin.get();
			char nm[32]; cin.getline(nm,30);
			if(strlen(nm)) strcpy(rpg_data.name, nm);
			rpgCurrentSlot = -1;
			break;
		}else if(sel >= 2 && sel <= RPG_SLOT_MAX + 1){
			int sid = sel - 1;
			if(LoadRpg(sid)){
				rpgCurrentSlot = sid;
				break;
			}
			cout<<"该存档为空,请重新选择\n"; _getch();
		}else{ cout<<"输入数字无效\n"; _getch(); }
	}
	while(true){
		RpgDrawMain();
		char c = _getch();
		if(c == 27){
			if(rpgCurrentSlot != -1){
				SaveRpg(rpgCurrentSlot);
				cout<<"已自动保存至存档"<<rpgCurrentSlot<<"\n";
			}else{
				int empty = -1;
				for(int i=1;i<=RPG_SLOT_MAX;i++) if(!RpgSlotExist(i)){empty=i;break;}
				if(empty != -1){
					SaveRpg(empty);
					cout<<"自动保存至空白存档"<<empty<<"\n";
				}else{
					while(true){
						system("cls");
						cout<<"所有存档已满\n1放弃保存 2-"<<RPG_SLOT_MAX+1<<"覆盖对应存档\n";
						int op; cin >> op;
						if(op == 1) break;
						if(op >= 2 && op <= RPG_SLOT_MAX + 1){ SaveRpg(op-1); cout<<"已覆盖存档"<<op-1<<"\n"; break; }
					}
				}
			}
			cout<<"任意键回到存档选择界面\n"; _getch();
			return;
		}
		if(c == '1') RpgBattle();
		if(c == '2') RpgShop();
		if(c == '3') ShowAllSkill();
	}
}

// ===================== 程序入口 =====================
void init(){}
signed main() {
	srand((unsigned)time(nullptr));
	RpgGame();
	return 0;
}

v1.1.4

以后当前版本内容到图鉴查看。、

INFO
C++
//flpar
#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <conio.h>
#include <Windows.h>
#include <algorithm>
#include <fstream>
#include <cstring>
#include <string>
using namespace std;

// ===================== RPG全局常量 =====================
const char RPG_SAVE_PREFIX[] = "rpg_slot";
const int RPG_SLOT_MAX = 10;
const int SKILL_PAGE_CNT = 8;

// 品质枚举 新增GOD_SKILL神技专属倍率
enum SkillQuality { WHITE, GREEN, BLUE, PURPLE, GOD_SKILL };
enum SkillID {
	SKILL_NONE,
	SKILL_POWERUP, SKILL_SHIELD, SKILL_LIFESTEAL, SKILL_SWAPHP, SKILL_BLOODDRAIN,
	SKILL_STUN, SKILL_CRIT, SKILL_POISON, SKILL_REFLECT, SKILL_RUSH,
	SKILL_HEALSELF, SKILL_WEAKEN, SKILL_SILENCE, SKILL_DOUBLEHIT, SKILL_IMMUNE,
	SKILL_DRAIN_MP,SKILL_MEDITATE,SKILL_OVERCHARGE,
	// 新增3个玩家技能
	SKILL_STOP_SHORT,    // 点到为止
	SKILL_GOLD_BURST,    // 豪掷千金
	SKILL_MONEY_LOVER    // 拜金
};
enum MonsterSkillID {
	MSKILL_NONE, MSKILL_IMPRISON_PLAYER, MSKILL_POISON, MSKILL_WEAK, MSKILL_DOUBLE_ATK,
	MSKILL_REVIVE // 新增怪物技能:卷土重来
};

// ===================== 存档工具 =====================
void GetRpgFileName(int slot, char buf[64]) { sprintf(buf, "%s%d.dat", RPG_SAVE_PREFIX, slot); }
bool RpgSlotExist(int slot) {
	char buf[64]; GetRpgFileName(slot, buf);
	ifstream f(buf, ios::binary); bool res = f.is_open(); f.close(); return res;
}

// ===================== 数据结构体 =====================
struct Skill {
	int id, quality;
	Skill() : id(SKILL_NONE), quality(WHITE) {}
	Skill(int i, int q) : id(i), quality(q) {}
};
struct RpgSaveData {
	char name[32];
	int hp, maxhp, atk, def, gold, stage;
	int skillCnt;
	Skill skills[20];
	int mp, maxMp, gem;
	int godSkillId;
} rpg_data;
struct MonsterSkill {
	int id, quality;
	bool reviveUsed; // 卷土重来复活标记
	MonsterSkill() : id(MSKILL_NONE), quality(WHITE), reviveUsed(false) {}
	MonsterSkill(int i,int q):id(i),quality(q),reviveUsed(false){}
};
struct MonsterTemp {
	int hp, maxhp, atk, def;
	int playerImprisonTurn; // 怪物自身被禁锢回合
	vector<MonsterSkill> ms;
	int eliteVal;
	bool revived; // 是否触发过卷土重来
} monster;

// 全局战斗变量
int buffAtk, buffDef, poisonDmg;
int playerImprisonTurn; // 新增:玩家被禁锢回合
// 扩充技能蓝耗数组 适配新增3技能
int SkillMpBase[22] = {0,8,7,10,12,11,13,9,6,14,10,12,7,11,15,16,13,20,18,12,22,14};
int rpgCurrentSlot = -1;

// ===================== 存档读写 =====================
bool LoadRpg(int slot) {
	char buf[64]; GetRpgFileName(slot, buf);
	ifstream fin(buf, ios::binary);
	if (!fin.is_open()) return false;
	memset(&rpg_data, 0, sizeof(rpg_data));
	fin.read((char*)&rpg_data.name, 32);
	fin.read((char*)&rpg_data.hp, sizeof(int) * 7);
	fin.read((char*)&rpg_data.skills, sizeof(Skill) * 20);
	fin.close();
	if (rpg_data.maxMp == 0) rpg_data.maxMp = 50;
	rpg_data.mp = rpg_data.maxMp;
	return true;
}
void SaveRpg(int slot) {
	char buf[64]; GetRpgFileName(slot, buf);
	ofstream f(buf, ios::binary); f.write((char*)&rpg_data, sizeof(rpg_data)); f.close();
}
void RpgNewChar() {
	memset(rpg_data.name, 0, 32);
	rpg_data.hp = rpg_data.maxhp = 100;
	rpg_data.atk = 10; rpg_data.def = 5;
	rpg_data.gold = rpg_data.gem = rpg_data.stage = rpg_data.skillCnt = rpg_data.godSkillId = 0;
	memset(rpg_data.skills, 0, sizeof(rpg_data.skills));
	rpg_data.maxMp = rpg_data.mp = 50;
}

// ===================== 文本转换工具 =====================
string GetQualityStr(int q) {
	if(q==WHITE)return"白色";if(q==GREEN)return"绿色";if(q==BLUE)return"蓝色";
	if(q==PURPLE)return"紫色";if(q==GOD_SKILL)return"神技";return"未知品质";
}
string GetSkillName(int id) {
	switch(id){
		case SKILL_POWERUP:return"狂怒增幅";case SKILL_SHIELD:return"钢铁壁垒";
		case SKILL_LIFESTEAL:return"吸血打击";case SKILL_SWAPHP:return"生命置换";
		case SKILL_BLOODDRAIN:return"鲜血窃取";case SKILL_STUN:return"眩晕重击";
		case SKILL_CRIT:return"致命暴击";case SKILL_POISON:return"剧毒侵蚀";
		case SKILL_REFLECT:return"伤害反弹";case SKILL_RUSH:return"冲锋突袭";
		case SKILL_HEALSELF:return"自愈术";case SKILL_WEAKEN:return"衰弱诅咒";
		case SKILL_SILENCE:return"缄默封印";case SKILL_DOUBLEHIT:return"二段连击";
		case SKILL_IMMUNE:return"伤害免疫";
		case SKILL_DRAIN_MP:return"吸能打击";
		case SKILL_MEDITATE:return"静心冥想";
		case SKILL_OVERCHARGE:return"超负荷";
		case SKILL_STOP_SHORT:return"点到为止";
		case SKILL_GOLD_BURST:return"豪掷千金";
		case SKILL_MONEY_LOVER:return"拜金";
		default:return"未知";
	}
}
string GetMonsterSkillName(int id) {
	switch(id){
		case MSKILL_IMPRISON_PLAYER:return"禁锢(锁玩家2回合)";
		case MSKILL_POISON:return"毒伤";case MSKILL_WEAK:return"削弱攻防";
		case MSKILL_DOUBLE_ATK:return"双倍普攻";
		case MSKILL_REVIVE:return"卷土重来";
		default:return"无";
	}
}
int GetSkillMpCost(Skill s) {
	int base = SkillMpBase[s.id];
	double rate;
	if(s.quality==WHITE)rate=1.0;
	else if(s.quality==GREEN)rate=0.9;
	else if(s.quality==BLUE)rate=0.8;
	else if(s.quality==PURPLE)rate=0.7;
	else rate=1.0; // 神技固定10蓝 不走此计算
	return max(2, (int)(base * rate));
}

// ===================== 抽卡/商店/技能列表 =====================
void DrawSkill() {
	system("cls");
	cout << "抽技能 30金币/次,可能落空 金币:" << rpg_data.gold << "\n";
	if (rpg_data.gold < 30) { cout << "金币不足,任意键返回\n"; _getch(); return; }
	rpg_data.gold -= 30;
	Skill sk;
	if (rand() % 100 < 20) { cout << "抽空!本次无新技能\n"; }
	else {
		// 包含全部21个普通技能ID
		sk.id = rand() % 21 + 1;
		int r = rand() % 100;
		if(r<50)sk.quality=WHITE;else if(r<80)sk.quality=GREEN;else if(r<95)sk.quality=BLUE;else sk.quality=PURPLE;
		cout << "抽到【" << GetQualityStr(sk.quality) << "】" << GetSkillName(sk.id) << "\n";
		bool same = false;
		for (int i = 0; i < rpg_data.skillCnt; i++) {
			if (rpg_data.skills[i].id == sk.id) {
				same = true;
				if (sk.quality > rpg_data.skills[i].quality) {
					rpg_data.skills[i].quality = sk.quality;
					cout << "高品质覆盖原有技能\n";
				} else if (sk.quality == rpg_data.skills[i].quality && sk.quality < PURPLE) {
					rpg_data.skills[i].quality++;
					cout << "同品质技能进阶\n";
				} break;
			}
		}
		if (!same && rpg_data.skillCnt < 20) rpg_data.skills[rpg_data.skillCnt++] = sk;
		else if (!same) cout << "技能栏已满,无法获取\n";
	}
	cout << "任意键返回\n"; _getch();
}
void ShowAllSkill() {
	int page = 0;
	while (true) {
		system("cls");
		cout << "技能列表 A上一页 D下一页 0退出 每页" << SKILL_PAGE_CNT << "个\n";
		int st = page * SKILL_PAGE_CNT, ed = min(st + SKILL_PAGE_CNT, rpg_data.skillCnt);
		for (int i = st; i < ed; i++) {
			Skill s = rpg_data.skills[i];
			cout << i + 1 << "." << GetQualityStr(s.quality) << GetSkillName(s.id) << " 蓝耗:" << GetSkillMpCost(s) << "\n";
		}
		cout << "当前页" << page + 1 << " 输入按键:";
		char c = _getch();
		if (c == '0') break;
		if (c == 'a' && page > 0) page--;
		if (c == 'd' && ed < rpg_data.skillCnt) page++;
	}
}
int RefreshGemShopItem() { return rand() % 3; }
void RpgShop() {
	system("cls");
	int gemItem = RefreshGemShopItem();
	cout << "===== RPG商店 宝石:" << rpg_data.gem << " =====\n";
	cout << "[金币道具]\n1回满血(30金) 2攻击+5(50金) 3防御+3(40金) 4抽取技能(30金) 5蓝上限+20(80金)\n";
	cout << "[宝石限定道具]\n";
	if(gemItem==0)cout<<"6永久最大蓝量+50 消耗3宝石\n";
	else if(gemItem==1)cout<<"6随机神级技能 消耗5宝石\n";
	else cout<<"6全部技能品质+1 消耗4宝石\n";
	cout << "输入编号购买,0关闭商店:";
	int op; cin >> op;
	if(op==1&&rpg_data.gold>=30){rpg_data.gold-=30;rpg_data.hp=rpg_data.maxhp;cout<<"已回满生命值\n";}
	else if(op==2&&rpg_data.gold>=50){rpg_data.gold-=50;rpg_data.atk+=5;cout<<"攻击力永久+5\n";}
	else if(op==3&&rpg_data.gold>=40){rpg_data.gold-=40;rpg_data.def+=3;cout<<"防御力永久+3\n";}
	else if(op==4){DrawSkill();return;}
	else if(op==5&&rpg_data.gold>=80){rpg_data.gold-=80;rpg_data.maxMp+=20;rpg_data.mp=rpg_data.maxMp;cout<<"法力上限+20\n";}
	else if(op==6){
		if(gemItem==0&&rpg_data.gem>=3){rpg_data.gem-=3;rpg_data.maxMp+=50;cout<<"法力上限+50\n";}
		else if(gemItem==1&&rpg_data.gem>=5){
			rpg_data.gem-=5;
			rpg_data.godSkillId=rand()%21+1;
			cout<<"获得神技:"<<GetSkillName(rpg_data.godSkillId)<<"\n";
		}
		else if(gemItem==2&&rpg_data.gem>=4){
			rpg_data.gem-=4;
			for(int i=0;i<rpg_data.skillCnt;i++)if(rpg_data.skills[i].quality<PURPLE)rpg_data.skills[i].quality++;
			cout<<"所有技能品质提升一级\n";
		}else cout<<"宝石数量不足\n";
	}else if(op!=0)cout<<"金币数量不足\n";
	cout << "任意键返回\n"; _getch();
}

// ===================== 主界面绘制 =====================
void RpgDrawMain() {
	system("cls");
	cout << "Crystal Skill Expedition RPG v1.1.4 | ESC保存并返回存档选择 存档名:" << rpg_data.name << "\n";
	cout << "HP:" << rpg_data.hp << "/" << rpg_data.maxhp << " MP:" << rpg_data.mp << "/" << rpg_data.maxMp << "\n";
	cout << "ATK:" << rpg_data.atk << " DEF:" << rpg_data.def << " GEM:" << rpg_data.gem << "\n";
	cout << "GOLD:" << rpg_data.gold << " STAGE:" << rpg_data.stage << " 技能数:" << rpg_data.skillCnt;
	if(rpg_data.godSkillId)cout<<" 神技:"<<GetSkillName(rpg_data.godSkillId);
	cout << "\n1进入战斗 2打开商店 3查看全部技能\n";
}

// ===================== 战斗核心函数 =====================
void CastSkillEffect(int sid, int q, int &pHP, int &mHP, int mMaxHp) {
	// 品质倍率 神技固定2.0
	double mul = 1;
	if(q==WHITE)mul=1.00;
	if(q==GREEN)mul=1.20;
	if(q==BLUE)mul=1.45;
	if(q==PURPLE)mul=1.80;
	if(q==GOD_SKILL)mul=2.00;
	int dmg = (rpg_data.atk + buffAtk) * mul;
	switch(sid){
		case SKILL_POWERUP:buffAtk+=10*mul;cout<<"狂怒增幅 临时攻击力大幅提升\n";break;
		case SKILL_SHIELD:buffDef+=8*mul;cout<<"钢铁壁垒 临时防御力大幅提升\n";break;
		case SKILL_LIFESTEAL:{int h=dmg*0.4;mHP-=dmg;pHP+=h;cout<<"吸血打击 造成伤害并回复"<<h<<"生命值\n";break;}
		case SKILL_SWAPHP:{int t=pHP;pHP=mHP;mHP=t;cout<<"生命置换 与怪物互换当前血量\n";break;}
		case SKILL_BLOODDRAIN:{int steal=mHP*0.3*mul;mHP-=steal;pHP+=steal;cout<<"鲜血窃取 夺取怪物30%当前血量\n";break;}
		// 玩家眩晕重击:禁锢怪物(monster.playerImprisonTurn)正确
		case SKILL_STUN:monster.playerImprisonTurn+=2*mul;mHP-=dmg;cout<<"眩晕重击 禁锢怪物"<<2*mul<<"回合\n";break;
		case SKILL_CRIT:mHP-=dmg*2;cout<<"致命暴击 双倍伤害\n";break;
		case SKILL_POISON:poisonDmg+=dmg*0.3;mHP-=dmg;cout<<"剧毒侵蚀 附加持续毒素伤害\n";break;
		case SKILL_REFLECT:{int ref=dmg*0.6;buffDef+=15*mul;mHP-=ref;cout<<"伤害反弹 反弹"<<ref<<"伤害,防御提升\n";break;}
		case SKILL_RUSH:mHP-=dmg*1.5;cout<<"冲锋突袭 1.5倍伤害\n";break;
		case SKILL_HEALSELF:{int h=rpg_data.maxhp*0.3*mul;pHP=min(pHP+h,rpg_data.maxhp);cout<<"自愈术 回复大量生命值\n";break;}
		case SKILL_WEAKEN:monster.atk-=3*mul;mHP-=dmg;cout<<"衰弱诅咒 降低怪物攻击力\n";break;
		// 玩家缄默封印:禁锢怪物,不影响玩家
		case SKILL_SILENCE:monster.playerImprisonTurn+=2*mul;mHP-=dmg;cout<<"缄默封印 禁锢怪物\n";break;
		case SKILL_DOUBLEHIT:mHP-=dmg;mHP-=dmg*0.5;cout<<"二段连击 两段连续伤害\n";break;
		case SKILL_IMMUNE:buffDef+=30*mul;cout<<"伤害免疫 高额减伤buff\n";break;
		case SKILL_DRAIN_MP:{
			int stealMp = 8 * mul;
			rpg_data.mp = min(rpg_data.mp + stealMp, rpg_data.maxMp);
			mHP -= dmg;
			cout<<"吸能打击,造成伤害并恢复"<<stealMp<<"法力\n";
			break;
		}
		case SKILL_MEDITATE:{
			int medRecover = 25 * mul;
			rpg_data.mp = min(rpg_data.mp + medRecover, rpg_data.maxMp);
			cout<<"静心冥想,跳过本回合行动,恢复"<<medRecover<<"法力\n";
			break;
		}
		case SKILL_OVERCHARGE:{
			int extraCost = 12;
			rpg_data.mp -= extraCost;
			mHP -= dmg * 2.5;
			cout<<"超负荷,额外消耗"<<extraCost<<"蓝,打出2.5倍高额伤害\n";
			break;
		}
		// 新增1:点到为止
		case SKILL_STOP_SHORT:{
			int trueDmg = rpg_data.atk * 0.05 * mul;
			int normalDmg = rpg_data.atk * 1.2 * mul;
			int total = normalDmg + trueDmg;
			int realHit = min(total, mHP - 1); // 强制剩余1血
			mHP -= realHit;
			cout<<"点到为止!最多仅能将怪物打到剩余1点血量,本次造成"<<realHit<<"伤害\n";
			break;
		}
		// 新增2:豪掷千金
		case SKILL_GOLD_BURST:{
			cout<<"输入你要消耗的金币数量:";
			int costGold;cin>>costGold;
			if(costGold <=0 || rpg_data.gold < costGold){
				cout<<"金币不足或数值无效,技能失效\n";
				break;
			}
			rpg_data.gold -= costGold;
			int hit = costGold * 1.5 * rpg_data.atk * mul;
			mHP -= hit;
			cout<<"豪掷千金!消耗"<<costGold<<"金币,造成"<<hit<<"巨额伤害\n";
			break;
		}
		// 新增3:拜金
		case SKILL_MONEY_LOVER:{
			mHP -= 1;
			cout<<"拜金!固定造成1点真实伤害,若击杀怪物收益翻倍\n";
			break;
		}
		default:mHP-=dmg;
	}
}
void SpawnMonster() {
	monster.ms.clear();
	monster.playerImprisonTurn = poisonDmg = 0;
	playerImprisonTurn = 0; // 重置玩家禁锢
	monster.revived = false;
	monster.maxhp = 20 + rpg_data.stage * 12;
	monster.hp = monster.maxhp;
	monster.atk = 4 + rpg_data.stage * 3;
	monster.def = 3 + rpg_data.stage * 2;
	int skCnt = rand() % 4;
	monster.eliteVal = 0;
	vector<int> usedSkill; // 去重,同种怪物技能不重复生成
	bool addRevive = (rand()%100 < 25); // 25%概率带卷土重来
	if(addRevive){
		monster.ms.emplace_back(MSKILL_REVIVE,WHITE);
		monster.eliteVal +=5;
		usedSkill.push_back(MSKILL_REVIVE);
	}
	for(int i=0;i<skCnt;i++){
		MonsterSkill s;
		int sid;
		// 不重复生成已有技能
		do{
			sid = rand() % 4 + 1;
		}while(find(usedSkill.begin(),usedSkill.end(),sid)!=usedSkill.end());
		usedSkill.push_back(sid);
		s.id = sid;
		int r = rand() % 100;
		if(r<60){s.quality=WHITE;monster.eliteVal+=1;}
		else if(r<85){s.quality=GREEN;monster.eliteVal+=2;}
		else if(r<97){s.quality=BLUE;monster.eliteVal+=3;}
		else{s.quality=PURPLE;monster.eliteVal+=5;}
		monster.ms.push_back(s);
	}
}
// 获取怪物技能品质倍率
double GetMonsterMul(int q){
	if(q==WHITE)return 1.0;
	if(q==GREEN)return 1.2;
	if(q==BLUE)return 1.45;
	return 1.8;
}
void RpgBattle() {
	SpawnMonster();
	int playerHp = rpg_data.hp;
	buffAtk = buffDef = 0;
	bool over = false;
	bool moneyLoverKill = false; // 拜金击杀标记
	while (!over) {
		system("cls");
		cout << "第" << rpg_data.stage << "关战斗\n";
		cout << "玩家 HP:" << playerHp << "/" << rpg_data.maxhp << " MP:" << rpg_data.mp << "/" << rpg_data.maxMp << "\n";
		cout << "临时攻击+" << buffAtk << " 临时防御+" << buffDef << "\n";
		cout << "怪物 HP:" << monster.hp << "/" << monster.maxhp;
		if(monster.playerImprisonTurn>0)cout<<" 怪物被禁锢"<<monster.playerImprisonTurn<<"回合";
		if(playerImprisonTurn>0)cout<<" 你被禁锢"<<playerImprisonTurn<<"回合无法行动";
		cout << "\n精英值:" << monster.eliteVal;
		if(monster.eliteVal>10)cout<<"【BOSS】";
		else if(monster.eliteVal>5)cout<<"【领主】";
		else if(monster.eliteVal>3)cout<<"【精英】";
		cout << "\n怪物技能:";
		for(auto &s:monster.ms)cout<<GetMonsterSkillName(s.id)<<"("<<GetQualityStr(s.quality)<<") ";
		cout << "\n1普通攻击 2释放技能 3逃跑\n";
		char op = _getch();
		bool skipTurn = false;
		if(op=='3'){cout<<"逃跑无任何奖励,任意键返回\n";_getch();return;}
		// 判断玩家禁锢(怪物技能禁锢玩家)
		if(playerImprisonTurn>0){
			cout<<"禁锢状态无法行动,任意键跳过本回合\n";_getch();
			playerImprisonTurn--;
		}else if(op=='1'){
			int dmg = max(1, (rpg_data.atk + buffAtk) - monster.def);
			monster.hp -= dmg;
			cout<<"普攻造成"<<dmg<<"点伤害\n";
		}else if(op=='2'){
			system("cls");
			cout << "选择要释放的技能(支持1~21两位数编号)\n";
			for(int i=0;i<rpg_data.skillCnt;i++){
				Skill s=rpg_data.skills[i];
				cout<<i+1<<"."<<GetQualityStr(s.quality)<<GetSkillName(s.id)<<" 消耗MP:"<<GetSkillMpCost(s)<<"\n";
			}
			if(rpg_data.godSkillId)cout<<"G释放神技(固定消耗10MP,倍率2.0)\n";
			cout << "输入数字释放,0返回战斗界面:";
			string selStr;
			cin >> selStr;
			if(selStr == "g" || selStr == "G"){
				if(rpg_data.mp>=10){
					rpg_data.mp -= 10;
					CastSkillEffect(rpg_data.godSkillId, GOD_SKILL, playerHp, monster.hp, monster.maxhp);
				}else cout<<"法力不足\n";
			}else{
				int sid = stoi(selStr);
				if(sid>=1&&sid<=rpg_data.skillCnt){
					Skill s = rpg_data.skills[sid-1];
					int cost = GetSkillMpCost(s);
					if(rpg_data.mp >= cost){
						rpg_data.mp -= cost;
						CastSkillEffect(s.id, s.quality, playerHp, monster.hp, monster.maxhp);
						if(s.id == SKILL_MONEY_LOVER) moneyLoverKill = true;
						if(s.id == SKILL_MEDITATE) skipTurn = true;
					}else cout<<"法力不足\n";
				}else if(sid != 0){
					cout<<"不存在该技能\n";
				}
			}
		}
		// 每回合结束自动恢复5点蓝
		rpg_data.mp = min(rpg_data.mp + 5, rpg_data.maxMp);
		cout << "\n回合结束,法力恢复5点 | 任意键怪物行动..."; _getch();
		if(poisonDmg>0){monster.hp -= poisonDmg; cout<<"毒素持续造成"<<poisonDmg<<"伤害\n";}
		// 检测卷土重来复活
		if(monster.hp <= 0 && !monster.revived){
			// 触发复活
			for(auto &sk : monster.ms){
				if(sk.id == MSKILL_REVIVE && !sk.reviveUsed){
					sk.reviveUsed = true;
					monster.revived = true;
					monster.hp = monster.maxhp;
					monster.maxhp *= 1.5;
					monster.atk *= 1.5;
					monster.def *= 1.5;
					cout<<"【卷土重来】怪物浴火重生,全属性提升至1.5倍!\n";
					monster.hp = monster.maxhp;
					break;
				}
			}
			if(monster.hp >0) continue;
		}
		if(monster.hp <= 0){ over = true; break; }
		// 冥想跳过怪物行动
		if(skipTurn){
			cout<<"冥想状态跳过怪物攻击\n";
			cout << "\n任意键进入下一回合..."; _getch();
			continue;
		}
		bool monsterUseSkill = false;
		if(!monster.ms.empty() && rand()%100 < 40){
			auto sk = monster.ms[rand()%monster.ms.size()];
			if(sk.id == MSKILL_REVIVE) goto monsterNormalAtk; // 复活被动,不主动释放
			monsterUseSkill = true;
			double mMul = GetMonsterMul(sk.quality);
			if(sk.id == MSKILL_IMPRISON_PLAYER){
				// 怪物禁锢技能 → 禁锢玩家(playerImprisonTurn)修复完成
				playerImprisonTurn += 2*mMul;
				cout<<"怪物禁锢你"<<2*mMul<<"回合\n";
			}else if(sk.id == MSKILL_POISON){
				int dmg = monster.atk * 0.3 * mMul;
				playerHp -= dmg;
				cout<<"怪物毒伤,损失"<<dmg<<"生命值\n";
			}else if(sk.id == MSKILL_WEAK){
				buffAtk -= 4*mMul; buffDef -= 4*mMul;
				cout<<"你的临时攻防被削弱\n";
			}else if(sk.id == MSKILL_DOUBLE_ATK){
				int dmg = max(1.0, monster.atk * 2 * mMul - buffDef);
				playerHp -= dmg;
				cout<<"怪物双倍攻击,受到"<<dmg<<"伤害\n";
			}
		}
		monsterNormalAtk:
		if(!monsterUseSkill){
			int dmg = max(1, monster.atk - buffDef);
			playerHp -= dmg;
			cout<<"怪物普通攻击,受到"<<dmg<<"伤害\n";
		}
		cout << "\n任意键下一回合..."; _getch();
		if(playerHp <= 0){ over = true; break; }
	}
	system("cls");
	int baseGold = 15 + rpg_data.stage * 8;
	int gemDrop = 0;
	double goldRate = 1.0;
	if(playerHp <= 0){
		cout<<"战败!关卡重置为第1关,血量、法力全部回满\n";
		rpg_data.stage = 1;
		rpg_data.hp = rpg_data.maxhp;
		rpg_data.mp = rpg_data.maxMp;
	}else{
		rpg_data.mp = rpg_data.maxMp;
		if(monster.eliteVal > 10){
			goldRate = 2.0;
			gemDrop = rand()%5 + 5;
			gemDrop = min(gemDrop, monster.eliteVal / 3);
		}else if(monster.eliteVal > 5){
			goldRate = 1.75;
			gemDrop = rand()%3 + 1;
		}else if(monster.eliteVal > 3){
			goldRate = 1.5;
			gemDrop = rand()%3;
		}
		// 卷土重来二次击杀收益翻倍
		if(monster.revived){
			goldRate *= 2;
		}
		// 拜金击杀再翻倍
		if(moneyLoverKill){
			goldRate *=2;
		}
		int finalGold = baseGold * goldRate;
		rpg_data.gold += finalGold;
		rpg_data.gem += gemDrop;
		rpg_data.stage++;
		rpg_data.hp = playerHp;
		cout<<"战斗胜利!法力已完全恢复\n";
		cout<<"基础金币"<<baseGold<<" 总收益倍率"<<goldRate<<" 本次获得"<<finalGold<<"金币\n";
		if(gemDrop>0)cout<<"掉落宝石×"<<gemDrop<<"\n";
		if(monster.eliteVal>10)cout<<"【BOSS:基础双倍金币+高额宝石】\n";
		else if(monster.eliteVal>5)cout<<"【领主:基础1.75倍金币+稳定宝石】\n";
		else if(monster.eliteVal>3)cout<<"【精英:基础1.5倍金币+概率宝石】\n";
		if(monster.revived)cout<<"【怪物触发卷土重来,二次击杀收益再翻倍】\n";
		if(moneyLoverKill)cout<<"【拜金效果触发,击杀收益额外×2】\n";
	}
	cout << "任意键返回角色主界面..."; _getch();
}

// ===================== RPG主流程 =====================
void RpgGame() {
	rpgCurrentSlot = -1;
	while(true){
		system("cls");
		cout << "===== Crystal Skill Expedition v1.1.4 存档选择(共"<<RPG_SLOT_MAX<<"个)=====\n";
		cout << "1 创建全新角色\n";
		for(int i=1;i<=RPG_SLOT_MAX;i++){
			if(RpgSlotExist(i)){
				LoadRpg(i);
				cout<<i+1<<".存档"<<i<<" 【"<<rpg_data.name<<"】\n";
			}else cout<<i+1<<".存档"<<i<<" (空白)\n";
		}
		cout<<"输入数字选择:";
		int sel; cin >> sel;
		if(sel == 1){
			RpgNewChar();
			cout<<"自定义角色名称(直接回车留空):";
			cin.get();
			char nm[32]; cin.getline(nm,30);
			if(strlen(nm)) strcpy(rpg_data.name, nm);
			rpgCurrentSlot = -1;
			break;
		}else if(sel >= 2 && sel <= RPG_SLOT_MAX + 1){
			int sid = sel - 1;
			if(LoadRpg(sid)){
				rpgCurrentSlot = sid;
				break;
			}
			cout<<"该存档为空,请重新选择\n"; _getch();
		}else{ cout<<"输入数字无效\n"; _getch(); }
	}
	while(true){
		RpgDrawMain();
		char c = _getch();
		if(c == 27){
			if(rpgCurrentSlot != -1){
				SaveRpg(rpgCurrentSlot);
				cout<<"已自动保存至存档"<<rpgCurrentSlot<<"\n";
			}else{
				int empty = -1;
				for(int i=1;i<=RPG_SLOT_MAX;i++) if(!RpgSlotExist(i)){empty=i;break;}
				if(empty != -1){
					SaveRpg(empty);
					cout<<"自动保存至空白存档"<<empty<<"\n";
				}else{
					while(true){
						system("cls");
						cout<<"所有存档已满\n1放弃保存 2-"<<RPG_SLOT_MAX+1<<"覆盖对应存档\n";
						int op; cin >> op;
						if(op == 1) break;
						if(op >= 2 && op <= RPG_SLOT_MAX + 1){ SaveRpg(op-1); cout<<"已覆盖存档"<<op-1<<"\n"; break; }
					}
				}
			}
			cout<<"任意键回到存档选择界面\n"; _getch();
			return;
		}
		if(c == '1') RpgBattle();
		if(c == '2') RpgShop();
		if(c == '3') ShowAllSkill();
	}
}

// ===================== 程序入口 =====================
void init(){}
signed main() {
	srand((unsigned)time(nullptr));
	RpgGame();
	return 0;
}
原文