//运行前请加入-O2 -lm -std=c++14
//赌徒狂欢1.9
#include <iostream>
#include <string>
#include <cstdlib>
#include<vector>
#include<algorithm>
#include <ctime>
#include<windows.h>
#include<iomanip>
// 替换Windows特定功能
#ifdef _WIN32
#include <windows.h>
#else
// 提供Linux/macOS的替代实现
#endif


using namespace std;
namespace dj {
	bool axj(long long key) {
		return (GetKeyState(key) < 0) ? (true) : (false);
	}
	struct hl {
		long long h,l;
	};
	void de(int x) {
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),x);
	}
	bool ax(long long key) {
		return (GetKeyState(key) < 0) ? (true) : (false);
	}
	hl wz(bool x = 1, bool n = 1) {
		HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
		HWND h = GetForegroundWindow();
		CONSOLE_FONT_INFO consoleCurrentFont;
		hl hl;
		POINT p;
		if (x) {
			GetCursorPos(&p);
			ScreenToClient(h, &p);
		} else {
			GetCursorPos(&p);
		}
		if (n) {
			GetCurrentConsoleFont(hOutput, FALSE, &consoleCurrentFont);
			p.x /= consoleCurrentFont.dwFontSize.X;
			p.y /= consoleCurrentFont.dwFontSize.Y;
		}
		hl.h = p.y + 1;
		hl.l = p.x + 1;
		return hl;
	}
	void ycbj() {
		HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
		DWORD mode;
		GetConsoleMode(hStdin, &mode);
		mode &= ~ENABLE_QUICK_EDIT_MODE;
		SetConsoleMode(hStdin, mode);
		return;
	}
	void ycgb() {
		CONSOLE_CURSOR_INFO cursor;
		cursor.bVisible = FALSE;
		cursor.dwSize = sizeof(cursor);
		HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
		SetConsoleCursorInfo(handle, &cursor);
		return;
	}
	inline void ydgb(long long h, long long l) {
		COORD pos = { l - 1,h - 1 };
		HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
		SetConsoleCursorPosition(hOut, pos);
		return;
	}
	bool pdbj(int y,int x,int x1,int x2,int ys,string zt) {
		ycgb();
		ycbj();
		hl z=wz(1,1);
		bool a=0;
		if(z.h==y&&z.l>=x1&&z.l<=x2) {
			ydgb(y,x);
			de(ys*16);
			cout<<zt;
			de(ys);
			if(axj(VK_LBUTTON)) {
				a=1;
			}
		} else {
			ydgb(y,x);
			de(ys);
			cout<<zt;
		}
		de(15);
		return a;
	}
};
using namespace dj;//一定要有
long long f=200;
int a,b,ans,k,x,water,jwine,swine,horses;
bool blog=1,xingshoupanduan=1;
bool developerMode = false;  // 开发者模式开关
string devPassword = "9178mod";  // 开发者密码

