//运行前请加入-O2 -lm -std=c++14
//赌徒狂欢1.9修复版【升级斗地主:双农民、抢地主、顺子、连对、飞机带翅膀、三带一】
#include <iostream>
#include <set>
#include <string>
#include <cstdlib>
#include<vector>
#include<algorithm>
#include<ctime>
#include<windows.h>
#include<iomanip>
#include <random>
#include <limits>
#include <map>
#include <sstream>
// 替换Windows特定功能
#ifdef _WIN32
#include <windows.h>
#else
// Linux/macOS占位,本游戏仅支持Windows控制台
#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,AK;
int a,b,ans,k,x,water,jwine,swine,horses;
bool blog=1,xingshoupanduan=1;
bool developerMode = false; // 开发者模式开关
string devPassword = "9178mod"; // 开发者密码
// ===================== 牌型枚举【扩展新增:三带一、顺子、连对、飞机带翅膀】=====================
enum CardType
{
TYPE_NONE = 0,
SINGLE, //单张
PAIR, //对子
TRIPLE, //三张
TRIPLE1, //三带一 3+1
TRIPLE2, //三带二 3+2
STRAIGHT, //顺子 >=5
DOUBLE_STRAIGHT,//连对 >=3对
PLANE_RAW, //纯飞机(不带翅膀,两组三张)
PLANE_1, //飞机带单(飞机+两个单张)
PLANE_2, //飞机带对子(飞机+两对)
FOUR2, //四带二
BOMB, //炸弹4张
KING_BOMB //王炸
};
//牌的点数定义 3=3 ...10=10 J=11 Q=12 K=13 A=14 2=15 小王=16 大王=17
int GetRank(int card)
{
return card;
}
map<int, int> GetCardCount(const vector<int>& hand)
{
map<int, int> cnt;
for (int c : hand) cnt[c]++;
return cnt;
}
void SortHand(vector<int>& hand)
{
sort(hand.begin(), hand.end());
}
// 判断顺子
bool IsStraight(const vector<int>& cards, int& mainVal)
{
int n = cards.size();
if(n <5) return false;
vector<int> wlist;
for(auto c:cards) wlist.push_back(GetRank(c));
sort(wlist.begin(),wlist.end());
//不能包含2,小王,大王
for(auto w:wlist)
{
if(w >= 15) return false;
}
for(int i=1;i<n;i++)
{
if(wlist[i]-wlist[i-1] !=1) return false;
}
mainVal = wlist.back();
return true;
}
//判断连对(至少3对)
bool IsDoubleStraight(const vector<int>& cards, int& mainVal)
{
auto cnt = GetCardCount(cards);
vector<int> keys;
for(auto &p:cnt)
{
if(p.second !=2) return false;
keys.push_back(p.first);
}
int nPair = keys.size();
if(nPair <3) return false;
sort(keys.begin(),keys.end());
for(auto k:keys) if(k>=15) return false;
for(int i=1;i<nPair;i++)
{
if(keys[i]-keys[i-1]!=1) return false;
}
mainVal = keys.back();
return true;
}
// 识别牌型入口
pair<CardType, int> GetCardType(const vector<int>& cards)
{
int n = cards.size();
auto cnt = GetCardCount(cards);
vector<int> countVals;
for (auto& p : cnt) countVals.push_back(p.second);
sort(countVals.rbegin(), countVals.rend());
// 单张
if (n == 1)
{
return make_pair(SINGLE, cards[0]);
}
//对子
if (n == 2 && cnt.size() == 1)
{
return make_pair(PAIR, cards[0]);
}
//三张
if (n == 3 && countVals[0] == 3)
{
int main = 0;
for (auto& p : cnt) if (p.second == 3) main = p.first;
return make_pair(TRIPLE, main);
}
//==== 三带一 4张 3+1 ====
if(n ==4 && countVals[0]==3 && countVals[1]==1)
{
int main=0;
for(auto&p:cnt) if(p.second==3) main=p.first;
return make_pair(TRIPLE1,main);
}
//三带二 5张 3+2
if (n == 5 && countVals[0] == 3 && countVals[1] == 2)
{
int main = 0;
for (auto& p : cnt) if (p.second == 3) main = p.first;
return make_pair(TRIPLE2, main);
}
//顺子
int sv;
if(IsStraight(cards,sv))
{
return make_pair(STRAIGHT,sv);
}
//连对
int dsv;
if(IsDoubleStraight(cards,dsv))
{
return make_pair(DOUBLE_STRAIGHT,dsv);
}
//====飞机不带翅膀 6张 两组三张====
if (n == 6 && cnt.size() == 2 && countVals[0]==3 && countVals[1]==3)
{
vector<int> tripleKeys;
for (auto& p : cnt) tripleKeys.push_back(p.first);
int r1 = GetRank(tripleKeys[0]);
int r2 = GetRank(tripleKeys[1]);
if(abs(r1 - r2) == 1 && r1<15 && r2<15)
{
int val = max(tripleKeys[0], tripleKeys[1]);
return make_pair(PLANE_RAW, val);
}
}
//====飞机带单 8张:2组三张+两个单张 333444+5+6====
if(n==8)
{
vector<int> tri;
auto tmpCnt = cnt;
for(auto &p:tmpCnt)
{
if(p.second ==3) tri.push_back(p.first);
}
if(tri.size()==2)
{
int a=tri[0],b=tri[1];
if(abs(GetRank(a)-GetRank(b))==1 && a<15 && b<15)
{
return make_pair(PLANE_1, max(a,b));
}
}
}
//====飞机带对子 10张:两组三张 +两对====
if(n==10)
{
vector<int> tri;
auto tmpCnt = cnt;
for(auto &p:tmpCnt)
{
if(p.second ==3) tri.push_back(p.first);
}
if(tri.size()==2)
{
int a=tri[0],b=tri[1];
if(abs(GetRank(a)-GetRank(b))==1 && a<15 && b<15)
{
return make_pair(PLANE_2, max(a,b));
}
}
}
//四带二 6张 4+任意两张
if (n == 6 && countVals[0] == 4)
{
int main = 0;
for (auto& p : cnt) if (p.second == 4) main = p.first;
return make_pair(FOUR2, main);
}
//炸弹4张
if (n == 4 && countVals[0] == 4)
{
int main = 0;
for (auto& p : cnt) if (p.second == 4) main = p.first;
return make_pair(BOMB, main);
}
//王炸
if(n == 2)
{
bool hasXiao = false, hasDa = false;
for(int c : cards)
{
if(c == 16) hasXiao = true;
if(c == 17) hasDa = true;
}
if(hasXiao && hasDa)
{
return make_pair(KING_BOMB, 0);
}
}
return make_pair(TYPE_NONE, 0);
}
// 判断能不能压过上一手
bool CanBeat(CardType prevType, int prevVal, int prevLen, const vector<int>& playCards)
{
auto res = GetCardType(playCards);
CardType t = res.first;
int v = res.second;
int nowLen = playCards.size();
if(t == TYPE_NONE) return false;
//王炸无敌
if(t == KING_BOMB) return true;
//炸弹大于普通牌
if(t == BOMB)
{
if(prevType == KING_BOMB) return false;
if(prevType == BOMB) return GetRank(v) > GetRank(prevVal);
return true;
}
if(prevType == KING_BOMB || prevType == BOMB) return false;
//牌型必须相同,长度必须一样!顺子、连对必须张数一致
if(t != prevType || nowLen != prevLen) return false;
return GetRank(v) > GetRank(prevVal);
}
//从手牌移除打出的牌
vector<int> RemoveCards(vector<int> hand, const vector<int>& delCards)
{
vector<int> h = hand;
for(int c : delCards)
{
auto it = find(h.begin(), h.end(), c);
if(it != h.end()) h.erase(it);
}
return h;
}
//AI出牌查找可以压的牌
vector<int> AiChoosePlay(const vector<int>& hand, CardType prevType, int prevVal, int prevLen)
{
vector<pair<vector<int>, pair<CardType, int>>> candidates;
auto cnt = GetCardCount(hand);
vector<int> keys;
for(auto &p : cnt) keys.push_back(p.first);
//单张
for(int k : keys) candidates.push_back({{k}, {SINGLE, k}});
//对子
for(int k : keys) if(cnt[k]>=2) candidates.push_back({{k,k}, {PAIR, k}});
//三张
for(int k : keys) if(cnt[k]>=3) candidates.push_back({{k,k,k}, {TRIPLE, k}});
//三带一
for(int main:keys)
{
if(cnt[main]>=3)
{
for(int sub:keys)
{
if(sub == main) continue;
if(cnt[sub]>=1)
{
vector<int> play={main,main,main,sub};
candidates.push_back({play, {TRIPLE1, main}});
}
}
}
}
//三带二
for(int main : keys)
{
if(cnt[main] >=3)
{
for(int sub : keys)
{
if(sub == main) continue;
if(cnt[sub] >= 2)
{
vector<int> play = {main,main,main,sub,sub};
candidates.push_back({play, {TRIPLE2, main}});
}
}
}
}
//顺子生成(5张示例)
vector<int> nums;
for(int i=3;i<=14;i++) nums.push_back(i);
for(int s=0;s<(int)nums.size()-4;s++)
{
vector<int> st;
bool ok=true;
for(int j=0;j<5;j++)
{
int x = nums[s+j];
if(cnt[x]<1) {ok=false;break;}
st.push_back(x);
}
if(ok) candidates.push_back({st,{STRAIGHT, st.back()}});
}
//连对(3对,6张)
for(int s=3;s<=12;s++)
{
if(cnt[s]>=2 && cnt[s+1]>=2 && cnt[s+2]>=2)
{
vector<int> d={s,s,s+1,s+1,s+2,s+2};
candidates.push_back({d,{DOUBLE_STRAIGHT, s+2}});
}
}
//纯飞机不带翅膀
vector<int> tripleList;
for(int k : keys) if(cnt[k]>=3 && k<15) tripleList.push_back(k);
for(int i=0;i<tripleList.size();i++)
{
for(int j=0;j<tripleList.size();j++)
{
if(i==j)continue;
int a = tripleList[i];
int b = tripleList[j];
if(abs(GetRank(a)-GetRank(b)) == 1)
{
vector<int> play = {a,a,a,b,b,b};
int val = max(a,b);
candidates.push_back({play, {PLANE_RAW, val}});
}
}
}
//四带二
for(int main : keys)
{
if(cnt[main] >=4)
{
for(int sub : keys)
{
if(sub == main) continue;
if(cnt[sub] >= 2)
{
vector<int> play = {main,main,main,main,sub,sub};
candidates.push_back({play, {FOUR2, main}});
}
}
vector<int> subs;
for(int s : keys)
{
if(s != main && cnt[s]>=1) subs.push_back(s);
}
if(subs.size()>=2)
{
vector<int> play = {main,main,main,main, subs[0], subs[1]};
candidates.push_back({play, {FOUR2, main}});
}
}
}
//炸弹
for(int k : keys)
{
if(cnt[k]>=4)
{
candidates.push_back({{k,k,k,k}, {BOMB, k}});
}
}
//王炸
bool hasXiao = false, hasDa = false;
for(int c : hand)
{
if(c ==16) hasXiao = true;
if(c ==17) hasDa = true;
}
if(hasXiao && hasDa)
{
candidates.push_back({{16,17}, {KING_BOMB,0}});
}
vector<pair<vector<int>, int>> canPlay;
for(auto &item : candidates)
{
vector<int> &cards = item.first;
auto typeInfo = item.second;
CardType t = typeInfo.first;
int v = typeInfo.second;
if(CanBeat(prevType, prevVal, prevLen, cards))
{
canPlay.emplace_back(cards, v);
}
}
if(!canPlay.empty())
{
sort(canPlay.begin(), canPlay.end(), [](const pair<vector<int>,int>&a,const pair<vector<int>,int>&b){
return GetRank(a.second) < GetRank(b.second);
});
return canPlay[0].first;
}
return vector<int>();
}
//===================== 【新版斗地主 3人:玩家+AI农民1 + AI农民2,抢地主、下注倍数】=====================
void landLord()
{
system("cls");
cout << "===== 斗地主 3人对局【赌徒狂欢】=====" << endl;
cout << "底分:50元,抢地主可以翻倍!" << endl;
if(f < 50)
{
cout << "余额不足50元,无法游玩斗地主!" << endl;
Sleep(2000);
return;
}
//生成完整牌堆
vector<int> poker;
for(int i=3;i<=15;i++)
{
poker.push_back(i);
poker.push_back(i);
poker.push_back(i);
poker.push_back(i);
}
poker.push_back(16);
poker.push_back(17);
shuffle(poker.begin(), poker.end(), mt19937((unsigned int)time(0)));
vector<int> player, aiFarmer1, aiFarmer2, landCard;
//发牌,每人17张,底牌3张
for(int i=0;i<17;i++)
{
player.push_back(poker.back()); poker.pop_back();
aiFarmer1.push_back(poker.back()); poker.pop_back();
aiFarmer2.push_back(poker.back()); poker.pop_back();
}
for(int i=0;i<3;i++) landCard.push_back(poker.back()), poker.pop_back();
SortHand(player); SortHand(aiFarmer1); SortHand(aiFarmer2);
//===== 抢地主阶段 =====
int multiple = 1;
int landlordIdx = -1; //0玩家,1AI农民1,2AI农民2
cout << "\n-----抢地主阶段-----" << endl;
cout << "轮到你抢地主!输入1=抢地主,0=不抢" << endl;
int choice;
cin >> choice;
if(choice ==1)
{
landlordIdx = 0;
multiple *=2;
cout << "你选择抢地主!倍数x2" << endl;
}
else
{
//AI1抢地主
int ai1Bid = rand()%2;
if(ai1Bid ==1)
{
landlordIdx=1;
multiple*=2;
cout << "AI农民1抢地主!倍数x2" << endl;
}
else
{
//AI2抢地主
int ai2Bid = rand()%2;
if(ai2Bid ==1)
{
landlordIdx=2;
multiple*=2;
cout << "AI农民2抢地主!倍数x2" << endl;
}
else
{
cout << "所有人都不抢,本局重新发牌!" << endl;
Sleep(1500);
landLord();
return;
}
}
}
//地主拿底牌
if(landlordIdx ==0)
{
player.insert(player.end(), landCard.begin(), landCard.end());
SortHand(player);
}
else if(landlordIdx ==1)
{
aiFarmer1.insert(aiFarmer1.end(), landCard.begin(), landCard.end());
SortHand(aiFarmer1);
}
else
{
aiFarmer2.insert(aiFarmer2.end(), landCard.begin(), landCard.end());
SortHand(aiFarmer2);
}
long long bet = 50 * multiple;
f -= bet;
cout << "本局赌注:" << bet << "元,倍数="<<multiple<<",扣除赌注,当前余额:"<<f<<endl;
Sleep(2000);
//出牌回合变量
CardType lastType = TYPE_NONE;
int lastVal = 0;
int lastLen =0;
int currentPlayer = landlordIdx; //地主先手出牌
int passCount = 0;
bool gameRun = true;
while(gameRun)
{
system("cls");
cout << "====斗地主回合====" << endl;
cout << "倍数:"<<multiple<<" | 赌注:"<<bet<<endl;
cout << "上一手:";
if(lastType == TYPE_NONE) cout << "无,可自由出牌" << endl;
else cout << "牌型:"<<lastType<<" 主牌:" << lastVal << " 张数:"<<lastLen<<endl;
vector<int>* nowHand;
string playerName;
if(currentPlayer ==0)
{
nowHand = &player;
playerName = "玩家";
}
else if(currentPlayer ==1)
{
nowHand = &aiFarmer1;
playerName = "AI农民1";
}
else
{
nowHand = &aiFarmer2;
playerName = "AI农民2";
}
cout << "\n【"<<playerName<<"回合】" << endl;
cout << "AI农民1手牌:" << aiFarmer1.size() << "张" << endl;
cout << "AI农民2手牌:" << aiFarmer2.size() << "张" << endl;
vector<int> playCard;
bool pass = false;
if(currentPlayer == 0)
{
//玩家回合
cout << "你的手牌:";
for(int x : player) cout << x << " ";
cout << endl;
cout << "输入打出的牌(空格分隔,0=不出):" << endl;
cin.ignore();
string line;
getline(cin, line);
if(line == "0")
{
pass = true;
}
else
{
stringstream ss(line);
int tmp;
while(ss >> tmp) playCard.push_back(tmp);
}
if(pass)
{
cout << "你选择不出" << endl;
passCount++;
}
else
{
auto pt = GetCardType(playCard);
if(pt.first == TYPE_NONE)
{
cout << "无效牌型!按回车继续";
cin.get();
continue;
}
if(lastType != TYPE_NONE && !CanBeat(lastType, lastVal, lastLen, playCard))
{
cout << "无法压过上家!按回车继续";
cin.get();
continue;
}
//移除手牌
player = RemoveCards(player, playCard);
cout << "你打出:";
for(int x : playCard) cout << x << " ";
cout << endl;
lastType = pt.first;
lastVal = pt.second;
lastLen = playCard.size();
passCount = 0;
if(player.empty())
{
cout << "你是地主,手牌打完!地主胜利!赢取 "<< bet*2 <<"元!" << endl;
f += bet*2;
Sleep(2500);
return;
}
}
}
else
{
//AI农民1 / AI农民2
vector<int>&aiHand = *nowHand;
playCard = AiChoosePlay(aiHand, lastType, lastVal, lastLen);
if(playCard.empty())
{
cout << playerName << "不出" << endl;
passCount++;
}
else
{
cout << playerName << "打出:";
for(int x : playCard) cout << x << " ";
cout << endl;
aiHand = RemoveCards(aiHand, playCard);
auto tinfo = GetCardType(playCard);
lastType = tinfo.first;
lastVal = tinfo.second;
lastLen = playCard.size();
passCount = 0;
if(aiHand.empty())
{
cout << playerName << "手牌打完!农民胜利!你输掉赌注"<<bet<<"元!" << endl;
Sleep(2500);
return;
}
}
}
Sleep(1200);
//连续两人pass,清空出牌记录,本轮出牌人继续先手
if(passCount >=2)
{
lastType = TYPE_NONE;
lastVal = 0;
lastLen =0;
passCount =0;
cout << "两人都pass,出牌权保留!" << endl;
Sleep(1200);
continue;
}
//切换玩家 0→1→2→0循环
currentPlayer = (currentPlayer +1)%3;
//判断农民胜利:两个农民任意一人打完牌就赢,上面已经处理
}
}
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; // 赛道长度
// 随机生成马匹基础速度(有一定随机性)
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");
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() {
f-=3;
ans=1; //初始化倍率
while(true)
{
cout<<"1-10选一个数(输入0可以离开,每次奖金会翻100倍)"<<endl;
cin>>a;
if(cin.fail())
{
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(),'\n');
cout<<"输入无效\n";
continue;
}
b=rand()%10+1;
if(a==0) {
f+=ans;
cout<<"带走奖金 "<<ans<<endl;
break;
}
if(a>=1&&a<=10)
{
if(a==b)ans*=100;
else {
ans=0;
cout<<"猜错!奖金清零\n";
break;
}
}else{
cout<<"只能输入0~10\n";
}
}
Sleep(1000);
system("cls");
}
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] <= 10) {
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 = "*** 头 奖! ***";
}
} else {
if(d == e) ans *= e / 2;
}
if(d == c + 1 && e == d + 1) {
ans *= 1000;
specialMessage = "*** 顺 子 奖! ***";
}
if(d == c - 1 && e == d - 1) {
ans *= 900;
specialMessage = "*** 反 顺 子 奖! ***";
}
// ========== 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+="瓶";
//黄金酒:金色(14)
de(14);
if(pdbj(3,1,1,50,14,szs)) {
de(15);
if(jwine<5) {
system("cls");
f-=500;
f*=10;
cout<<"金子!金子!";
jwine++;
Sleep(500);
} else {
cout<<"酒已售尽";
Sleep(500);
}
system("cls");
}
de(8); //灰黑色
if(pdbj(4,1,1,50,8,jzj)) {
de(15);
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");
}
de(15); //白色
if(pdbj(5,1,1,50,15,"圣水,200元,可以免疫一次死亡;")) {
de(15);
system("cls");
f-=200;
water++;
cout<<"神明会庇佑你";
Sleep(500);
system("cls");
}
de(12); //红色
if(pdbj(6,1,1,50,12,"可口可乐,300元,可以获得1-500元不等的人民币")) {
de(15);
system("cls");
f-=300;
int ed=rand()%500+1;
cout<<"瓶盖上显示你得了"<<ed<<"元"<<endl;
f+=ed;
Sleep(500);
system("cls");
}
de(6); //土黄色/棕黄色
if(pdbj(7,1,1,50,6,"突击步枪(有奇效哦!),100元")) {
de(15);
system("cls");
f-=100;
AK++;
Sleep(100);
system("cls");
}
de(15);
if(pdbj(8,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<<" _/[ ]"<<endl;
cout<<"============================================================"<<endl;
}
void lunpandu() {
system("cls");
if(AK){
renlian();
gs("666,俄罗斯轮盘赌用步枪都来了!");
system("cls");
renlian();
gs("那别怪我了!");
system("cls");
system("start https://www.bilibili.com/video/BV1pvY16QEwd?t=3.1");
gs("恭喜你死了");
cout<<endl;
gs("解锁隐藏结局3:人间情悠扬~");
exit(0);
}
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&¤tChamber<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 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 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);
}
}
// 洗牌
mt19937 rng ((unsigned int) time (0));
shuffle (deck.begin (), deck.end (), rng);
// 玩家和庄家的手牌
vector<string> playerHand;
vector<string> dealerHand;
// 游戏状态
bool playerStands = false;
bool dealerStands = false;
bool gameOver = false;
string winner = "";
bool firstRound = true; // 标记:是否是玩家第一轮(强制摸牌)
// 游戏主循环
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) {
if(firstRound)
{
// ==========第一轮强制摸牌,不能停牌==========
cout << "【第一轮!必须摸牌!】" << endl;
cout << "自动选择摸牌" << endl;
if (!deck.empty ()) {
playerHand.push_back (deck.back ());
deck.pop_back ();
cout << "你摸到了一张:" << playerHand.back () << endl;
}
firstRound = false; // 第一轮结束,后续可以停牌
Sleep (1000);
}
else
{
cout << "请选择操作:" << endl;
cout << "1. 摸牌" << endl;
cout << "2. 停牌" << endl;
int choice;
cin >> choice;
if (choice == 1) {
// 摸牌
if (!deck.empty ()) {
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) {
if (!deck.empty ()) {
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((unsigned int)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点")) {
system("cls");
Sleep(500);
blackjack();
system("cls");
}
if(pdbj(8,1,1,20,7,"斗地主")) {
system("cls");
Sleep(500);
landLord();
system("cls");
}
if(pdbj(9,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;
}