void horseRacing() {
	system("cls");

	// 检查余额
	if(f < 10) {
		cout << "余额不足,至少需要10元才能参与赌马!" << endl;
		Sleep(1500);
		return;
	}

	// 显示马匹和赔率
	cout << "======= 赌马模式 =======" << endl;
	cout << "当前余额: " << f << " 元" << endl;
	cout << "选择你要下注的马匹 (1-4号):" << endl;
	cout << "1号马: 赤兔 (红色)" << endl;
	cout << "2号马: 的卢 (蓝色)" << endl;
	cout << "3号马: 绝影 (绿色)" << endl;
	cout << "4号马: 乌骓 (黄色)" << endl;
	cout << "赔率: 获胜马匹下注者获得4倍赌注" << endl;
	cout << "=========================" << endl;

	// 选择马匹
	int selectedHorse = 0;
	while(selectedHorse < 1 || selectedHorse > 4) {
		cout << "请选择马匹编号 (1-4): ";
		cin >> selectedHorse;
		if(selectedHorse < 1 || selectedHorse > 4) {
			cout << "无效选择,请重新输入!" << endl;
		}
	}

	// 下注金额
	long long betAmount = 0;
	while(betAmount < 10 || betAmount > f) {
		cout << "请输入下注金额 (最低10元,最高" << f << "元): ";
		cin >> betAmount;
		if(betAmount < 10) {
			cout << "下注金额不能低于10元!" << endl;
		} else if(betAmount > f) {
			cout << "余额不足!" << endl;
		}
	}

	// 扣除赌注
	f -= betAmount;

	system("cls");
	cout << "下注成功!你选择了" << selectedHorse << "号马,下注" << betAmount << "元" << endl;
	cout << "比赛即将开始..." << endl;
	Sleep(2000);

	// 初始化马匹位置和速度
	int horsePositions[4] = {0, 0, 0, 0};  // 马匹当前位置
	int horseSpeeds[4];                    // 马匹速度(每轮前进的步数)
	const int trackLength = 50;            // 赛道长度

	// 随机生成马匹基础速度(有一定随机性)
	srand(time(0));
	for(int i = 0; i < 4; i++) {
		horseSpeeds[i] = rand() % 3 + 2;  // 速度在2-4之间
	}

	// 比赛开始
	system("cls");
	cout << "====== 比赛开始!======" << endl;
	cout << "赛道长度: " << trackLength << " 米" << endl;
	cout << "你的选择: " << selectedHorse << "号马" << endl;
	cout << "=========================" << endl << endl;

	bool raceFinished = false;
	int winner = -1;
	int round = 1;

	while(!raceFinished) {
		// 清空赛道显示区域
		ydgb(6, 1);

		// 更新每匹马的位置
		for(int i = 0; i < 4; i++) {
			// 每匹马有一定概率加速或减速
			int speedVariation = rand() % 3 - 1;  // -1, 0, 1
			int currentSpeed = max(1, horseSpeeds[i] + speedVariation);
			horsePositions[i] += currentSpeed;

			// 确保不超过终点
			if(horsePositions[i] >= trackLength) {
				horsePositions[i] = trackLength;
				if(!raceFinished) {
					raceFinished = true;
					winner = i + 1;  // 马匹编号是1-4
				}
			}
		}

		// 显示当前赛道状态
		for(int i = 0; i < 4; i++) {
			// 设置颜色
			switch(i) {
				case 0:
					de(12);
					break;  // 红色
				case 1:
					de(9);
					break;   // 蓝色
				case 2:
					de(10);
					break;  // 绿色
				case 3:
					de(14);
					break;  // 黄色
			}

			cout << i+1 << "号马: ";

			// 绘制赛道
			for(int j = 0; j < trackLength; j++) {
				if(j < horsePositions[i]) {
					cout << "=";
				} else if(j == horsePositions[i]) {
					// 马匹当前位置
					switch(i) {
						case 0:
							cout << "赤";
							break;
						case 1:
							cout << "的";
							break;
						case 2:
							cout << "绝";
							break;
						case 3:
							cout << "乌";
							break;
					}
				} else {
					cout << "-";
				}
			}

			// 显示进度百分比
			cout << " " << min(100, (horsePositions[i] * 100 / trackLength)) << "%";

			// 如果是玩家选择的马匹,特别标注
			if(i + 1 == selectedHorse) {
				cout << " <-- 你的选择";
			}

			cout << endl;
			de(15);  // 恢复默认颜色
		}

		// 显示当前轮次
		cout << endl << "第 " << round << " 轮" << endl;

		// 如果有马到达终点
		if(raceFinished) {
			cout << endl;
			de(10);
			cout << "比赛结束!" << endl;
			de(15);
			system("cls");
			break;
		}

		round++;
		Sleep(500);  // 每轮之间的延迟

		// 每3轮清屏一次,避免画面混乱
		if(round % 3 == 0) {
			ydgb(6, 1);
			for(int i = 0; i < 10; i++) {
				cout << "                                                                                " << endl;
			}
			ydgb(6, 1);
		}
	}

	// 显示比赛结果
	Sleep(1000);
	system("cls");

	cout << "====== 比赛结果 ======" << endl;
	cout << "冠军: " << winner << "号马!" << endl;
	cout << "你的选择: " << selectedHorse << "号马" << endl;
	cout << "下注金额: " << betAmount << "元" << endl;
	cout << "=======================" << endl << endl;

	// 计算奖励
	if(winner == selectedHorse) {
		long long winnings = betAmount * 4;  // 4倍赔率
		f += winnings;

		de(10);
		cout << "恭喜你!你选择的" << selectedHorse << "号马获胜!" << endl;
		cout << "获得奖金: " << winnings << " 元" << endl;
		cout << "当前余额: " << f << " 元" << endl;
		de(15);
		horses+=1;
		if(horses>=2) {
			cout<<"您真是个伯乐!"<<endl;
			cout<<"达成隐藏结局2:伯乐相马";
			exit(0);
		}
	} else {
		de(12);

		cout << "很遗憾,你选择的" << selectedHorse << "号马没有获胜。" << endl;
		cout << "获胜的是" << winner << "号马。" << endl;
		cout << "损失赌注: " << betAmount << " 元" << endl;
		cout << "当前余额: " << f << " 元" << endl;
		de(15);
		horses=0;
	}

	// 继续游戏选项
	cout << endl;
	while(1) {
		if(pdbj(15, 1, 1, 10, 10, "再玩一次")) {
			system("cls");
			horseRacing();
			return;
		}

		if(pdbj(16, 1, 1, 6, 10, "退出")) {
			system("cls");
			cout << "返回主菜单..." << endl;
			Sleep(1000);
			return;
		}
	}
}



void developerMenu() {
	system("cls");
	return;
	cout << "=== 开发者模式 ===" << endl;
	cout << "当前余额: " << f << endl;
	cout << "圣水数量: " << water << endl;
	cout << "开发者模式: " << (developerMode ? "开启" : "关闭") << endl;
	cout << "==================" << endl;
	while(1) {
		if(pdbj(6,1,1,20,10,"设置余额")) {
			system("cls");
			cout << "请输入新的余额: ";
			long long newBalance;
			cin >> newBalance;
			f = newBalance;
			cout << "余额已设置为: " << f << endl;
			Sleep(1000);
			system("cls");
			developerMenu();
			return;
		}

		if(pdbj(7,1,1,20,10,"添加圣水")) {
			water++;
			cout << "圣水+1,当前数量: " << water << endl;
			Sleep(1000);
			system("cls");
			developerMenu();
			return;
		}

		if(pdbj(8,1,1,20,10,"直接获胜")) {
			f = 100000000;
			cout << "已设置为亿万富翁!" << endl;
			Sleep(1000);
			system("cls");
			developerMenu();
			return;
		}

		if(pdbj(9,1,1,15,10,"返回主菜单")) {
			system("cls");
			return;
		}

		if(pdbj(10,1,1,20,10,"关闭开发者模式")) {
			developerMode = false;
			cout << "开发者模式已关闭" << endl;
			Sleep(1000);
			system("cls");
			return;
		}
	}
}


void gs(string x) {
	int a=x.size();
	for(int i=0; i<=a; ++i) {
		Sleep(50);
		cout<<x[i];
	}
}
void ccp() {
	for(int i=1; i<=100000000; i++) {
		cout<<"1-10选一个数(输入0可以离开,每次奖金会翻100倍)"<<endl;
		cin>>a;
		b=rand()%10+1;
		if(a==b)ans*=100;  // 每次匹配奖金×100
		else if(a==0) {
			f+=ans;
		} else {
			ans=0;
			break;
		}
	}

}

void cp() {
	system("cls");
	f -= 3;

	// 输入6个数字
	int userNumbers[6];
	cout << "======= 彩票游戏 =======" << endl;
	cout << "每次花费: 3元" << endl;
	cout << "当前余额: " << f << "元" << endl;
	cout << "请输入6个数字 (每个数字1-10):" << endl;

	for(int i = 0; i < 6; i++) {
		while(1) {
			cout << "第" << i+1 << "个数字: ";
			cin >> userNumbers[i];
			if(userNumbers[i] >= 1 && userNumbers[i] <= 30) {
				break;
			} else {
				cout << "请输入1-10之间的数字!" << endl;
			}
		}
	}

	// 生成开奖号码
	int lotteryNumbers[6];
	cout << endl << "正在开奖..." << endl;
	Sleep(1000);

	cout << "开奖结果: ";
	for(int i = 0; i < 6; i++) {
		lotteryNumbers[i] = rand() % 10 + 1;
		cout << lotteryNumbers[i] << " ";
	}
	cout << endl;

	// 显示用户选择的号码
	cout << "您的号码: ";
	for(int i = 0; i < 6; i++) {
		cout << userNumbers[i] << " ";
	}
	cout << endl;

	// 比对中奖情况
	int matchCount = 0;
	long long multiplier = 1;  // 初始倍率为1

	cout << endl << "比对结果:" << endl;
	for(int i = 0; i < 6; i++) {
		if(userNumbers[i] == lotteryNumbers[i]) {
			cout << "第" << i+1 << "位: ? 匹配 (倍率×10)" << endl;
			matchCount++;
			multiplier *= 10;  // 每个匹配位置倍率翻10倍
		} else {
			cout << "第" << i+1 << "位: ? 不匹配 (您选" << userNumbers[i]
			     << ",开奖" << lotteryNumbers[i] << ")" << endl;
		}
	}

	// 计算奖金
	long long winnings = 0;
	if(matchCount > 0) {
		winnings = 3 * multiplier;  // 基础奖金为赌注3元乘以倍率
		f += winnings;

		cout << endl << "=========================" << endl;
		cout << "恭喜!您匹配了 " << matchCount << " 个位置" << endl;
		cout << "中奖倍率: " << multiplier << "倍" << endl;
		cout << "获得奖金: " << winnings << " 元" << endl;
		cout << "当前余额: " << f << " 元" << endl;
		cout << "=========================" << endl;
	} else {
		cout << endl << "=========================" << endl;
		cout << "很遗憾,没有匹配任何数字" << endl;
		cout << "损失赌注: 3元" << endl;
		cout << "当前余额: " << f << " 元" << endl;
		cout << "=========================" << endl;
	}

	Sleep(3000);
	system("cls");
}


void tiger() {
	f -= 15; // 扣除费用
	ans = 1;  // 重置奖金倍数
	system("cls");

	// ========== 1. 游戏开始界面 ==========
	cout << "==================================================" << endl;
	cout << "||                幸 运 老 虎 机                ||" << endl;
	cout << "==================================================" << endl;
	cout << "||  花费:15 元                                 ||" << endl;
	cout << "||  当前余额:" << setw(8) << f << " 元                       ||" << endl;
	cout << "==================================================" << endl;
	cout << "||  规则:匹配数字或特定序列即可赢得大奖!      ||" << endl;
	cout << "||  点击下方按钮开始转动...                     ||" << endl;
	cout << "==================================================" << endl << endl;

	// ========== 2. 动态等待玩家点击 ==========
	cout << "        +---------+---------+---------+" << endl;
	cout << "        |   ???   |   ???   |   ???   |" << endl;
	cout << "        +---------+---------+---------+" << endl << endl;

	// 等待按钮点击(保留原有交互逻辑)
	while(!pdbj(10, 20, 20, 35, 11, "[ 开 始 游 戏 ]")) {
		// 等待期间显示闪烁提示
		static int blink = 0;
		ydgb(21, 25); // 定位到提示行
		if(blink % 2 == 0) {
			de(13); // 紫色高亮
			cout << ">> 点击按钮开始游戏 <<";
			de(15);
		} else {
			cout << "                           "; // 清空提示
		}
		blink++;
		Sleep(300);
	}

	// ========== 3. 转动动画效果 ==========
	system("cls");
	cout << "==================================================" << endl;
	cout << "||                转 动 中...                   ||" << endl;
	cout << "==================================================" << endl;

	int c, d, e;
	const int spinFrames = 15; // 转动帧数

	for(int frame = 0; frame < spinFrames; frame++) {
		ydgb(5, 1); // 定位到显示区域

		// 生成随机数字(模拟转动)
		c = (rand() % 30 + 1);
		d = (rand() % 30 + 1);
		e = (rand() % 30 + 1);

		// 显示转轮框架
		cout << "        +---------+---------+---------+" << endl;
		cout << "        |  ";

		// 第一个转轮(黄色)
		de(14);
		cout << setw(3) << c;
		de(15);
		cout << "    |  ";

		// 第二个转轮(红色)
		de(12);
		cout << setw(3) << d;
		de(15);
		cout << "    |  ";

		// 第三个转轮(绿色)
		de(10);
		cout << setw(3) << e;
		de(15);
		cout << "    |" << endl;

		cout << "        +---------+---------+---------+" << endl << endl;

		// 显示转动进度条
		cout << "        [";
		int progress = (frame * 100) / spinFrames;
		int bars = (progress * 20) / 100;
		de(10); // 绿色进度
		for(int i = 0; i < bars; i++) cout << "=";
		de(15); // 恢复默认
		for(int i = bars; i < 20; i++) cout << "-";
		cout << "] " << setw(3) << progress << "%" << endl;

		// 速度逐渐减慢
		Sleep(100 + frame * 10);
	}

	// ========== 4. 最终结果显示 ==========
	system("cls");
	cout << "==================================================" << endl;
	cout << "||                开 奖 结 果                   ||" << endl;
	cout << "==================================================" << endl << endl;

	// 高亮显示最终数字
	cout << "        +---------+---------+---------+" << endl;
	cout << "        |  ";

	de(14); // 黄色
	cout << setw(3) << c;
	de(15);
	cout << "    |  ";

	de(12); // 红色
	cout << setw(3) << d;
	de(15);
	cout << "    |  ";

	de(10); // 绿色
	cout << setw(3) << e;
	de(15);
	cout << "    |" << endl;

	cout << "        +---------+---------+---------+" << endl << endl;

	// ========== 5. 计算奖金(完全保留原有逻辑) ==========
	string specialMessage = "";

	// 逻辑判断
	if(c == d) {
		ans *= 10 * e / 2;
		if(d == e) {
			ans *= 100 * e;
			specialMessage = "&zwnj;*** 头 奖! ***&zwnj;";
		}
	} else {
		if(d == e) ans *= e / 2;
	}

	if(d == c + 1 && e == d + 1) {
		ans *= 1000;
		specialMessage = "&zwnj;*** 顺 子 奖! ***&zwnj;";
	}

	if(d == c - 1 && e == d - 1) {
		ans *= 900;
		specialMessage = "&zwnj;*** 反 顺 子 奖! ***&zwnj;";
	}

	// ========== 6. 显示中奖结果 ==========
	cout << "==================================================" << endl;

	if(!specialMessage.empty()) {
		// 特殊奖励闪烁效果
		for(int flash = 0; flash < 3; flash++) {
			ydgb(12, 18); // 调整坐标以居中显示消息
			de(13); // 紫色闪烁
			cout << specialMessage;
			Sleep(300);
			ydgb(12, 18);
			cout << "                        "; // 清空消息长度
			Sleep(200);
		}
		ydgb(12, 18);
		de(13);
		cout << specialMessage;
		de(15);
		cout << endl << endl;
	}

	// 显示奖金结果
	cout << "||                                              ||" << endl;
	if(ans == 1) {
		de(12); // 红色表示未中奖
		cout << "||          很遗憾,本次未中奖!                ||" << endl;
		cout << "||          获得奖金:0 元                      ||" << endl;
		de(15);
	} else {
		de(10); // 绿色表示中奖
		long long prize = ans;
		f += prize; // 更新余额
		cout << "||          恭喜中奖!                          ||" << endl;
		cout << "||          获得奖金:" << setw(10) << prize << " 元          ||" << endl;
		de(15);
	}

	cout << "||                                              ||" << endl;
	cout << "||          当前余额:" << setw(10) << f << " 元             ||" << endl;
	cout << "||                                              ||" << endl;
	cout << "==================================================" << endl;

	// ========== 7. 操作选项 ==========
	cout << "||                                              ||" << endl;
	cout << "||          请选择下一步操作:                  ||" << endl;
	cout << "||                                              ||" << endl;

	// 使用原有pdbj函数创建交互按钮
	bool choiceMade = false;
	while(!choiceMade) {
		ydgb(22, 15);
		if(pdbj(22, 15, 15, 25, 10, "[ 再 玩 一 次 ]")) {
			system("cls");
			tiger(); // 递归调用自身
			return;
		}

		ydgb(22, 35);
		if(pdbj(22, 35, 35, 45, 10, "[ 返 回 主 菜 单 ]")) {
			system("cls");
			cout << "返回主菜单..." << endl;
			Sleep(1000);
			choiceMade = true;
		}
	}

	system("cls");
}



void winer() {
	system("cls");
	while(f>=0) {
		ydgb(1,1);
		cout<<"你好,要点什么?"<<endl;
		cout<<"当前余额:"<<f<<endl;
		string szs="";
		szs+="黄金酒,500元,可以将购买后你的总额翻十倍,库存";
		szs+=char(5-jwine+'0');
		szs+="瓶";
		string jzj="生死酒,70%的概率死亡,30%的概率将总额翻1000倍,库存";
		if(!swine) {
			jzj+="10";
		} else {
			jzj+=char(10-swine+'0');
		}
		jzj+="瓶";
		if(pdbj(3,1,1,50,5,szs)) {
			if(jwine<5) {
				system("cls");
				f-=500;
				f*=10;
				cout<<"金子!金子!";
				jwine++;
				Sleep(500);
			} else {
				cout<<"酒已售尽";
				Sleep(500);
			}
			system("cls");
		}
		if(pdbj(4,1,1,50,5,jzj)) {
			system("cls");
			if(swine<10) {
				int ed=rand()%100+1;
				if(ed<=70) {
					if(water) {
						water-=1;
						cout<<"神明庇护了你";
						swine++;
						break;
					} else {
						cout<<"你死了"<<endl;
						cout<<"达成结局3:死亡";
						exit(0);
					}
				} else {
					cout<<"恭喜你,活下来了";
					f*=1000;
					swine++;
				}
			} else {
				cout<<"酒已售尽";
			}
			Sleep(500);
			system("cls");
		}
		if(pdbj(5,1,1,50,5,"圣水,200元,可以免疫一次死亡;")) {
			system("cls");
			f-=200;
			water++;
			cout<<"神明会庇佑你";
			Sleep(500);
			system("cls");
		}
		if(pdbj(6,1,1,50,5,"可口可乐,300元,可以获得1-500元不等的人民币")) {
			system("cls");
			f-=300;
			int ed=rand()%500+1;
			cout<<"瓶盖上显示你得了"<<ed<<"元"<<endl;
			f+=ed;
			Sleep(500);
			system("cls");
		}
		if(pdbj(7,1,1,4,5,"退出")) {
			system("cls");
			cout<<"欢迎下次光临"<<endl;
			break;
		}
		if(water==10) {
			system("cls");
			cout<<"神明将永远与你同行!"<<endl;
			cout<<"达成隐藏结局1:立地成佛";
			exit(0);
		}
	}
	Sleep(1000);
	system("cls");
	return ;
}

void renlian() {
	cout<<"                         --------"<<endl;
	cout<<"                         (^-^)"<<endl;
	cout<<"                         \\\b\\/[  ]"<<endl;
	cout<<"============================================================"<<endl;
}

void lunpandu() {
	system("cls");
	if(xingshoupanduan) {
		renlian();
		gs("你好,我叫Bob,你也是来参加轮盘赌的吧");
		Sleep(100);
		system("cls");

		renlian();
		gs("规则就是在你回合,可以选择用枪打谁");
		Sleep(100);
		system("cls");

		renlian();
		gs("如果射向自己,并且是空弹,那么你可以在打一次");
		Sleep(100);
		system("cls");

		renlian();
		gs("如果射向对手,那么无论是不是空弹,都将把回合给到我");
		Sleep(100);
		system("cls");

		renlian();
		gs("那么,");
		xingshoupanduan=0;
	}

	gs("开始吧!");
	Sleep(100);

	// 游戏初始化
	int bulletPosition = rand() % 6 + 1;  // 实弹位置
	int currentChamber = 1;  // 当前枪膛位置
	bool playerTurn = true;
	int playerBet = rand()%10000+100;  // 基础赌注

	while(1) {
		system("cls");
		renlian();
		cout << "当前枪膛位置: " << currentChamber << "/6" << endl;
		cout << "你的回合" << endl;
		cout << "赌注: " << playerBet << "元" << endl;
		if(playerTurn) {
			// 玩家回合
			while(1) {
				if(pdbj(8,1,1,15,10,"射击自己")) {
					if(currentChamber == bulletPosition) {
						// 中弹
						if(water > 0) {
							system("cls");
							water--;
							cout << "圣水救了你一命!" << endl;
							bulletPosition = rand() % 6 + 1;  // 重新装弹
							currentChamber = 1;
							Sleep(1500);
							break;
						} else {
							system("cls");
							cout << "砰!你中弹了..." << endl;
							cout << "游戏结束" << endl;
							cout<<"达成结局3:死亡";
							Sleep(2000);
							exit(0);
						}
					} else {
						// 空弹,继续回合
						cout << "咔哒...空弹,继续你的回合" << endl;
						Sleep(1500);
						currentChamber++;
						break;
					}
				}

				if(pdbj(9,1,1,15,10,"射击Bob")) {
					if(currentChamber == bulletPosition) {
						// Bob中弹,玩家获胜
						system("cls");
						cout << "砰!Bob中弹了!" << endl;
						cout << "你赢得了 " << playerBet  << " 元!" << endl;
						f += playerBet;
						Sleep(2000);
						return;
					} else {
						// 空弹,轮到Bob
						cout << "咔哒...空弹,轮到Bob了" << endl;
						playerTurn = false;
						Sleep(1500);
						currentChamber++;
						break;
					}
				}
			}

			// 转动枪膛

		} else {
			// Bob的AI回合
			cout << "Bob的回合..." << endl;
			Sleep(1000);

			// Bob的简单AI:70%概率射击玩家,30%概率射击自己
			int bobChoice = rand() % 100;
			if(currentChamber>=4&&currentChamber<6) {
				if(bobChoice <= 90) {
					// Bob射击玩家
					cout << "Bob选择射击你..." << endl;
					Sleep(1000);

					if(currentChamber == bulletPosition) {
						if(water > 0) {
							system("cls");
							water--;
							cout << "圣水救了你一命!" << endl;
							bulletPosition = rand() % 6 + 1;  // 重新装弹
							currentChamber = 1;
							Sleep(1500);
							continue;
						} else {
							system("cls");
							cout << "砰!你中弹了..." << endl;
							cout << "游戏结束" << endl;
							cout<<"达成结局3:死亡";
							Sleep(2000);
							exit(0);
						}
					} else {
						cout<<"是空弹,轮到你的回合了"<<endl;
						Sleep(1000);
						currentChamber++;
					}
					playerTurn = true;  // 回到玩家回合
				} else {
					// Bob射击自己
					cout << "Bob选择射击自己..." << endl;
					Sleep(1000);

					if(currentChamber == bulletPosition) {
						// Bob中弹,玩家获胜
						system("cls");
						cout << "Bob中弹了!" << endl;
						cout << "你赢得了 " << playerBet<< " 元!" << endl;
						f += playerBet;
						Sleep(2000);
						return;
					} else {
						// 空弹,Bob继续
						cout << "咔哒...空弹,Bob继续" << endl;
						Sleep(1500);
						currentChamber++;
					}
				}
			} else if(bobChoice <= 70||currentChamber==6) {
				// Bob射击玩家
				cout << "Bob选择射击你..." << endl;
				Sleep(1000);

				if(currentChamber == bulletPosition) {
					if(water > 0) {
						system("cls");
						water--;
						cout << "圣水救了你一命!" << endl;
						bulletPosition = rand() % 6 + 1;  // 重新装弹
						currentChamber = 1;
						Sleep(1500);
						continue;
					} else {
						system("cls");
						cout << "砰!你中弹了..." << endl;
						cout << "游戏结束" << endl;
						cout<<"达成结局3:死亡";
						Sleep(2000);
						exit(0);
					}
				} else {
					cout<<"是空弹,轮到你的回合了"<<endl;
					Sleep(1000);
					currentChamber++;
				}
				playerTurn = true;  // 回到玩家回合
			} else {
				// Bob射击自己
				cout << "Bob选择射击自己..." << endl;
				Sleep(1000);

				if(currentChamber == bulletPosition) {
					// Bob中弹,玩家获胜
					cout << "Bob中弹了!" << endl;
					cout << "你赢得了 " << playerBet<< " 元!" << endl;
					f += playerBet;
					Sleep(2000);
					return;
				} else {
					// 空弹,Bob继续
					cout << "咔哒...空弹,Bob继续" << endl;
					Sleep(1500);
					currentChamber++;
				}
			}
		}
	}
}

void cards() {
	int wash[53]= {0,1,2,3,4,5,6,7,8,9,10,11,12,13,1,2,3,4,5,6,7,8,9,10,11,12,13,1,2,3,4,5,6,7,8,9,10,11,12,13,1,2,3,4,5,6,7,8,9,10,11,12,13};
	int m=rand()%50+10;
	for(int i=1; i<=m; i++) {
		swap(wash[rand()%53+1],wash[rand()%53+1]);
	}
}

void aboutgame() {
	Sleep(100);
	system("cls");
	gs("本游戏由Mod笔谈出品");
	cout<<endl;
	gs("      参与者");
	cout<<endl;
	gs("  技术扶持:林培奇");
	cout<<endl;
	gs("  技术扶持:黄嘉赢");
	cout<<endl;
	gs("  界面设计:莫晗");
	cout<<endl;
	gs("  技术实现:莫晗");
	cout<<endl;
	gs("  灵感来源:G币人生");
	cout<<endl;
	gs("https://www.bcoi.cn/d/gfhd/blog/252/");
	cout<<endl;
	gs("  灵感来源2:赌神模拟器");
	cout<<endl;
	gs("https://www.bcoi.cn/d/gfhd/blog/507/68cdf84a445b45c7920cde55#1758328906825");
	cout<<endl;
	gs("  出版:Mod笔谈");
	cout<<endl;
	gs("正版渠道:https://www.bcoi.cn/blog/246/68b67a8535f6ac3821de3868#1756789381892");
	Sleep(3000);
	system("cls");
}

void shezhi() {
	system("cls");
	Sleep(100);
	while(1) {
		if(pdbj(1,1,1,8,7,"关于游戏")) {
			aboutgame();
			continue;
		}
		if(pdbj(2,1,1,8,7,"退出")) {
			Sleep(100);
			system("cls");
			return ;
		}
		cout<<endl;
		cout<<"版本:赌徒狂欢1.0.9"<<endl;
		if(pdbj(5,1,1,1,7,"")) {
			Sleep(100);
			system("cls");
			if(!developerMode) {
				cout << "请输入开发者密码: ";
				string inputPwd;
				cin >> inputPwd;
				if(inputPwd == devPassword) {
					developerMode = true;
					cout << "开发者模式已开启!" << endl;
				} else {
					cout << "密码错误!" << endl;
				}
			} else {
				system("cls");
				developerMenu();
			}
			Sleep(1000);
			system("cls");
			continue;
		}
	}
}

// ========== 21点游戏辅助函数:计算手牌最佳点数 ==========
int calculateScore(const vector<string>& hand) {
    int score = 0;
    int aceCount = 0;

    // 第一遍遍历,计算非A的牌面值,并统计A的数量
    for (const string& card : hand) {
        if (card == "A") {
            aceCount++;
        } else if (card == "J" || card == "Q" || card == "K") {
            score += 10;
        } else {
            // 数字牌 2-10
            score += stoi(card);
        }
    }

    // 处理A,使其点数最大化且不超过21
    for (int i = 0; i < aceCount; i++) {
        // 如果当前总分加11不会超过21,则A按11点算
        if (score + 11 <= 21) {
            score += 11;
        } else {
            // 否则A按1点算
            score += 1;
        }
    }

    return score;
}

// ========== 21点游戏主函数 ==========
void blackjack() {
    system("cls");

    // 1. 介绍规则
    cout << "==================== 21点 ====================" << endl;
    cout << "规则介绍:" << endl;
    cout << "1. 游戏开始前下注。" << endl;
    cout << "2. 你可以选择「摸牌」或「停牌」。" << endl;
    cout << "3. 目标是让手牌点数尽可能接近21点,但不能超过。" << endl;
    cout << "4. A可计为1点或11点,J、Q、K计为10点。" << endl;
    cout << "5. 如果你先爆牌(超过21点),则庄家获胜。" << endl;
    cout << "6. 双方停牌后,点数更接近21点的一方获胜。" << endl;
    cout << "7. 获胜可获得双倍赌注!" << endl;
    cout << "==============================================" << endl;
    cout << "当前余额: " << f << " 元" << endl;

    // 2. 输入赌注
    long long bet = 0;
    while (bet <= 0 || bet > f) {
        cout << "请输入下注金额 (1 - " << f << "): ";
        cin >> bet;
        if (bet <= 0) {
            cout << "下注金额必须为正数!" << endl;
        } else if (bet > f) {
            cout << "余额不足!" << endl;
        }
    }
    f -= bet; // 扣除赌注

    // 初始化牌堆
    vector<string> deck;
    string suits[] = {"", ""}; // 我们只关心点数,不关心花色
    string values[] = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"};

    // 创建一副牌(4副牌混合,增加随机性)
    for (int i = 0; i < 4; i++) {
        for (const string& val : values) {
            deck.push_back(val);
        }
    }

    // 洗牌
    srand(time(0));
    random_shuffle(deck.begin(), deck.end());

    // 玩家和庄家的手牌
    vector<string> playerHand;
    vector<string> dealerHand;


    // 游戏状态
    bool playerStands = false;
    bool dealerStands = false;
    bool gameOver = false;
    string winner = "";

    // 游戏主循环
    while (!gameOver) {
        system("cls");
        cout << "==================== 21点 ====================" << endl;
        cout << "赌注: " << bet << " 元 | 余额: " << f << " 元" << endl;
        cout << "----------------------------------------------" << endl;

        // 显示庄家手牌(第一张隐藏)
        cout << "庄家手牌: ";
        if (!dealerStands) {
            cout << "[?] ";
            for (size_t i = 1; i < dealerHand.size(); i++) {
                cout << dealerHand[i] << " ";
            }
            cout << endl;
        } else {
            for (const string& card : dealerHand) {
                cout << card << " ";
            }
            cout << " (点数: " << calculateScore(dealerHand) << ")" << endl;
        }

        // 显示玩家手牌和点数
        cout << "你的手牌: ";
        for (const string& card : playerHand) {
            cout << card << " ";
        }
        cout << " (点数: " << calculateScore(playerHand) << ")" << endl;
        cout << "----------------------------------------------" << endl;

        // 检查玩家是否爆牌
        if (calculateScore(playerHand) > 21) {
            cout << "你爆牌了!" << endl;
            winner = "庄家";
            gameOver = true;
            break;
        }

        // 玩家回合
        if (!playerStands) {
            cout << "请选择操作:" << endl;
            cout << "1. 摸牌" << endl;
            cout << "2. 停牌" << endl;

            int choice;
            cin >> choice;

            if (choice == 1) {
                // 摸牌
                playerHand.push_back(deck.back());
                deck.pop_back();
                cout << "你摸到了一张: " << playerHand.back() << endl;
                Sleep(1000);
            } else if (choice == 2) {
                // 停牌
                playerStands = true;
                cout << "你选择停牌。" << endl;
                Sleep(1000);
            }
        }

        // 庄家回合(简单AI:点数小于17则摸牌,否则停牌)
        if (!dealerStands && !gameOver) {
            if (calculateScore(dealerHand) < 17) {
                dealerHand.push_back(deck.back());
                deck.pop_back();
                cout << "庄家摸了一张牌。" << endl;
            } else {
                dealerStands = true;
                cout << "庄家选择停牌。" << endl;
            }
            Sleep(1500);
        }

        // 检查庄家是否爆牌
        if (calculateScore(dealerHand) > 21) {
            system("cls");
            cout << "庄家爆牌了!" << endl;
            winner = "玩家";
            gameOver = true;
            break;
        }

        // 检查游戏是否结束(双方都停牌)
        if (playerStands && dealerStands) {
            gameOver = true;
            int playerScore = calculateScore(playerHand);
            int dealerScore = calculateScore(dealerHand);

            if (playerScore > dealerScore) {
                winner = "玩家";
            } else if (playerScore < dealerScore) {
                winner = "庄家";
            } else {
                winner = "平局";
            }
        }
    }

    // 显示最终结果
    system("cls");
    cout << "==================== 游戏结束 ====================" << endl;
    cout << "庄家手牌: ";
    for (const string& card : dealerHand) {
        cout << card << " ";
    }
    cout << " (点数: " << calculateScore(dealerHand) << ")" << endl;

    cout << "你的手牌: ";
    for (const string& card : playerHand) {
        cout << card << " ";
    }
    cout << " (点数: " << calculateScore(playerHand) << ")" << endl;
    cout << "----------------------------------------------" << endl;

    if (winner == "玩家") {
        long long winnings = bet * 2;
        f += winnings;
        de(10); // 绿色
        cout << "恭喜你获胜!获得 " << winnings << " 元!" << endl;
        de(15);
    } else if (winner == "庄家") {
        de(12); // 红色
        cout << "庄家获胜。你损失了 " << bet << " 元。" << endl;
        de(15);
    } else {
        // 平局,返还赌注
        f += bet;
        de(14); // 黄色
        cout << "平局!赌注已返还。" << endl;
        de(15);
    }
    cout << "当前余额: " << f << " 元" << endl;
    cout << "==============================================" << endl;

    // 返回主菜单选项
    cout << endl;
    while (1) {
        if (pdbj(15, 1, 1, 10, 10, "再玩一次")) {
            system("cls");
            blackjack();
            return;
        }
        if (pdbj(16, 1, 1, 6, 10, "退出")) {
            system("cls");
            cout << "返回主菜单..." << endl;
            Sleep(1000);
            return;
        }
    }
}


int main() {
	srand(time(0));
	int zslsd=1;
	while(1) {
		ydgb(1,1);
		if(zslsd==1) {
			gs("欢迎来到赌徒狂欢");
			cout<<endl;
			gs("初始金额200元");
			cout<<endl;
			gs("本游戏由803莫晗,810林培奇,806黄嘉赢联合出品");
			cout<<endl;
			gs("游戏中有三种普通结局,两种隐藏结局,供你探索");
		}
		Sleep(100);
		system("cls");
		Sleep(100);
		while(f>0) {
			if(f>=100000000) {
				cout<<"恭喜你通关本游戏"<<endl;
				cout<<"感谢游玩"<<endl;
				cout<<"达成结局1:亿万富翁";
				Sleep(1000);
				exit(0);
			}

			if(pdbj(1,1,1,16,7,"3元一次的彩票")) {
				system("cls");
				Sleep(500);
				cp();
			}
			if(pdbj(2,1,1,6,7,"3元,连击")) {
				system("cls");
				Sleep(500);
				ccp();
			}
			if(pdbj(3,1,1,20,7,"15元一次,玩老虎机")) {
				system("cls");
				Sleep(500);
				tiger();
			}
			if(pdbj(4,1,1,20,7,"进入酒吧")) {
				system("cls");
				Sleep(500);
				winer();
				system("cls");
			}
			if(pdbj(5,1,1,22,7,"紧张刺激的俄罗斯轮盘赌")) {
				system("cls");
				Sleep(500);
				lunpandu();
				system("cls");
			}
			if(pdbj(6,1,1,18,7,"赌马模式")) {
				system("cls");
				Sleep(500);
				horseRacing();
				system("cls");
			}
			if(pdbj(7,1,1,18,7,"21点")) { // 注意:这里假设原来第7行是“设置”,你需要调整行号或重新布局
				system("cls");
				Sleep(500);
				blackjack();
				system("cls");
			}

			if(pdbj(8,1,1,4,7,"设置")) {
				shezhi();
				Sleep(500);
				system("cls");
			}
			cout<<endl;
			cout<<"存款:"<<f<<endl;
		}
		system("cls");
		cout<<"你破产了,记得下载反诈APP"<<endl;
		cout<<"达成结局2:破产";
		return 0;
	}
	zslsd=2;
}