【转载】florr塔防

· · 休闲·娱乐

塔防

#include<bits/stdc++.h>
#include<windows.h>
#define getc(x) (GetAsyncKeyState(x)&0x8000)
#define int long long
using namespace std;
void color(int x){
    SetConsoleTextAttribute(GetStdHandle(4294967285u),x);
}
void go(int x,int y){
    COORD p;
    p.X=x-1,p.Y=y-1;
    SetConsoleCursorPosition(GetStdHandle(4294967285u),p);
}
int n=6,m=16,nT=9,nE=11,co=30,gk,bl[]={0,1,2,5,11,26,58,130,292},bl2[]={0,1,2,6,14,33,80,191,459},xyco[]={7,10,14,9,13,12,11,6,2},shop[11],xg=1,upd_c[]={0,30,50,90,150,240,310,440,570,800},lv1=1,
upd1[15][15]={{},
    {0,100,0,0,0,0},
    {0,92,8,0,0,0},
    {0,80,15,5,0,0},
    {0,60,30,10,0,0},
    {0,44,34,20,2,0},
    {0,25,30,38,7,0},
    {0,15,24,44,16,1},
    {0,8,21,36,30,5},
    {0,4,20,28,38,10},
    {0,2,11,18,44,25}
};
struct node{
    char c;
    int d,th,tH,gs,gst,fw,sst,hps,hpss,hpst,hx,hxs,hxfw,hxt,dz,l,ls,jg,xy;
    int d2,h2,H2,ys,gs2,yst,gs2t,xy2,hx2,hxs2,hxfw2,hx2t,sb2,f;
}a[21][21],aa[21][21];
struct tower{
    char c;
    string na,sx;
    int pr,qd,d,th,tH,gs,fw,sst,hps,hpss,hpst,hx,hxs,hxfw,hxt,dz,l,ls,jg,xy; 
}T[1001];
struct enemy{
    char c;
    string na,sx;
    int d,h,H,ys,gs,qd,xy,hx,hxs,hxfw,sb;
}E[1001];
void init(){
    T[1]={'A',"基本","基本",3,1,10,200,200,10,3};
    T[2]={'B',"轻","轻",4,2,8,140,140,4,4};
    T[3]={'C',"叶子","叶子",5,3,13,220,220,12,3,0,1,2};
    T[4]={'D',"玫瑰","玫瑰",5,3,0,200,200,0,0,0,0,0,0,25,10,2};
    T[5]={'E',"刺","刺",6,3,100,150,150,25,4};
    T[6]={'F',"大米","大米",5,3,5,100,100,1,1};
    T[7]={'G',"导弹","导弹",6,3,0,150,150,10,0,0,0,0,0,0,0,0,0,35};
    T[8]={'H',"闪电","闪电",7,4,0,200,200,10,4,0,0,0,0,0,0,0,0,0,12,5};
    T[9]={'I',"激光","激光",8,5,0,100,100,1,0,0,0,0,0,0,0,0,0,0,0,0,2};
    for(int i=1,j=1;i<=nE*8;i+=nE,j++){
        E[i]={'a',"幼蚁","幼蚁",10,80,80,6,6,1};
        E[i+1]={'b',"工蚁","工蚁",10,150,150,4,5,2};
        E[i+2]={'c',"兵蚁","兵蚁",10,220,220,3,4,3};
        E[i+3]={'d',"蜜蜂","蜜蜂",50,70,70,4,5,3};
        E[i+4]={'e',"甲虫","甲虫",20,200,200,3,5,4};
        E[i+5]={'f',"火幼蚁","火幼",15,80,80,5,6,2};
        E[i+6]={'g',"火工蚁","火工",15,150,150,4,5,3};
        E[i+7]={'h',"火兵蚁","火兵",15,220,220,3,4,4};
        E[i+8]={'i',"瓢虫","瓢虫",10,200,200,4,5,3,0,15,10,1};
        E[i+9]={'j',"测试怪","测试",10,200,200,1,10,0};
        E[i+10]={'k',"苍蝇","苍蝇",10,40,40,1,5,2,0,0,0,0,75};
    }
}
void out(int x,int y,int f){
    if(y<=m/2)go(y*6-5,x*3-2);
    else go(y*6-1,x*3-2);
    int fc1=(f?112:(a[x][y].f==2?160:(a[x][y].f==1?192:(a[x][y].f==3?176:0)))),fc2=(isalpha(a[x][y].c)?xyco[max(a[x][y].xy,a[x][y].xy2)]:7);
    color(fc1+fc2);
    if(a[x][y].c=='.'){
        color(7),cout<<"  ",color(fc1+fc2),cout<<"□",color(7),cout<<"  ";
        for(int i=0;i<2;i++){
            if(y<=m/2)go(y*6-5,x*3-i);
            else go(y*6-1,x*3-i);
            cout<<"      ";
        }
    }
    for(int i=1;i<=nT;i++){
        if(a[x][y].c==T[i].c){
            color(7);
            if(T[i].sx.size()==2)color(7),cout<<"  ",color(fc1+fc2),cout<<T[i].sx,color(7),cout<<"  ";
            else color(7),cout<<" ",color(fc1+fc2),cout<<T[i].sx,color(7),cout<<" ";
            color(12);
            if(y<=m/2)go(y*6-5,x*3-1);
            else go(y*6-1,x*3-1);
            cout<<"[炮塔]";
            color(10);
            if(y<=m/2)go(y*6-5,x*3);
            else go(y*6-1,x*3);
            int xt=a[x][y].th*100.0/a[x][y].tH;
            cout<<" "<<max(0ll,xt)<<"% ";
            if(xt>9&&xt<100)cout<<" ";
            else if(xt<10)cout<<"  ";
            break;
        }
    }
    for(int i=1;i<=nE;i++){
        if(a[x][y].c==E[i].c){
            if(E[i].sx.size()==2)cout<<"  "<<E[i].sx<<"  ";
            else cout<<" "<<E[i].sx<<" ";
            color(1);
            if(y<=m/2)go(y*6-5,x*3-1);
            else go(y*6-1,x*3-1);
            cout<<"[敌人]";
            color(4);
            if(y<=m/2)go(y*6-5,x*3);
            else go(y*6-1,x*3);
            int xt=a[x][y].h2*100.0/a[x][y].H2;
            cout<<" "<<max(0ll,xt)<<"% ";
            if(xt>9&&xt<100)cout<<" ";
            else if(xt<10)cout<<"  ";
            break;
        }
    }
    color(7);
}
void clear(int x,int y){
    a[x][y].c='.',a[x][y].d=a[x][y].th=a[x][y].tH=a[x][y].gs=a[x][y].gst=a[x][y].fw=a[x][y].hps=a[x][y].hpss=a[x][y].hpst=a[x][y].hx=a[x][y].hxs=a[x][y].hxt=a[x][y].hxfw=a[x][y].dz=a[x][y].l=a[x][y].ls=a[x][y].jg=
    a[x][y].d2=a[x][y].h2=a[x][y].H2=a[x][y].ys=a[x][y].gs2=a[x][y].yst=a[x][y].gs2t=a[x][y].sst=a[x][y].f=a[x][y].xy=a[x][y].xy2=a[x][y].hx2=a[x][y].hx2t=a[x][y].hxs2=a[x][y].hxfw2=a[x][y].sb2=0;
}
void clear2(int x,int y){
    aa[x][y].c='.',aa[x][y].d=aa[x][y].th=aa[x][y].tH=aa[x][y].gs=aa[x][y].gst=aa[x][y].fw=aa[x][y].hps=aa[x][y].hpss=aa[x][y].hpst=aa[x][y].hx=aa[x][y].hxs=aa[x][y].hxt=aa[x][y].hxfw=aa[x][y].dz=aa[x][y].l=aa[x][y].ls=aa[x][y].jg=
    aa[x][y].d2=aa[x][y].h2=aa[x][y].H2=aa[x][y].ys=aa[x][y].gs2=aa[x][y].yst=aa[x][y].gs2t=aa[x][y].sst=aa[x][y].f=aa[x][y].xy2=aa[x][y].hx2=aa[x][y].hx2t=aa[x][y].hxs2=aa[x][y].hxfw2=aa[x][y].sb2=0;
}
void init_t(int x,int y){
    a[x][y].sst=0;
    if(isupper(a[x][y].c))a[x][y].hpst=a[x][y].gst=a[x][y].hxt=clock();
    if(islower(a[x][y].c))a[x][y].hx2t=a[x][y].gs2t=a[x][y].yst=clock();
}
void set_t(int x,int y,int l,int xy){
    clear(x,y);
    a[x][y].c=T[l].c,a[x][y].d=T[l].d*bl[xy],a[x][y].th=T[l].th*bl[xy],a[x][y].tH=T[l].tH*bl[xy],a[x][y].gs=T[l].gs,a[x][y].fw=T[l].fw,a[x][y].hps=T[l].hps*bl[xy],a[x][y].hpss=T[l].hpss,a[x][y].hx=T[l].hx*bl[xy],a[x][y].hxs=T[l].hxs,a[x][y].hxfw=T[l].hxfw,a[x][y].xy=xy,a[x][y].dz=T[l].dz*bl[xy],a[x][y].l=T[l].l*bl[xy],a[x][y].ls=T[l].ls,a[x][y].jg=T[l].jg*bl[xy];
    a[x][y].gst=a[x][y].f=a[x][y].sst=a[x][y].hpst=a[x][y].hxt=0;
}
void set_e(int x,int y,int l,int xy){
    clear(x,y);
    a[x][y].c=E[l].c,a[x][y].d2=E[l].d*bl2[xy],a[x][y].h2=E[l].h*bl2[xy],a[x][y].H2=E[l].H*bl2[xy],a[x][y].ys=E[l].ys,a[x][y].gs2=E[l].gs,a[x][y].xy2=xy,a[x][y].hx2=E[l].hx*bl2[xy],a[x][y].hxs2=E[l].hxs,a[x][y].hxfw2=E[l].hxfw,a[x][y].sb2=E[l].sb;
    a[x][y].yst=a[x][y].gs2t=a[x][y].f=a[x][y].sst=a[x][y].hx2t=0;
}
void initgame(){
    init();
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)clear2(i,j);
}
int r100(){
    return rand()%100+1;
}
void game();
void enemy_bz(int num,int p){
    int sp=0;
    for(int i=1;i<=num;i++){
        int tx,ty,xy,qd,tl,tt[]={0,1,1,2,3,3,4};
        do{
            tx=rand()%n+1,ty=rand()%(m/2-1)+m/2+2,xy=(gk-1)/6+1,qd=tt[(gk-1)%6+1];
            if(gk<=1)do{tl=rand()%nE+1;}while((tl-1)%nE+1==10||((tl-1)%nE+1!=10&&!(E[tl].qd<=1)));
            else if(gk<=3)do{tl=rand()%nE+1;}while((tl-1)%nE+1==10||((tl-1)%nE+1!=10&&!(E[tl].qd<=2)));
            else if(gk<=4)do{tl=rand()%nE+1;}while((tl-1)%nE+1==10||((tl-1)%nE+1!=10&&!(E[tl].qd<=3)));
            else if(gk<=6)do{tl=rand()%nE+1;}while((tl-1)%nE+1==10||((tl-1)%nE+1!=10&&!(E[tl].qd<=4)));
            else do{tl=rand()%(nE*xy)+1;}while((tl-1)%nE+1==10||((tl-1)%nE+1!=10&&(!(((tl+nE-1)/nE==xy-1&&E[tl].qd>=qd+1)||((tl+nE-1)/nE==xy&&E[tl].qd<=qd)))));
        }
        while(a[tx][ty].c!='.');
        set_e(tx,ty,tl,(tl+nE-1)/nE);
        sp+=1.0*a[tx][ty].d2*a[tx][ty].h2/a[tx][ty].gs2*100/(100-a[tx][ty].sb2)*(a[tx][ty].hx2>0?1.0*a[tx][ty].hx2/a[tx][ty].hxs2:1);
        out(tx,ty,0);
    }
    color(14);
    go(1,n*3+7);
    cout<<"关卡战力:"<<sp<<"   ";
    color(7);
}
void buzhen(int F){
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)a[i][j]=aa[i][j];
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)out(i,j,0);
    for(int i=1;i<=n*3;i+=3)go(m*3,i),cout<<"  ||  ";
    int x=1,y=1,tt=clock(),pw=clock(),ps=clock(),pa=clock(),p_=clock(),pd=clock(),pn=clock(),pco=clock(),px=clock(),pz=clock();
    out(x,y,1);
    go(1,n*3+1);
    if(F)co+=((gk-1)/3+1)*40,gk++;
    cout<<"第"<<gk<<"关 金币:"<<co<<"     \n";
    cout<<"----商店---- 按R刷新,花费2金币;按U升级\n";
    cout<<"当前商店等级:"<<lv1;
    if(lv1<10)cout<<"  升级需要花费"<<upd_c[lv1]<<"金币";
    else cout<<"  已满级                               ";
    go(1,n*3+4);
    color(7);
    for(int i=1;i<=3;i++)cout<<"|["<<i<<"] |  ";
    cout<<"\n";
    if(F){
        for(int i=1;i<=3;i++){
            int x=r100(),s=0;
            for(int j=1;j<=5;j++){
                s+=upd1[lv1][j];
                if(s>=x){
                    do{
                        shop[i]=rand()%nT+1;
                    }
                    while(T[shop[i]].qd!=j);
                    break;
                }
            }
        }
    }
    for(int i=1;i<=3;i++){
        if(T[shop[i]].sx.size()==2)cout<<"| "<<T[shop[i]].sx<<" |  ";
        else cout<<"|"<<T[shop[i]].sx<<"|  ";
    }
    cout<<"\n";
    for(int i=1;i<=3;i++)cout<<"| "<<T[shop[i]].pr<<"¥"<<"|  ";
    enemy_bz((gk-1)/2+2,0);
    for(;;){
        int tx=x,ty=y;
        if(getc(VK_RETURN)){
            for(int i=1;i<=n;i++)for(int j=1;j<=m/2;j++)aa[i][j]=a[i][j];
            for(int i=1;i<=n;i++)for(int j=m/2+1;j<=m;j++)clear2(i,j);
            game();
        }
        if(getc('W')&&x>1&&(clock()-pw-0.0)/CLOCKS_PER_SEC>=0.13)x--,pw=clock();
        if(getc('S')&&x<n&&(clock()-ps-0.0)/CLOCKS_PER_SEC>=0.13)x++,ps=clock();
        if(getc('A')&&y>1&&(clock()-pa-0.0)/CLOCKS_PER_SEC>=0.13)y--,pa=clock();
        if(getc('D')&&y<m/2&&(clock()-pd-0.0)/CLOCKS_PER_SEC>=0.13)y++,pd=clock();
        if(getc('Z')&&isupper(a[x][y].c)&&(clock()-pz-0.0)/CLOCKS_PER_SEC>=0.15){
            int f=1;
            for(int i=1;i<=n;i++){
                for(int j=1;j<=m/2;j++){
                    if(a[i][j].c=='.'){
                        f=0;
                        break;
                    }
                }
            }
            if(f){
                go(1,n*3+4);
                cout<<"棋盘已满";
                Sleep(1000);
                go(1,n*3+4);
                cout<<"        ";
            }
            else{
                int mx=x,my=y,xx=x,yy=y;
                for(;;){
                    int tx=mx,ty=my;
                    if(getc('W')&&mx>1&&(clock()-pw-0.0)/CLOCKS_PER_SEC>=0.13)mx--,pw=clock();
                    if(getc('S')&&mx<n&&(clock()-ps-0.0)/CLOCKS_PER_SEC>=0.13)mx++,ps=clock();
                    if(getc('A')&&my>1&&(clock()-pa-0.0)/CLOCKS_PER_SEC>=0.13)my--,pa=clock();
                    if(getc('D')&&my<m/2&&(clock()-pd-0.0)/CLOCKS_PER_SEC>=0.13)my++,pd=clock();
                    if(mx!=tx||my!=ty){
                        out(tx,ty,tx==xx&&ty==yy);
                        out(mx,my,1);
                    }
                    if(getc(VK_SPACE)&&my<=m/2&&a[mx][my].c=='.'&&(clock()-p_-0.0)/CLOCKS_PER_SEC>=0.15){
                        set_t(mx,my,a[x][y].c-'A'+1,a[xx][yy].xy);
                        clear(xx,yy);
                        out(xx,yy,0);
                        out(mx,my,1);
                        p_=clock(),x=mx,y=my;
                        break;
                    }
                }
            }
            pz=clock();
        }
        if(getc('Q')&&isupper(a[x][y].c)&&a[x][y].xy<8){
            while(getc('Q'));
            int c=0,xx[5],yy[5];
            for(int i=1;i<=n;i++){
                for(int j=1;j<=m;j++){
                    if(a[i][j].c==a[x][y].c&&a[i][j].xy==a[x][y].xy&&(i!=x||j!=y))xx[++c]=i,yy[c]=j;
                    if(c>2){
                        for(int k=1;k<=c;k++){
                            clear(xx[k],yy[k]);
                            out(xx[k],yy[k],0);
                        }
                        set_t(x,y,a[x][y].c-'A'+1,a[x][y].xy+1);
                        out(x,y,0);
                        break;
                    }
                }
                if(c>2)break;
            }
        }
        if(getc('X')&&isupper(a[x][y].c)&&(clock()-px-0.0)/CLOCKS_PER_SEC>=0.15){
            p_=clock(),co+=T[a[x][y].c-64].pr*bl[a[x][y].xy];
            clear(x,y);
            out(x,y,1);
            go(1,n*3+1);
            cout<<"第"<<gk<<"关 金币:"<<co<<"       ";
        }
        for(int i=1;i<=3;i++){
            if(getc(i+'0')&&(clock()-pn-0.0)/CLOCKS_PER_SEC>=0.15&&y<=m/2&&a[x][y].c=='.'&&shop[i]>0&&co>=T[shop[i]].pr){
                pn=clock();
                set_t(x,y,shop[i],1);
                out(x,y,1);
                p_=clock(),co-=T[shop[i]].pr;
                go(1,n*3+1);
                cout<<"第"<<gk<<"关 金币:"<<co<<"       ";
                shop[i]=0;
                go(1,n*3+4);
                color(7);
                for(int i=1;i<=3;i++)cout<<"|["<<i<<"] |  ";
                cout<<"\n";
                for(int i=1;i<=3;i++){
                    if(shop[i]>0){
                        if(T[shop[i]].sx.size()==2)cout<<"| "<<T[shop[i]].sx<<" |  ";
                        else cout<<"|"<<T[shop[i]].sx<<"|  ";
                    }
                    else cout<<"|    |  ";
                }
                cout<<"\n";
                for(int i=1;i<=3;i++){
                    if(shop[i]>0)cout<<"| "<<T[shop[i]].pr<<"¥"<<"|  ";
                    else cout<<"|    |  ";
                }
                break;
            }
        }
        if(getc('R')&&co>=2){
            while(getc('R'));
            go(1,n*3+1);
            co-=2,cout<<"第"<<gk<<"关 金币:"<<co<<"       ";
            go(1,n*3+4);
            color(7);
            for(int i=1;i<=3;i++)cout<<"|["<<i<<"] |  ";
            cout<<"\n";
            for(int i=1;i<=3;i++){
                int x=r100(),s=0;
                for(int j=1;j<=5;j++){
                    s+=upd1[lv1][j];
                    if(s>=x){
                        do{
                            shop[i]=rand()%nT+1;
                        }
                        while(T[shop[i]].qd!=j);
                        break;
                    }
                }
            }
            for(int i=1;i<=3;i++){
                if(T[shop[i]].sx.size()==2)cout<<"| "<<T[shop[i]].sx<<" |  ";
                else cout<<"|"<<T[shop[i]].sx<<"|  ";
            }
            cout<<"\n";
            for(int i=1;i<=3;i++)cout<<"| "<<T[shop[i]].pr<<"¥"<<"|  ";
        }
        if(getc('U')&&co>=upd_c[lv1]&&lv1<10){
            while(getc('U'));
            go(1,n*3+1);
            co-=upd_c[lv1],cout<<"第"<<gk<<"关 金币:"<<co<<"       ";
            go(1,n*3+3);
            cout<<"当前商店等级:"<<++lv1;
            if(lv1<10)cout<<"  升级需要花费"<<upd_c[lv1]<<"金币";
            else cout<<"  已满级                               ";
        }
        if(x!=tx||y!=ty){
            out(tx,ty,0);
            out(x,y,1);
        }
        if(getc('G')&&xg){
            go(1,n*3+7);
            string s;
            int jf=0;
            system("pause");
            go(1,n*3+7);
            cout<<"请输入命令:                  ";
            go(13,n*3+7);
            cin>>s;
            if(s=="set"){
                int x,y,l,xy;
                cin>>x>>y>>l>>xy;
                if(y<=m/2){
                    set_t(x,y,l,xy);
                    out(x,y,0);
                }
                else{
                    set_e(x,y,l,xy);
                    out(x,y,0);
                }
            }
            if(s=="fill"){
                char c;
                int l,xy;
                cin>>c>>l>>xy;
                if(c=='t'){
                    for(int i=1;i<=n;i++){
                        for(int j=1;j<=m/2;j++){
                            set_t(i,j,l,xy);
                            out(i,j,0);
                        }
                    }
                }
                if(c=='e'){
                    for(int i=1;i<=n;i++){
                        for(int j=m/2+1;j<=m;j++){
                            set_e(i,j,l,xy);
                            out(i,j,0);
                        }
                    }
                }
            }
            if(s=="clear"){
                char c;
                cin>>c;
                if(c=='t'){
                    for(int i=1;i<=n;i++){
                        for(int j=1;j<=m/2;j++){
                            clear(i,j);
                            out(i,j,0);
                        }
                    }
                }
                if(c=='e'){
                    for(int i=1;i<=n;i++){
                        for(int j=m/2+1;j<=m;j++){
                            clear(i,j);
                            out(i,j,0);
                        }
                    }
                }
            }
            if(s=="jump")cin>>gk,co-=((gk-1)/3+1)*40,gk--,jf=1;
            if(s=="coin"){
                int x;
                cin>>x,co+=x;
                go(1,n*3+1);
                cout<<"第"<<gk<<"关 金币:"<<co<<"       ";
            }
            if(s=="level"){
                int x;
                cin>>x,lv1=min(x,10ll);
                go(1,n*3+3);
                cout<<"当前商店等级:"<<lv1;
                if(lv1<10)cout<<"  升级需要花费"<<upd_c[lv1]<<"金币";
                else cout<<"  已满级                               ";
            }
            go(13,n*3+7);
            for(int i=1;i<=100;i++)cout<<" ";
            go(1,n*3+7);
            system("pause");
            go(1,n*3+7);
            cout<<"                               ";
            if(jf){
                for(int i=1;i<=n;i++)for(int j=1;j<=m/2;j++)aa[i][j]=a[i][j];
                for(int i=1;i<=n;i++)for(int j=m/2+1;j<=m;j++)clear2(i,j);
                buzhen(1);
                return;
            }
        }
        if(getc('V')){
            system("cls");
            color(7);
            cout<<"炮塔图鉴\n";
            int cq[]={0,0,0,7,10,11,11,13,6};
            for(int i=1;i<=nT;i++){
                color(cq[T[i].pr]);
                cout<<i<<"、"<<T[i].na<<(T[i].na.size()==2?"  ":"");
                color(6);
                cout<<"  价格:"<<T[i].pr;
                color(12);
                cout<<"  伤害:"<<setw(3)<<max(T[i].d,T[i].dz);
                color(10);
                cout<<"  血量:"<<setw(3)<<T[i].th;
                color(1);
                cout<<"  攻击范围:"<<setw(3)<<T[i].fw;
                color(3);
                cout<<" 攻速:1/"<<setw(3)<<T[i].gs;
                if(T[i].hx||T[i].hps){
                    color(10);
                    cout<<"  ";
                    if(T[i].hps)cout<<"(周围4个)";
                    cout<<"回血:"<<setw(3)<<max(T[i].hx,T[i].hps);
                    cout<<"  回血速度:1/"<<setw(3)<<max(T[i].hxs,T[i].hpss);
                }
                if(T[i].l){
                    color(11);
                    cout<<"  闪电:"<<setw(3)<<T[i].l;
                    cout<<"  连锁:"<<setw(3)<<T[i].ls;
                }
                if(T[i].jg){
                    color(11);
                    cout<<"  激光:"<<setw(3)<<T[i].jg;
                }
                cout<<"\n";
            }
            color(7);
            cout<<"敌人图鉴\n";
            int cq2[]={7,7,10,11,13};
            for(int i=1;i<=nE;i++){
                color(cq2[E[i].qd]);
                cout<<i<<"、"<<E[i].na<<(E[i].na.size()==4?"  ":"");
                color(6);
                color(12);
                cout<<"  伤害:"<<setw(3)<<E[i].d;
                color(10);
                cout<<"  HP:"<<setw(3)<<E[i].h;
                color(1);
                cout<<"  移速:"<<setw(3)<<E[i].ys;
                color(3);
                cout<<"  攻速:1/"<<setw(3)<<E[i].gs;
                color(14);
                cout<<"  战力:"<<(int)(1.0*E[i].d*E[i].h/E[i].gs*100/(100-E[i].sb)*(E[i].hx>0?1.0*E[i].hx/E[i].hxs:1))<<"\n";
            }
            color(7);
            cout<<"按空格退出";
            for(;;){
                if(getc(VK_SPACE)){
                    for(int i=1;i<=n;i++)for(int j=1;j<=m/2;j++)aa[i][j]=a[i][j];
                    for(int i=1;i<=n;i++)for(int j=m/2+1;j<=m;j++)clear2(i,j);
                    system("cls");
                    buzhen(0);
                }
            }
        }
    }
}
void t_atk(){
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i][j].d>0&&isupper(a[i][j].c)&&(clock()-a[i][j].gst)*10.0/CLOCKS_PER_SEC>=a[i][j].gs){
                a[i][j].gst=clock();
                int px=0,py=0;
                double dis=1e9;
                for(int k=1;k<=n;k++)for(int l=1;l<=m;l++)if(islower(a[k][l].c)&&sqrt((k-i)*(k-i)+(l-j)*(l-j))<dis)dis=sqrt((k-i)*(k-i)+(l-j)*(l-j)),px=k,py=l;
                if(px&&py&&(dis<=a[i][j].fw||(a[i][j].fw==1&&dis<2))){
                    int f=0;
                    a[px][py].sst=clock();
                    if(r100()>=a[px][py].sb2)a[px][py].h2-=a[i][j].d,f=1;
                    a[px][py].f=f;
                    out(px,py,0);
                }
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i][j].dz>0&&(clock()-a[i][j].gst)*10.0/CLOCKS_PER_SEC>=a[i][j].gs){
                a[i][j].gst=clock();
                for(int k=j+1;k<=m;k++){
                    if(islower(a[i][k].c)){
                        int f=0;
                        a[i][k].sst=clock();
                        if(r100()>=a[i][k].sb2)a[i][k].h2-=a[i][j].dz,f=1;
                        a[i][k].f=f;
                        out(i,k,0);
                        break;
                    }
                }
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i][j].l>0&&isupper(a[i][j].c)&&(clock()-a[i][j].gst)*10.0/CLOCKS_PER_SEC>=a[i][j].gs){
                a[i][j].gst=clock();
                int px=0,py=0;
                double dis=1e9;
                for(int k=1;k<=n;k++)for(int l=1;l<=m;l++)if(islower(a[k][l].c)&&sqrt((k-i)*(k-i)+(l-j)*(l-j))<dis)dis=sqrt((k-i)*(k-i)+(l-j)*(l-j)),px=k,py=l;
                if(px&&py&&(dis<=a[i][j].fw||(a[i][j].fw==1&&dis<2))){
                    a[px][py].f=3,a[px][py].sst=clock(),a[px][py].h2-=a[i][j].l;
                    out(px,py,0);
                    int vis[21][21],c=1;
                    for(int k=1;k<=n;k++)for(int l=1;l<=m;l++)vis[k][l]=islower(a[k][l].c)&&(px!=k||py!=l),c+=vis[k][l];
                    for(int t=1;t<min(c,a[i][j].ls);t++){
                        int x,y;
                        do{
                            x=rand()%n+1,y=rand()%m+1;
                        }
                        while(!vis[x][y]);
                        vis[x][y]=0,a[x][y].f=3,a[x][y].sst=clock(),a[x][y].h2-=a[i][j].l;
                        out(x,y,0);
                    }
                }
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i][j].jg>0&&(clock()-a[i][j].gst)*10.0/CLOCKS_PER_SEC>=a[i][j].gs){
                a[i][j].gst=clock();
                for(int k=j+1;k<=m;k++){
                    if(islower(a[i][k].c)){
                        a[i][k].sst=clock();
                        a[i][k].h2-=a[i][j].jg,a[i][k].f=3;
                        out(i,k,0);
                    }
                }
            }
        }
    }
}
void t_hx(){
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i][j].hps>0&&(clock()-a[i][j].hpst)*10.0/CLOCKS_PER_SEC>=a[i][j].hpss){
                a[i][j].hpst=clock();
                int dx[]={-1,1,0,0},dy[]={0,0,-1,1};
                for(int k=0;k<4;k++){
                    int ii=i+dx[k],jj=j+dy[k];
                    if(ii>0&&ii<=n&&jj>0&&jj<=m&&isupper(a[ii][jj].c)&&a[ii][jj].th<a[ii][jj].tH&&a[ii][jj].hx==0&&a[ii][jj].hps==0){
                        a[ii][jj].th=min(a[ii][jj].tH,a[ii][jj].th+a[i][j].hps),a[ii][jj].f=2,a[ii][jj].sst=clock();
                        out(ii,jj,0);
                    }
                }
            }
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i][j].hx>0&&(clock()-a[i][j].hxt)*10.0/CLOCKS_PER_SEC>=a[i][j].hxs){
                a[i][j].hxt=clock();
                int px=0,py=0,hp=1e9;
                for(int ii=max(1ll,i-a[i][j].hxfw);ii<=min(n,i+a[i][j].hxfw);ii++)for(int jj=max(1ll,j-a[i][j].hxfw);jj<=min(m,j+a[i][j].hxfw);jj++)if(isupper(a[ii][jj].c)&&a[ii][jj].th<hp&&a[ii][jj].hx==0&&a[ii][jj].hps==0)hp=a[ii][jj].th,px=ii,py=jj;
                if(px&&py&&hp<a[px][py].tH){
                    a[px][py].th=min(a[px][py].tH,a[px][py].th+a[i][j].hx),a[px][py].f=2,a[px][py].sst=clock();
                    out(px,py,0);
                }
            }
        }
    }
}
void e_atk(){
    for(int i=1;i<=n;i++){
        for(int j=2;j<=m;j++){
            int dx[]={0,-1,1,-1,1},dy[]={-1,-1,-1,0,0},fk=8,f=1;
            double fd=1e18;
            for(int k=0;k<5;k++){
                if(i>0&&i<=n&&j>0&&j<=m&&islower(a[i][j].c)&&(clock()-a[i][j].gs2t)*10.0/CLOCKS_PER_SEC>=a[i][j].gs2&&isupper(a[i+dx[k]][j+dy[k]].c)){
                    a[i+dx[k]][j+dy[k]].f=1,a[i+dx[k]][j+dy[k]].sst=clock(),a[i+dx[k]][j+dy[k]].th-=a[i][j].d2;
                    out(i+dx[k],j+dy[k],0);
                    a[i][j].gs2t=clock(),f=0;
                    break;
                }
                if(islower(a[i][j].c)&&!isupper(a[max(i-1,1ll)][j-1].c)&&!isupper(a[i][j-1].c)&&!isupper(a[min(i+1,n)][j-1].c)&&!isupper(a[max(i-1,1ll)][j].c)&&!isupper(a[min(i+1,n)][j].c)){
                    for(int k=0;k<5;k++){
                        int nx=i+dx[k],ny=j+dy[k];
                        double dis=1e9;
                        if(nx>0&&nx<=n&&ny>0&&ny<=m&&a[nx][ny].c=='.'){
                            for(int ii=1;ii<=n;ii++)for(int jj=1;jj<=j;jj++)if(isupper(a[ii][jj].c)&&sqrt((ii-nx)*(ii-nx)+(jj-ny)*(jj-ny))<dis)dis=sqrt((ii-nx)*(ii-nx)+(jj-ny)*(jj-ny));
                            if(dis<fd)fd=dis,fk=k;
                        }
                    }
                }
            }
            if(f&&fd<1e18&&fk<8&&islower(a[i][j].c)&&(clock()-a[i][j].yst)*10.0/CLOCKS_PER_SEC>=a[i][j].ys&&a[i+dx[fk]][j+dy[fk]].c=='.'){
                a[i+dx[fk]][j+dy[fk]]=a[i][j];
                clear(i,j);
                out(i,j,0);
                out(i+dx[fk],j+dy[fk],0);
                a[i+dx[fk]][j+dy[fk]].yst=clock();
            }
        }
    }
}
void e_hx(){
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i][j].hx2>0&&(clock()-a[i][j].hx2t)*10.0/CLOCKS_PER_SEC>=a[i][j].hxs2){
                a[i][j].hx2t=clock();
                int px=0,py=0,hp=1e9;
                for(int ii=max(1ll,i-a[i][j].hxfw2);ii<=min(n,i+a[i][j].hxfw2);ii++)for(int jj=max(1ll,j-a[i][j].hxfw2);jj<=min(m,j+a[i][j].hxfw2);jj++)if(islower(a[ii][jj].c)&&a[ii][jj].h2<hp&&a[ii][jj].hx2==0)hp=a[ii][jj].h2,px=ii,py=jj;
                if(px&&py&&hp<a[px][py].H2){
                    a[px][py].h2=min(a[px][py].H2,a[px][py].h2+a[i][j].hx2),a[px][py].f=2,a[px][py].sst=clock();
                    out(px,py,0);
                }
            }
        }
    }
}
void game(){
    if(gk>48){
        cout<<"你通关了!!!";
        Sleep(3000);
        return;
    }
    srand(time(0));
    int cnt=0;
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)init_t(i,j),out(i,j,0);
    go(1,n*3+1);
    cout<<"第"<<gk<<"关                 \n";
    for(int i=1;i<=5;i++)cout<<"                                                         \n";
    for(;;){
        for(int i=1;i<=n;i++){
            if(islower(a[i][1].c)){
                go(1,n*3+4);
                Sleep(1000);
                cout<<"敌人突破防线,你输了\n你会在3秒后复活";
                Sleep(3000);
                buzhen(0);
                return;
            }
        }
        t_atk(),t_hx();
        for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)a[i][j].f=0;
        e_atk(),e_hx();
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(a[i][j].sst&&(clock()-a[i][j].sst)*1000.0/CLOCKS_PER_SEC>=50){
                    a[i][j].f=a[i][j].sst=0;
                    if((isupper(a[i][j].c)&&a[i][j].th<=0)||(islower(a[i][j].c)&&a[i][j].h2<=0))clear(i,j);
                    out(i,j,0);
                }
            }
        }
        int f=1;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(islower(a[i][j].c)){
                    f=0;
                    break;
                }
            }
        }
        if(f){
            go(1,n*3+3);
            cout<<"你过关了!";
            Sleep(2000);
            buzhen(1);
            return;
        }
    }
}
signed main(){
    srand(time(0));
    initgame();
    buzhen(1);
    return 0;
}

摸金

#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <windows.h>
#include <algorithm>
#define int long long
using namespace std;

// ==================== 游戏常量 ====================
const int SKILL_COUNT = 6;
const int MAX_FLOORS = 3;
const int ROOMS_PER_FLOOR = 2;
const int INIT_BAG_CAP = 6;

// ★ Boss机制(增强)
const int BOSS_NORMAL_RATE = 8;
const int BOSS_DANGER_RATE = 18;
const int BOSS_ESCAPE_CHANCE = 30;

// ★★★ 段位系统 ★★★
enum Rank { BRONZE = 0, SILVER = 1, GOLD_RANK = 2, PLATINUM = 3, DIAMOND = 4, MASTER = 5 };
const string RANK_NAMES[] = {"青铜", "白银", "黄金", "铂金", "钻石", "大师"};
const int RANK_WIN_MONEY[] = {8000, 50000, 300000, 2000000, 15000000, 100000000};
const int RANK_UNLOCK_EARNED[] = {0, 30000, 200000, 1500000, 10000000, 80000000};

// ★★★ 难度系统 ★★★
const int DIFFICULTY_WIN_MONEY[][6] = {
    {8000, 50000, 300000, 2000000, 15000000, 100000000},        // 普通
    {300000, 1000000, 5000000, 30000000, 200000000, 1000000000}, // 困难
    {6000000, 20000000, 100000000, 500000000, 3000000000, 15000000000} // 噩梦
};

// ★★★ 动态地图大小 ★★★
struct MapConfig {
    int areaCount;
    int totalItems;
    vector<string> areaNames;
    vector<string> mapLabels;
    vector<vector<int>> adj;
    vector<int> adjCnt;
    vector<bool> hasFloors;
    vector<bool> isDanger;
};

MapConfig currentMap;
int AREA_COUNT;
int TOTAL_ITEMS;
string* AREA_NAMES;
string* MAP_LABEL;
vector<vector<int>> ADJ;
vector<int> ADJ_CNT;
vector<bool> HAS_FLOORS;
vector<bool> IS_DANGER;
int WIN_MONEY;

// 品质系统
enum Quality { WHITE = 0, GREEN = 1, GOLD = 2, PURPLE = 3, RED = 4, MYTH = 5, SHINE = 6, SUPER = 7 };
const string Q_TAG[] = {"[白]", "[绿]", "[金]", "[紫]", "[红]", "[彩]", "[炫]", "[神]"};
const int Q_PRICE_MULT[] = {1, 4, 15, 50, 200, 1000, 5000, 25000};

// 爆率
const int Q_WEIGHTS_BASE[] = {700, 200, 60, 25, 10, 5, 0, 0};
const int Q_WEIGHTS_DANGER[] = {620, 220, 85, 45, 20, 10, 0, 0};
const int Q_WEIGHTS_HARD[] = {600, 220, 90, 50, 25, 10, 4, 1};
const int Q_WEIGHTS_HARD_DANGER[] = {520, 220, 110, 70, 45, 25, 8, 2};
const int Q_WEIGHTS_NIGHTMARE[] = {550, 200, 100, 70, 40, 25, 12, 3};
const int Q_WEIGHTS_NIGHTMARE_DANGER[] = {470, 190, 115, 90, 65, 40, 25, 5};

struct Item {
    string name; 
    Quality q; 
    bool taken;
    int loc, floor, room, price;
};

struct Skill { string name; string desc; int cost; bool has; };
Skill skills[SKILL_COUNT] = {
    {"透视眼镜", "显示所有未拾取物品位置", 80, false},
    {"空间瞬移", "传送到任意地面区域", 120, false},
    {"隐身护盾", "立即结束Boss追逐", 150, false},
    {"时间怀表", "Boss追逐额外+2回合缓冲", 100, false},
    {"黄金手套", "下次拾取品质+2级", 200, false},
    {"商人执照", "出售价格永久翻倍", 300, false}
};

struct BagUpgrade { string name; int cap; int cost; bool bought; };
BagUpgrade bagShop[3] = {
    {"帆布挎包", 12, 150, false},
    {"登山背包", 24, 400, false},
    {"战术驮包", 48, 900, false}
};

// ★★★ 赛前道具系统 ★★★
struct PreGameItem {
    string name;
    string desc;
    int cost;
    int count;
};

PreGameItem preGameShop[4] = {
    {"免死金牌", "抵御一次Boss直接淘汰", 500000, 0},
    {"防掉链", "防止Boss追击时掉落物品", 300000, 0},
    {"幸运符", "下次搜索必得高品质物品", 200000, 0},
    {"护身符", "Boss出现概率降低50%", 400000, 0}
};

bool immunityActive = false;
bool antiDropActive = false;
bool luckyCharmActive = false;
bool protectionActive = false;

// ★★★ 仓库系统 ★★★
vector<Item> warehouse;

bool goldGloveOn = false, merchantLic = false;
int trainBuff = 0;

// ==================== 物品池 ====================
struct NameEntry { string name; int basePrice; };

const NameEntry POOL_WHITE[] = {
    {"空矿泉水瓶",1},{"揉成团的草稿纸",1},{"一次性筷子",1},{"破损快递盒",2},
    {"用完的笔芯",1},{"食堂打包袋",2},{"褪色宣传单",1},{"断掉的橡皮筋",1},
    {"旧鞋带",2},{"生锈回形针",1},{"过期优惠券",1},{"干瘪橘子皮",1},
    {"破洞袜子",3},{"缺角笔记本",2},{"没墨记号笔",1},{"压扁易拉罐",1},
    {"食堂纸巾",1},{"磨损钥匙扣",3},{"碎玻璃片",1},{"缠绕数据线",4},
    {"干枯树枝",1},{"褪色贴纸",2},{"空奶精罐",1},{"破雨伞骨架",3},
    {"旧报纸",2},{"断裂梳子",2},{"空酸奶盒",1},{"磨花镜片",3},
    {"掉漆徽章",2},{"脏抹布",1},{"废电池",2},{"塑料瓶盖",1},
    {"卷边海报",3},{"断铅笔",1},{"油渍围裙",4},{"破手套",2},
    {"烂菜叶",1},{"碎砖块",1},{"旧信封",2},{"断尺子",1},
    {"空胶水瓶",2},{"磨损鼠标垫",3},{"破拖鞋",4},{"旧日历",2},
    {"空茶包",1},{"断发圈",1},{"碎布头",2},{"旧标签",1},
    {"空调味包",1},{"破网兜",2},{"旧票根",3},{"粉笔头",1},
    {"橡皮屑",1},{"枯花瓣",1},{"纸杯",1},{"吸管",1}
};
const int SZ_W = 56;

const NameEntry POOL_GREEN[] = {
    {"二手充电宝",30},{"宿舍小风扇",25},{"不锈钢保温杯",20},{"蓝牙音箱",45},
    {"机械键盘(微瑕)",60},{"护眼台灯",35},{"收纳箱套装",28},{"电子体重秤",30},
    {"正版教材(九新)",40},{"运动护膝",25},{"便携烧水壶",35},{"折叠晾衣架",20},
    {"无线鼠标",30},{"金属手机支架",18},{"桌面加湿器",40},{"降噪耳塞",25},
    {"多功能工具钳",35},{"速干毛巾套装",22},{"迷你投影仪(旧)",70},{"电竞椅垫",30},
    {"遮光床帘",28},{"USB扩展坞",35},{"移动硬盘盒",25},{"品牌中性笔套",20},
    {"精装词典",35},{"Kindle(划痕)",75},{"老式手电筒",15},{"基础工具箱",30},
    {"专业钉鞋(二手)",50},{"厨师帽(干净)",20},{"大号汤勺",15},{"蒸笼屉布",12},
    {"古籍修复入门套",45},{"文献索引卡",20},{"防毒面具(过期)",35},{"撬棍(小)",25},
    {"旧电路板(可拆)",30},{"单人电热毯",45},{"迷你消毒柜",50},{"临期灭火器",25},
    {"高清放大镜",30},{"木质书立",15},{"焊接面罩(旧)",35},{"手动液压钳",40},
    {"入门滑板",55},{"儿童轮滑鞋",40},{"保温饭盒",25},{"便携缝纫包",18}
};
const int SZ_G = 48;

const NameEntry POOL_GOLD[] = {
    {"限定动漫手办",250},{"Cherry键盘(全新)",400},{"高端无人认领包裹",300},
    {"进口咖啡机(二手)",350},{"手写祖传菜谱",200},{"纯银餐具套装",450},
    {"遗失银项链",280},{"皮质神秘日记",200},{"校庆纪念银币",300},
    {"大疆无人机(旧)",500},{"民国绝版古籍",600},{"名家书法小品",400},
    {"古董留声机(可修)",350},{"黄铜保险密码盘",250},{"市级比赛奖杯",280},
    {"省队签名运动服",320},{"生肖绝版邮票册",400},{"隐藏款盲盒",250},
    {"AJ球鞋(微氧化)",450},{"Switch港版",380},{"索尼微单套机",550},
    {"施华洛世奇酒杯",300},{"初版哈利波特",500},{"钛合金精密齿轮",350},
    {"高端降噪耳机",400},{"专业绘图板",350},{"vintage胶片相机",480}
};
const int SZ_GO = 27;

const NameEntry POOL_PURPLE[] = {
    {"动漫原画稿",1200},{"马丁全单吉他",2000},{"海外直邮神秘件",1500},
    {"米其林厨师笔记",1800},{"百年老卤汁配方",1000},{"校长亲笔题词",1500},
    {"冷战军用电台",1800},{"奥运火炬模型",2200},{"古董招财猫",1200},
    {"状元高数笔记",1500},{"命题组考研原稿",1800},{"专业分子料理设备",2500},
    {"百年陈酿(sealed)",2000},{"达芬奇手稿限量复刻",2200},{"羊皮纸炼金笔记",1800},
    {"二代军用夜视仪",2000},{"专业核辐射检测仪",2200},{"清代民窑瓷碗",1500},
    {"袁大头银元",1200},{"绝版黑胶唱片",1600},{"青铜镇纸",1400}
};
const int SZ_P = 21;

const NameEntry POOL_RED[] = {
    {"学长传家玉佩",4000},{"1克拉钻戒快递",6000},{"清代御膳房令牌",5000},
    {"野生千年灵芝",4500},{"纯金奠基仪式铲",7000},{"永乐大典残卷真迹",8000},
    {"疑似外星金属片",6000},{"博尔特签名战靴",7500},{"铜鎏金聚宝盆",5000},
    {"院士亲笔推荐信",3500},{"纯金诺贝尔仿章",6000},{"天然龙涎香",7000},
    {"完整凤凰蛋化石",8000},{"死海文书高精复制",6500},{"伏尼契手稿精仿",7000},
    {"铁镍陨石核心",7500},{"宋代曜变建盏",8000},{"唐三彩马残件",5500}
};
const int SZ_R = 18;

const NameEntry POOL_MYTH[] = {
    {"闹鬼录像带母带",12000},{"时空胶囊未来信",15000},{"纯金镶钻食神碗",20000},
    {"发光世界树种子",25000},{"青铜校园龙脉罗盘",18000},{"阿卡夏水晶碎片",30000},
    {"古希腊潘多拉魔盒",28000},{"黄金赫尔墨斯飞翼",25000},{"贤者之石点金石",30000},
    {"次元壁裂缝稳定器",20000},{"逆流时光沙漏",28000},{"青铜饕餮之牙",25000},
    {"商周神农鼎碎片",30000},{"蓝宝石全知之眼",28000},{"宇宙真理手抄本",30000},
    {"达芬奇永动机原型",25000}
};
const int SZ_M = 16;

const NameEntry POOL_SHINE[] = {
    {"星空之门钥匙",50000},{"量子纠缠对戒",65000},{"时间管理局徽章",80000},
    {"平行宇宙导航仪",70000},{"永恒之枪冈格尼尔",120000},{"宇宙魔方碎片",90000},
    {"圣杯(真品)",150000},{"贤者之石(完整)",180000},{"生命之树果实",100000},
    {"命运之轮",85000},{"混沌之眼",95000},{"创世神之泪",200000},
    {"次元穿梭器",110000},{"无限宝石(仿)",75000},{"永恒之火种",130000},
    {"灵魂之井钥匙",88000},{"真理之门碎片",92000},{"神之左手",160000},
    {"宇宙之心",190000},{"万物起源之书",200000}
};
const int SZ_SH = 20;

const NameEntry POOL_SUPER[] = {
    {"创世神权杖",500000},{"宇宙大爆炸奇点",800000},{"上帝之眼",1000000},
    {"全知全能之冠",1200000},{"维度之主权戒",900000},{"现实宝石(真品)",1500000},
    {"时间宝石(真品)",1500000},{"空间宝石(真品)",1500000},{"力量宝石(真品)",1500000},
    {"心灵宝石(真品)",1500000},{"灵魂宝石(真品)",1500000},{"宇宙之心(完整)",2000000},
    {"创世之柱",1800000},{"万物终结之剑",2500000},{"永恒轮回之环",2200000},
    {"绝对零度之核",1600000},{"无限维度之镜",1900000},{"神之领域钥匙",2800000},
    {"宇宙法则之书",3000000},{"存在本身",3000000}
};
const int SZ_SU = 20;

// ==================== 全局状态 ====================
int playerLoc = 0, playerFloor = 0, playerRoom = 0;
int money = 0, turnCount = 0;
int bagCap = INIT_BAG_CAP;
bool bossActive = false;
int bossBufferLeft = 0;
bool shieldOn = false, timeWatchOn = false;
vector<Item> bag;
vector<Item> worldItems;
int worldItemCount = 0;
bool gameRunning = true;
bool gameEliminated = false;
int totalWins = 0;
int totalEarned = 0;
Rank currentRank = BRONZE;
int currentDifficulty = 0;

// ==================== 函数前置声明 ====================
Quality rollQuality(bool dangerZone);
string pickName(Quality q, int& outBasePrice);
void generateRandomMap();
void generateWorldItems();
void resetGameState();
void initGame();
bool checkWin();
string getLocDesc();
void showMap();
void showAdjacent();
void moveFloor();
void moveRoom();
void backToGround();
void pickItem();
void sellItems();
void buyShop();
void useSkill();
void useBuildingSpecial();
void triggerBoss();
void handleBoss();
void showHelp();
void clearScreen();
void selectDifficulty();
void updateRank();
bool canPlayDifficulty(int diff);
void restFunction();
void tradeFunction();
void gambleFunction();
void exploreFunction();
void trainFunction();
void healFunction();
void hideFunction();
void infoFunction();
void craftFunction();
int getBuildingFunction(int areaIndex);
void buyPreGameItems();
void showWarehouse();
void dropItem();

// ==================== 建筑特殊功能 ====================
enum SpecialFunction {
    NONE = 0, REST = 1, TRADE = 2, GAMBLE = 3, EXPLORE = 4, 
    TRAIN = 5, HEAL = 6, HIDE = 7, INFO = 8, CRAFT = 10
};

int getBuildingFunction(int areaIndex) {
    string areaName = AREA_NAMES[areaIndex];

    if (areaName.find("宿舍") != string::npos) return REST;
    if (areaName.find("快递") != string::npos) return TRADE;
    if (areaName.find("食堂") != string::npos) return HEAL;
    if (areaName.find("树林") != string::npos) return EXPLORE;
    if (areaName.find("广场") != string::npos) return INFO;
    if (areaName.find("图书") != string::npos) return TRAIN;
    if (areaName.find("仓库") != string::npos) return EXPLORE;
    if (areaName.find("操场") != string::npos) return TRAIN;
    if (areaName.find("商店") != string::npos) return TRADE;
    if (areaName.find("实验") != string::npos) return CRAFT;
    if (areaName.find("艺术") != string::npos) return GAMBLE;
    if (areaName.find("体育") != string::npos) return TRAIN;
    if (areaName.find("车库") != string::npos) return HIDE;
    if (areaName.find("花园") != string::npos) return HEAL;
    if (areaName.find("校门") != string::npos) return INFO;
    if (areaName.find("人工湖") != string::npos) return REST;
    if (areaName.find("医务室") != string::npos) return HEAL;
    if (areaName.find("广播") != string::npos) return INFO;
    if (areaName.find("印刷") != string::npos) return CRAFT;
    if (areaName.find("停车") != string::npos) return HIDE;

    return NONE;
}

// 休息功能
void restFunction() {
    cout << "\n=== 休息区 ===\n";
    if (bossActive) {
        cout << "你在这里休息了一会...\n";
        if (rand() % 100 < 50) {
            bossActive = false;
            cout << "成功摆脱了教导主任的追击!\n";
        } else {
            cout << "但主任还在附近徘徊...\n";
        }
    } else {
        cout << "这里很安静,适合休息。\n";
        if (money > 0 && rand() % 100 < 20) {
            int found = rand() % 5 + 1;
            money += found;
            cout << "你在地上发现了" << found << "元零钱!\n";
        }
    }
}

// 交易功能
void tradeFunction() {
    if (playerFloor > 0) return;
    cout << "\n=== 交易区 ===\n";
    if (bag.empty()) {
        cout << "你的背包是空的,没什么可交易的。\n";
        return;
    }
    cout << "选择要交易的物品:\n";
    for (int i = 0; i < (int)bag.size(); i++) {
        cout << "[" << i+1 << "] " << Q_TAG[bag[i].q] << bag[i].name 
             << " (价值:" << bag[i].price << ")\n";
    }
    cout << "[0] 取消\n选择: ";
    int choice;
    cin >> choice;
    if (choice < 1 || choice > (int)bag.size()) return;

    int itemIdx = choice - 1;
    Item tradedItem = bag[itemIdx];

    if (rand() % 100 < 40) {
        int cashValue = tradedItem.price * (110 + rand() % 20) / 100;
        money += cashValue;
        bag.erase(bag.begin() + itemIdx);
        cout << "交易成功! 获得" << cashValue << "元现金!\n";
    } else {
        cout << "交易失败,没人愿意换。\n";
    }
}

// 赌博功能
void gambleFunction() {
    cout << "\n=== 赌博区 ===\n";
    cout << "当前金币: " << money << "\n";
    cout << "[1] 押注100元 (40%概率翻倍)\n";
    cout << "[2] 押注500元 (30%概率翻3倍)\n";
    cout << "[3] 押注2000元 (20%概率翻5倍)\n";
    cout << "[0] 离开\n选择: ";

    int choice;
    cin >> choice;
    int bet = 0, winChance = 0, multiplier = 0;

    switch(choice) {
        case 1: bet = 100; winChance = 40; multiplier = 2; break;
        case 2: bet = 500; winChance = 30; multiplier = 3; break;
        case 3: bet = 2000; winChance = 20; multiplier = 5; break;
        default: return;
    }

    if (money < bet) { cout << "金币不足!\n"; return; }
    money -= bet;
    if (rand() % 100 < winChance) {
        int win = bet * multiplier;
        money += win;
        cout << "恭喜! 你赢了" << win << "元!\n";
    } else {
        cout << "很遗憾,你输了" << bet << "元...\n";
    }
}

// 深度探索功能
void exploreFunction() {
    cout << "\n=== 探索区 ===\n";
    cout << "你开始仔细搜索这个区域...\n";

    int successRate = 50 + (IS_DANGER[playerLoc] ? 20 : 0);
    if (rand() % 100 < successRate) {
        Quality q = rollQuality(IS_DANGER[playerLoc]);
        int basePrice;
        string name = pickName(q, basePrice);
        int finalPrice = basePrice * Q_PRICE_MULT[q];

        cout << "你发现了隐藏物品: " << Q_TAG[q] << name 
             << " (价值:" << finalPrice << ")\n";

        if ((int)bag.size() < bagCap) {
            bag.push_back({name, q, true, playerLoc, playerFloor, playerRoom, finalPrice});
            cout << "已放入背包!\n";
        } else {
            cout << "但背包已满,无法携带...\n";
        }
    } else {
        cout << "什么也没找到。\n";
    }
}

// 训练功能
void trainFunction() {
    cout << "\n=== 训练区 ===\n";
    cout << "[1] 体能训练 (50元) - 下次Boss逃脱率+30%\n";
    cout << "[2] 技巧训练 (100元) - 下次拾取品质提升\n";
    cout << "[0] 离开\n选择: ";

    int choice;
    cin >> choice;

    switch(choice) {
        case 1:
            if (money >= 50) {
                money -= 50;
                trainBuff = 1;
                cout << "训练完成! 体能提升!\n";
            } else cout << "金币不足!\n";
            break;
        case 2:
            if (money >= 100) {
                money -= 100;
                goldGloveOn = true;
                cout << "训练完成! 下次拾取品质提升!\n";
            } else cout << "金币不足!\n";
            break;
    }
}

// 治疗功能
void healFunction() {
    cout << "\n=== 治疗区 ===\n";
    if (bossActive) {
        if (rand() % 100 < 60) {
            bossActive = false;
            cout << "你成功躲避了教导主任!\n";
        }
    } else {
        cout << "这里很安静,你放松了一下。\n";
        if (bag.size() > 0 && rand() % 100 < 15) {
            int found = rand() % 30 + 5;
            money += found;
            cout << "整理背包时发现" << found << "元!\n";
        }
    }
}

// 躲藏功能
void hideFunction() {
    cout << "\n=== 躲藏区 ===\n";
    if (bossActive) {
        if (rand() % 100 < 70) {
            bossActive = false;
            cout << "你成功躲过了教导主任!\n";
        } else {
            cout << "但还是被发现了!\n";
        }
    } else {
        cout << "这里很隐蔽,适合躲藏。\n";
        if (rand() % 100 < 25) {
            Quality q = rollQuality(false);
            int basePrice;
            string name = pickName(q, basePrice);
            int finalPrice = basePrice * Q_PRICE_MULT[q];

            if ((int)bag.size() < bagCap) {
                bag.push_back({name, q, true, playerLoc, playerFloor, playerRoom, finalPrice});
                cout << "你发现了被藏起来的物品: " << Q_TAG[q] << name << "!\n";
            }
        }
    }
}

// 信息收集功能
void infoFunction() {
    cout << "\n=== 信息区 ===\n";
    cout << "你开始打听消息...\n";

    bool foundInfo = false;
    for (int i = 0; i < worldItemCount; i++) {
        if (!worldItems[i].taken && worldItems[i].q >= PURPLE) {
            cout << "听说" << AREA_NAMES[worldItems[i].loc] 
                 << "有价值" << worldItems[i].price << "元的物品!\n";
            foundInfo = true;
            break;
        }
    }

    if (!foundInfo) {
        cout << "没打听到什么有用的消息。\n";
    }
}

// 制作功能
void craftFunction() {
    cout << "\n=== 制作区 ===\n";
    if (bag.size() < 2) {
        cout << "需要至少2个物品才能制作。\n";
        return;
    }

    cout << "选择要合成的物品:\n";
    for (int i = 0; i < (int)bag.size(); i++) {
        cout << "[" << i+1 << "] " << Q_TAG[bag[i].q] << bag[i].name 
             << " (价值:" << bag[i].price << ")\n";
    }

    cout << "选择第一个物品 (0取消): ";
    int item1;
    cin >> item1;
    if (item1 < 1 || item1 > (int)bag.size()) return;

    cout << "选择第二个物品 (0取消): ";
    int item2;
    cin >> item2;
    if (item2 < 1 || item2 > (int)bag.size() || item2 == item1) return;

    Item combined;
    int avgQuality = ((int)bag[item1-1].q + (int)bag[item2-1].q) / 2;
    if (avgQuality > SUPER) avgQuality = SUPER;

    int avgPrice = (bag[item1-1].price + bag[item2-1].price) * 1.2;

    combined.q = (Quality)avgQuality;
    combined.name = "合成物品";
    combined.price = avgPrice;
    combined.taken = true;
    combined.loc = playerLoc;
    combined.floor = playerFloor;
    combined.room = playerRoom;

    if (item1 > item2) {
        bag.erase(bag.begin() + item1 - 1);
        bag.erase(bag.begin() + item2 - 1);
    } else {
        bag.erase(bag.begin() + item2 - 1);
        bag.erase(bag.begin() + item1 - 1);
    }

    bag.push_back(combined);
    cout << "合成成功! 获得" << Q_TAG[combined.q] << combined.name 
         << " (价值:" << combined.price << ")\n";
}

void useBuildingSpecial() {
    if (playerFloor > 0) {
        cout << "请先返回地面。\n";
        return;
    }

    int function = getBuildingFunction(playerLoc);

    switch(function) {
        case REST: restFunction(); break;
        case TRADE: tradeFunction(); break;
        case GAMBLE: gambleFunction(); break;
        case EXPLORE: exploreFunction(); break;
        case TRAIN: trainFunction(); break;
        case HEAL: healFunction(); break;
        case HIDE: hideFunction(); break;
        case INFO: infoFunction(); break;
        case CRAFT: craftFunction(); break;
        default:
            cout << "这里没有特殊功能。\n";
            break;
    }
}

// ==================== 地图生成 ====================
void generateRandomMap() {
    int baseAreas;
    switch(currentDifficulty) {
        case 0: baseAreas = 6 + rand() % 3; break;
        case 1: baseAreas = 8 + rand() % 3; break;
        case 2: baseAreas = 10 + rand() % 3; break;
    }

    AREA_COUNT = baseAreas;
    TOTAL_ITEMS = AREA_COUNT * 15 + rand() % 20;

    vector<string> namePool = {
        "学生宿舍", "快递站", "第一食堂", "小树林", "中心广场", "图书馆",
        "废弃仓库", "田径操场", "校园商店", "实验楼", "艺术中心", "体育馆",
        "地下车库", "天台花园", "旧校门", "人工湖", "医务室", "广播站",
        "印刷厂", "停车棚"
    };

    random_shuffle(namePool.begin(), namePool.end());

    currentMap.areaNames.clear();
    currentMap.mapLabels.clear();
    for (int i = 0; i < AREA_COUNT; i++) {
        currentMap.areaNames.push_back(namePool[i]);
        string label = namePool[i].substr(0, 2);
        currentMap.mapLabels.push_back(label);
    }

    currentMap.adj.assign(AREA_COUNT, vector<int>());
    currentMap.adjCnt.assign(AREA_COUNT, 0);

    for (int i = 0; i < AREA_COUNT - 1; i++) {
        currentMap.adj[i].push_back(i + 1);
        currentMap.adj[i + 1].push_back(i);
        currentMap.adjCnt[i]++;
        currentMap.adjCnt[i + 1]++;
    }

    int extraConnections = AREA_COUNT / 2 + rand() % (AREA_COUNT / 2);
    for (int i = 0; i < extraConnections; i++) {
        int a = rand() % AREA_COUNT;
        int b = rand() % AREA_COUNT;
        if (a != b && currentMap.adjCnt[a] < 4 && currentMap.adjCnt[b] < 4) {
            bool alreadyConnected = false;
            for (int j = 0; j < currentMap.adj[a].size(); j++) {
                if (currentMap.adj[a][j] == b) {
                    alreadyConnected = true;
                    break;
                }
            }
            if (!alreadyConnected) {
                currentMap.adj[a].push_back(b);
                currentMap.adj[b].push_back(a);
                currentMap.adjCnt[a]++;
                currentMap.adjCnt[b]++;
            }
        }
    }

    currentMap.hasFloors.assign(AREA_COUNT, false);
    currentMap.isDanger.assign(AREA_COUNT, false);

    int floorCount = AREA_COUNT / 3;
    int dangerCount = AREA_COUNT / 4;
    if (dangerCount < 1) dangerCount = 1;

    for (int i = 0; i < AREA_COUNT; i++) {
        if (i < floorCount) currentMap.hasFloors[i] = true;
        if (i >= AREA_COUNT - dangerCount) currentMap.isDanger[i] = true;
    }

    random_shuffle(currentMap.hasFloors.begin(), currentMap.hasFloors.end());
    random_shuffle(currentMap.isDanger.begin(), currentMap.isDanger.end());

    AREA_NAMES = currentMap.areaNames.data();
    MAP_LABEL = currentMap.mapLabels.data();
    ADJ = currentMap.adj;
    ADJ_CNT = currentMap.adjCnt;
    HAS_FLOORS = currentMap.hasFloors;
    IS_DANGER = currentMap.isDanger;
}

// ==================== 动态概率生成核心 ====================
Quality rollQuality(bool dangerZone) {
    const int* weights;

    switch(currentDifficulty) {
        case 1:
            weights = dangerZone ? Q_WEIGHTS_HARD_DANGER : Q_WEIGHTS_HARD;
            break;
        case 2:
            weights = dangerZone ? Q_WEIGHTS_NIGHTMARE_DANGER : Q_WEIGHTS_NIGHTMARE;
            break;
        default:
            weights = dangerZone ? Q_WEIGHTS_DANGER : Q_WEIGHTS_BASE;
            break;
    }

    int r = rand() % 1000;
    int cumulative = 0;
    for (int i = 0; i <= SUPER; i++) {
        cumulative += weights[i];
        if (r < cumulative) return (Quality)i;
    }
    return WHITE;
}

string pickName(Quality q, int& outBasePrice) {
    int idx;
    switch(q) {
        case WHITE:  idx = rand() % SZ_W;  outBasePrice = POOL_WHITE[idx].basePrice;  return POOL_WHITE[idx].name;
        case GREEN:  idx = rand() % SZ_G;  outBasePrice = POOL_GREEN[idx].basePrice;  return POOL_GREEN[idx].name;
        case GOLD:   idx = rand() % SZ_GO; outBasePrice = POOL_GOLD[idx].basePrice;   return POOL_GOLD[idx].name;
        case PURPLE: idx = rand() % SZ_P;  outBasePrice = POOL_PURPLE[idx].basePrice; return POOL_PURPLE[idx].name;
        case RED:    idx = rand() % SZ_R;  outBasePrice = POOL_RED[idx].basePrice;    return POOL_RED[idx].name;
        case MYTH:   idx = rand() % SZ_M;  outBasePrice = POOL_MYTH[idx].basePrice;   return POOL_MYTH[idx].name;
        case SHINE:  idx = rand() % SZ_SH; outBasePrice = POOL_SHINE[idx].basePrice;  return POOL_SHINE[idx].name;
        case SUPER:  idx = rand() % SZ_SU; outBasePrice = POOL_SUPER[idx].basePrice;  return POOL_SUPER[idx].name;
        default:     outBasePrice = 1; return "未知物品";
    }
}

struct SpawnPoint { int loc; int floor; int room; };
vector<SpawnPoint> spawnPoints;

void buildSpawnPoints() {
    spawnPoints.clear();
    for (int a = 0; a < AREA_COUNT; a++)
        spawnPoints.push_back({a, 0, 0});
    for (int a = 0; a < AREA_COUNT; a++) {
        if (!HAS_FLOORS[a]) continue;
        for (int f = 1; f <= MAX_FLOORS; f++)
            for (int r = 1; r <= ROOMS_PER_FLOOR; r++)
                spawnPoints.push_back({a, f, r});
    }
}

void generateWorldItems() {
    worldItems.clear();
    worldItemCount = 0;
    buildSpawnPoints();
    int spSize = (int)spawnPoints.size();

    for (int i = 0; i < TOTAL_ITEMS; i++) {
        const SpawnPoint& sp = spawnPoints[rand() % spSize];
        bool danger = IS_DANGER[sp.loc];
        Quality q = rollQuality(danger);
        int basePrice;
        string name = pickName(q, basePrice);
        int finalPrice = basePrice * Q_PRICE_MULT[q];

        worldItems.push_back({name, q, false, sp.loc, sp.floor, sp.room, finalPrice});
        worldItemCount++;
    }
}

// ==================== 段位系统 ====================
void updateRank() {
    Rank newRank = BRONZE;
    for (int i = MASTER; i >= BRONZE; i--) {
        if (totalEarned >= RANK_UNLOCK_EARNED[i]) {
            newRank = (Rank)i;
            break;
        }
    }

    if (newRank != currentRank) {
        cout << "\n*** 段位提升! " << RANK_NAMES[currentRank] << " -> " << RANK_NAMES[newRank] << " ***\n";
        cout << "新的撤离目标: " << DIFFICULTY_WIN_MONEY[currentDifficulty][newRank] << "元\n";
        currentRank = newRank;
    }
}

bool canPlayDifficulty(int diff) {
    switch(diff) {
        case 0: return currentRank >= BRONZE;
        case 1: return currentRank >= SILVER;
        case 2: return currentRank >= GOLD_RANK;
    }
    return false;
}

// ==================== 赛前道具购买 ====================
void buyPreGameItems() {
    clearScreen();
    cout << "========================================\n";
    cout << "   赛前道具商店 - 累计金币: " << totalEarned << "\n";
    cout << "========================================\n";

    for (int i = 0; i < 4; i++) {
        cout << "[" << i+1 << "] " << preGameShop[i].name 
             << " - " << preGameShop[i].desc
             << " | 价格: " << preGameShop[i].cost 
             << " | 拥有: " << preGameShop[i].count << "\n";
    }
    cout << "[5] 查看仓库 (" << warehouse.size() << "件藏品)\n";
    cout << "[0] 开始游戏\n";
    cout << "选择: ";

    int choice;
    cin >> choice;

    if (choice == 0) return;

    if (choice == 5) {
        showWarehouse();
        buyPreGameItems();
        return;
    }

    if (choice >= 1 && choice <= 4) {
        int idx = choice - 1;
        if (totalEarned >= preGameShop[idx].cost) {
            totalEarned -= preGameShop[idx].cost;
            preGameShop[idx].count++;
            cout << "购买成功! " << preGameShop[idx].name 
                 << " x" << preGameShop[idx].count << "\n";
            Sleep(1500);
        } else {
            cout << "金币不足! 需要" << preGameShop[idx].cost 
                 << ",当前累计: " << totalEarned << "\n";
            Sleep(1500);
        }
        buyPreGameItems();
    }
}

// ==================== 仓库系统 ====================
void showWarehouse() {
    clearScreen();
    cout << "========================================\n";
    cout << "   仓库 - 藏品 (" << warehouse.size() << "件)\n";
    cout << "========================================\n";

    if (warehouse.empty()) {
        cout << "仓库是空的。\n";
    } else {
        for (int i = 0; i < (int)warehouse.size(); i++) {
            cout << "[" << i+1 << "] " << Q_TAG[warehouse[i].q] 
                 << warehouse[i].name << " (价值:" << warehouse[i].price << ")\n";
        }
    }

    cout << "\n按回车返回...";
    cin.ignore(); cin.get();
}

// ==================== 初始化 ====================
void resetGameState() {
    playerLoc = 0; playerFloor = 0; playerRoom = 0;
    money = 0; turnCount = 0;
    bagCap = INIT_BAG_CAP;
    bossActive = false;
    bossBufferLeft = 0;
    shieldOn = false; timeWatchOn = false;
    goldGloveOn = false; merchantLic = false;
    trainBuff = 0;
    gameEliminated = false;
    bag.clear();

    immunityActive = false;
    antiDropActive = false;
    luckyCharmActive = false;
    protectionActive = false;

    if (preGameShop[0].count > 0) {
        immunityActive = true;
        preGameShop[0].count--;
        cout << "* 免死金牌已激活!\n";
    }
    if (preGameShop[1].count > 0) {
        antiDropActive = true;
        preGameShop[1].count--;
        cout << "* 防掉链已激活!\n";
    }
    if (preGameShop[2].count > 0) {
        luckyCharmActive = true;
        preGameShop[2].count--;
        cout << "* 幸运符已激活!\n";
    }
    if (preGameShop[3].count > 0) {
        protectionActive = true;
        preGameShop[3].count--;
        cout << "* 护身符已激活!\n";
    }

    for (int i = 0; i < SKILL_COUNT; i++) {
        skills[i].has = false;
    }

    for (int i = 0; i < 3; i++) {
        bagShop[i].bought = false;
    }

    generateRandomMap();
    generateWorldItems();

    WIN_MONEY = DIFFICULTY_WIN_MONEY[currentDifficulty][currentRank];
}

void initGame() {
    srand((unsigned)time(NULL));
    SetConsoleOutputCP(936);
    SetConsoleCP(936);

    resetGameState();

    cout << "========================================\n";
    cout << "   校园摸金模拟器 v15.0\n";
    cout << "   段位: " << RANK_NAMES[currentRank] << "\n";
    cout << "   目标: 攒够" << WIN_MONEY << "元即可胜利!\n";

    string diffName = currentDifficulty == 0 ? "普通" : 
                      currentDifficulty == 1 ? "困难" : "噩梦";
    cout << "   当前难度: " << diffName << "\n";
    cout << "   地图大小: " << AREA_COUNT << "个区域\n";
    cout << "   物品总数: " << TOTAL_ITEMS << "个\n";
    cout << "   累计赚取: " << totalEarned << "金币\n";

    if (currentDifficulty == 0) {
        cout << "   概率: 白70% 绿20% 金6% 紫2.5% 红1% 彩0.5%\n";
    } else if (currentDifficulty == 1) {
        cout << "   概率: 白60% 绿22% 金9% 紫5% 红2.5% 彩1% 炫0.4% 神0.1%\n";
    } else {
        cout << "   概率: 白55% 绿20% 金10% 紫7% 红4% 彩2.5% 炫1.2% 神0.3%\n";
    }

    cout << "   Boss: 普通区8% | 危险区18% | 每回合30%逃脱\n";
    if (currentDifficulty == 2) {
        cout << "   !!! 噩梦模式: 被Boss追到有概率直接淘汰 !!!\n";
    }
    cout << "========================================\n";
    cout << "提示: 输入H查看帮助\n\n";
}

bool checkWin() {
    if (money >= WIN_MONEY) {
        cout << "\n*** 你已攒够" << WIN_MONEY << "元! ***\n";
        cout << "当前金币: " << money << "\n";
        cout << "背包物品:\n";
        for (int i = 0; i < (int)bag.size(); i++) {
            cout << "  " << Q_TAG[bag[i].q] << bag[i].name 
                 << " (价值:" << bag[i].price << ")\n";
        }
        cout << "\n[1] 立即撤离(胜利)\n";
        cout << "[2] 继续游戏(可收集更多藏品)\n";
        cout << "选择: ";

        int choice;
        cin >> choice;

        if (choice == 1) {
            totalWins++;
            totalEarned += money;

            cout << "\n=== 撤离成功! ===\n";
            cout << "将高品质藏品放入仓库...\n";
            int warehouseCount = 0;
            for (int i = bag.size() - 1; i >= 0; i--) {
                if (bag[i].q >= PURPLE) {
                    warehouse.push_back(bag[i]);
                    cout << "存入: " << Q_TAG[bag[i].q] << bag[i].name << "\n";
                    bag.erase(bag.begin() + i);
                    warehouseCount++;
                }
            }

            if (!bag.empty()) {
                int sellTotal = 0;
                for (int i = 0; i < (int)bag.size(); i++) {
                    sellTotal += bag[i].price;
                }
                totalEarned += sellTotal;
                cout << "剩余物品出售获得: " << sellTotal << "金币\n";
            }

            if (warehouseCount > 0) {
                cout << "共" << warehouseCount << "件藏品存入仓库!\n";
            }

            cout << "总回合: " << turnCount << " | 本局获得: " << money << "\n";
            cout << "累计通关: " << totalWins << "次 | 累计赚取: " << totalEarned << "金币\n";

            updateRank();

            cout << "\n按回车返回难度选择...";
            cin.ignore(); cin.get();
            return true;
        } else {
            cout << "继续游戏!\n";
            return false;
        }
    }
    return false;
}

string getLocDesc() {
    string desc = AREA_NAMES[playerLoc];
    if (playerFloor > 0) {
        desc += " " + to_string(playerFloor) + "楼";
        desc += (playerRoom > 0) ? (" " + to_string(playerRoom) + "号房") : " 走廊";
    }
    if (IS_DANGER[playerLoc] && playerFloor == 0) desc += " [!]";
    return desc;
}

void showMap() {
    cout << "\n--- 当前地图 (" << AREA_COUNT << "个区域) ---\n";
    for (int i = 0; i < AREA_COUNT; i++) {
        string tag = IS_DANGER[i] ? "!" : " ";
        if (i == playerLoc && playerFloor == 0) 
            cout << "[" << tag << MAP_LABEL[i] << "]";
        else 
            cout << " " << tag << MAP_LABEL[i] << " ";
        if ((i + 1) % 4 == 0) cout << "\n";
    }

    string diffName = currentDifficulty == 0 ? "普通" : 
                      currentDifficulty == 1 ? "困难" : "噩梦";
    cout << "\n(!=危险区) 位置: " << getLocDesc() 
         << " | 金币:" << money << "/" << WIN_MONEY
         << " | 背包:" << bag.size() << "/" << bagCap
         << " | " << diffName << " | " << RANK_NAMES[currentRank]
         << " | 累计:" << totalEarned << "\n";
}

void showAdjacent() {
    if (playerFloor > 0) {
        cout << "楼内: [F]上下楼 [R]进出房间 [P]搜寻 [B]返回地面\n";
        return;
    }
    cout << "可前往: ";
    for (int i = 0; i < ADJ_CNT[playerLoc]; i++) {
        int next = ADJ[playerLoc][i];
        string danger = IS_DANGER[next] ? "[!]" : "";
        cout << "[" << i+1 << "]" << AREA_NAMES[next] << danger << " ";
    }
    if (HAS_FLOORS[playerLoc]) cout << "[F]进入楼栋 ";
    cout << "\n";

    int func = getBuildingFunction(playerLoc);
    if (func != NONE) {
        cout << "当前位置功能: [E]";
        switch(func) {
            case REST: cout << "休息"; break;
            case TRADE: cout << "交易"; break;
            case GAMBLE: cout << "赌博"; break;
            case EXPLORE: cout << "探索"; break;
            case TRAIN: cout << "训练"; break;
            case HEAL: cout << "治疗"; break;
            case HIDE: cout << "躲藏"; break;
            case INFO: cout << "打听消息"; break;
            case CRAFT: cout << "制作"; break;
        }
        cout << "\n";
    }
}

// ==================== 楼层移动 ====================
void moveFloor() {
    if (!HAS_FLOORS[playerLoc]) { cout << "这里不是楼房!\n"; return; }
    if (playerFloor == 0) { playerFloor = 1; playerRoom = 0; cout << "进入1楼走廊\n"; return; }
    cout << "当前" << playerFloor << "楼 [1]上 [2]下 [0]取消: ";
    int c; cin >> c;
    if (c == 1 && playerFloor < MAX_FLOORS) { playerFloor++; playerRoom = 0; cout << "上到" << playerFloor << "楼\n"; }
    else if (c == 2) { playerFloor--; playerRoom = 0; cout << (playerFloor == 0 ? "回到地面\n" : "下到" + to_string(playerFloor) + "楼\n"); }
}

void moveRoom() {
    if (playerFloor == 0) { cout << "请先上楼!\n"; return; }
    if (playerRoom == 0) {
        cout << "选择: [1]" << playerFloor << "01室 [2]" << playerFloor << "02室 [0]取消: ";
        int c; cin >> c;
        if (c >= 1 && c <= ROOMS_PER_FLOOR) { playerRoom = c; cout << "进入" << playerFloor << "0" << c << "室\n"; }
    } else { playerRoom = 0; cout << "返回走廊\n"; }
}

void backToGround() {
    if (playerFloor == 0) { cout << "已在地面。\n"; return; }
    playerFloor = 0; playerRoom = 0;
    cout << "回到地面: " << AREA_NAMES[playerLoc] << "\n";
}

// ==================== 搜寻物品 ====================
void pickItem() {
    if ((int)bag.size() >= bagCap) {
        cout << "背包已满(" << bag.size() << "/" << bagCap << ")! 去商店出售或扩容。\n";
        return;
    }
    vector<int> avail;
    for (int i = 0; i < worldItemCount; i++) {
        if (worldItems[i].taken || worldItems[i].loc != playerLoc || worldItems[i].floor != playerFloor) continue;
        if (playerFloor > 0 && worldItems[i].room != playerRoom) continue;
        avail.push_back(i);
    }
    if (avail.empty()) { cout << "这里没有可拾取的物品。\n"; return; }
    cout << "发现物品:\n";
    for (int i = 0; i < (int)avail.size(); i++)
        cout << "[" << i+1 << "] " << Q_TAG[worldItems[avail[i]].q] << worldItems[avail[i]].name
             << " (价值:" << worldItems[avail[i]].price << ")\n";
    cout << "选择(0取消): ";
    int c; cin >> c;
    if (c < 1 || c > (int)avail.size()) return;

    int idx = avail[c-1];
    if (goldGloveOn || luckyCharmActive) {
        int oldQ = (int)worldItems[idx].q;
        int newQ = oldQ + 2;
        if (newQ > SUPER) newQ = SUPER;
        int base = worldItems[idx].price / Q_PRICE_MULT[oldQ];
        if (base <= 0) base = 1;
        worldItems[idx].q = (Quality)newQ;
        worldItems[idx].price = base * Q_PRICE_MULT[newQ];
        if (goldGloveOn) {
            goldGloveOn = false;
            cout << "* 黄金手套生效! 升级为" << Q_TAG[newQ] << "!\n";
        }
        if (luckyCharmActive) {
            luckyCharmActive = false;
            cout << "* 幸运符生效! 升级为" << Q_TAG[newQ] << "!\n";
        }
    }
    worldItems[idx].taken = true;
    bag.push_back(worldItems[idx]);
    cout << "获得: " << Q_TAG[bag.back().q] << bag.back().name
         << " | 背包:" << bag.size() << "/" << bagCap << "\n";
}

// ==================== 丢弃物品 ====================
void dropItem() {
    if (bag.empty()) { 
        cout << "背包为空,没有可丢弃的物品。\n"; 
        return; 
    }

    while (true) {
        cout << "\n--- 背包(" << bag.size() << "/" << bagCap << ") ---\n";
        for (int i = 0; i < (int)bag.size(); i++) {
            cout << "[" << i+1 << "] " << Q_TAG[bag[i].q] << bag[i].name 
                 << " (价值:" << bag[i].price << ")\n";
        }
        cout << "[0] 取消丢弃\n";
        cout << "选择要丢弃的物品: ";

        int c;
        cin >> c;

        if (c == 0) {
            cout << "取消丢弃。\n";
            break;
        }

        if (c < 1 || c > (int)bag.size()) {
            cout << "无效选择!\n";
            continue;
        }

        int idx = c - 1;
        cout << "确认丢弃 " << Q_TAG[bag[idx].q] << bag[idx].name 
             << " (价值:" << bag[idx].price << ")? (1=确认, 0=取消): ";

        int confirm;
        cin >> confirm;

        if (confirm == 1) {
            cout << "已丢弃: " << Q_TAG[bag[idx].q] << bag[idx].name << "\n";
            bag.erase(bag.begin() + idx);
        } else {
            cout << "取消丢弃。\n";
        }

        if (bag.empty()) {
            cout << "背包已空。\n";
            break;
        }

        cout << "\n是否继续丢弃? (1=继续, 0=完成): ";
        int cont;
        cin >> cont;
        if (cont != 1) break;
    }
}

// ==================== 商店功能 ====================
void sellItems() {
    int shopLoc = AREA_COUNT - 1;
    if (playerLoc != shopLoc || playerFloor > 0) { cout << "只能在" << AREA_NAMES[shopLoc] << "地面出售!\n"; return; }
    if (bag.empty()) { cout << "背包为空。\n"; return; }

    while (true) {
        cout << "\n--- 背包(" << bag.size() << "/" << bagCap << ") ---\n";
        for (int i = 0; i < (int)bag.size(); i++) {
            int val = bag[i].price * (merchantLic ? 2 : 1);
            cout << "[" << i+1 << "] " << Q_TAG[bag[i].q] << bag[i].name << " 售价:" << val << "\n";
        }
        cout << "[0] 完成出售\n";
        cout << "选择要出售的物品: ";

        int c;
        cin >> c;

        if (c == 0) {
            cout << "出售结束。当前金币: " << money << "\n";
            break;
        }

        if (c < 1 || c > (int)bag.size()) {
            cout << "无效选择!\n";
            continue;
        }

        int idx = c - 1;
        int val = bag[idx].price * (merchantLic ? 2 : 1);
        money += val;
        totalEarned += val;
        cout << "出售成功: " << Q_TAG[bag[idx].q] << bag[idx].name 
             << " 获得" << val << "金币! 当前金币: " << money << "\n";
        bag.erase(bag.begin() + idx);

        if (bag.empty()) {
            cout << "背包已空。\n";
            break;
        }
    }
}

void buyShop() {
    int shopLoc = AREA_COUNT - 1;
    if (playerLoc != shopLoc || playerFloor > 0) { cout << "只能在" << AREA_NAMES[shopLoc] << "地面购买!\n"; return; }
    cout << "\n===== 商店 =====\n";
    cout << "--- 背包扩容 ---\n";
    for (int i = 0; i < 3; i++) {
        string st = bagShop[i].bought ? "[已购]" : "";
        cout << "[B" << i+1 << "] " << bagShop[i].name << " 容量:" << bagShop[i].cap
             << " 价格:" << bagShop[i].cost << " " << st << "\n";
    }
    cout << "--- 技能 ---\n";
    for (int i = 0; i < SKILL_COUNT; i++) {
        string st = skills[i].has ? "[已有]" : "";
        cout << "[S" << i+1 << "] " << skills[i].name << " " << skills[i].cost << "金币 " << st << "\n";
    }
    cout << "选择(B1-B3/S1-S6, 0取消): ";
    string sel; cin >> sel;

    if (sel[0] == 'B' || sel[0] == 'b') {
        int idx = atoi(sel.c_str()+1) - 1;
        if (idx < 0 || idx > 2) return;
        if (bagShop[idx].bought) { cout << "已购买!\n"; return; }
        if (money < bagShop[idx].cost) { cout << "金币不足!\n"; return; }
        money -= bagShop[idx].cost;
        bagShop[idx].bought = true;
        bagCap = bagShop[idx].cap;
        cout << "购买成功! 背包容量->" << bagCap << "\n";
    } else if (sel[0] == 'S' || sel[0] == 's') {
        int idx = atoi(sel.c_str()+1) - 1;
        if (idx < 0 || idx >= SKILL_COUNT) return;
        if (skills[idx].has) { cout << "已拥有!\n"; return; }
        if (money < skills[idx].cost) { cout << "金币不足!\n"; return; }
        money -= skills[idx].cost;
        skills[idx].has = true;
        cout << "购买成功: " << skills[idx].name << "\n";
        if (idx == 4) goldGloveOn = true;
        if (idx == 5) merchantLic = true;
    }
}

void useSkill() {
    cout << "\n--- 可用技能 ---\n";
    vector<int> usable;
    for (int i = 0; i < SKILL_COUNT; i++)
        if (skills[i].has) { usable.push_back(i); cout << "[" << usable.size() << "] " << skills[i].name << "\n"; }
    if (usable.empty()) { cout << "无可用技能。\n"; return; }
    cout << "选择(0取消): ";
    int c; cin >> c;
    if (c < 1 || c > (int)usable.size()) return;

    int idx = usable[c-1];
    switch(idx) {
        case 0:
            cout << "* 未拾取物品:\n";
            for (int i = 0; i < worldItemCount; i++) {
                if (!worldItems[i].taken) {
                    cout << "  " << AREA_NAMES[worldItems[i].loc];
                    if (worldItems[i].floor > 0) cout << " " << worldItems[i].floor << "F" << worldItems[i].room << "室";
                    cout << ": " << Q_TAG[worldItems[i].q] << worldItems[i].name << "\n";
                }
            }
            break;
        case 1:
            if (playerFloor > 0) { cout << "楼内无法瞬移!\n"; break; }
            cout << "目标(0-" << AREA_COUNT-1 << "): "; int d; cin >> d;
            if (d >= 0 && d < AREA_COUNT) { playerLoc = d; cout << "到达: " << AREA_NAMES[d] << "\n"; }
            break;
        case 2: 
            if (bossActive) { bossActive = false; cout << "* 护盾激活! 追逐立即结束!\n"; }
            else { shieldOn = true; cout << "* 护盾储备! 下次被追时自动生效。\n"; }
            break;
        case 3:
            if (bossActive) { bossBufferLeft += 2; cout << "* 怀表生效! 缓冲+2回合!\n"; }
            else { timeWatchOn = true; cout << "* 怀表储备! 下次追逐自动+2缓冲。\n"; }
            break;
        case 4: goldGloveOn = true; cout << "* 手套激活! 下次拾取品质+2级\n"; break;
        case 5: merchantLic = true; cout << "* 执照生效!\n"; break;
    }
}

// ==================== Boss系统(增强) ====================
void triggerBoss() {
    if (bossActive) return;

    int rate = IS_DANGER[playerLoc] ? BOSS_DANGER_RATE : BOSS_NORMAL_RATE;

    if (protectionActive) {
        rate = rate / 2;
    }

    if (currentDifficulty == 1) rate = rate * 3 / 2;
    if (currentDifficulty == 2) rate *= 2;

    if (rand() % 100 < rate) {
        bossActive = true;
        bossBufferLeft = 0;

        if (shieldOn) {
            shieldOn = false;
            bossActive = false;
            cout << "\n!!! 教导主任出现! 隐身护盾自动生效,安全脱身! !!!\n";
            return;
        }
        if (timeWatchOn) {
            timeWatchOn = false;
            bossBufferLeft = 2;
            cout << "\n!!! 教导主任出现! 时间怀表自动生效(+2缓冲)! !!!\n";
        } else {
            cout << "\n!!! 教导主任发现你! 开始追逐! !!!\n";
        }
        if (IS_DANGER[playerLoc]) cout << "(危险区域! 被发现概率更高!)\n";
        if (protectionActive) cout << "(护身符生效中!)\n";
    }
}

void handleBoss() {
    if (!bossActive) return;

    if (bossBufferLeft > 0) {
        bossBufferLeft--;
        cout << "! 怀表缓冲中... 主任暂时迷失方向 (剩余" << bossBufferLeft << "回合)\n";
        return;
    }

    int escapeChance = BOSS_ESCAPE_CHANCE;
    if (currentDifficulty == 1) escapeChance = 25;
    if (currentDifficulty == 2) escapeChance = 20;

    if (trainBuff == 1) {
        escapeChance += 30;
        trainBuff = 0;
        cout << "* 体能训练生效! 逃脱率提升!\n";
    }

    if (rand() % 100 < escapeChance) {
        bossActive = false;
        cout << "* 你趁主任不注意溜走了! 追逐结束!\n";
        return;
    }

    if (currentDifficulty == 2) {
        int catchChance = 15;
        if (rand() % 100 < catchChance) {
            if (immunityActive) {
                immunityActive = false;
                bossActive = false;
                cout << "\n!!! 教导主任抓住了你! 但免死金牌生效! 你成功逃脱! !!!\n";
                return;
            }

            cout << "\n!!! 教导主任抓住了你! 游戏结束! !!!\n";
            cout << "你在噩梦难度中被淘汰了...\n";
            cout << "本局获得金币: " << money << "\n";

            totalEarned -= money;
            if (totalEarned < 0) totalEarned = 0;

            cout << "惩罚: 本局金币作废,累计赚取变为: " << totalEarned << "\n";
            cout << "\n按回车返回难度选择...";
            cin.ignore(); cin.get();

            gameEliminated = true;
            gameRunning = false;
            return;
        }
    }

    int dropChance = 15;
    if (currentDifficulty == 1) dropChance = 20;
    if (currentDifficulty == 2) dropChance = 25;

    if (antiDropActive) {
        cout << "* 防掉链生效! 物品不会掉落!\n";
        cout << "! 主任仍在追击! (每回合" << escapeChance << "%概率逃脱)\n";
        return;
    }

    if (!bag.empty() && rand() % 100 < dropChance) {
        int dropIdx = rand() % bag.size();
        Item lost = bag[dropIdx];
        bag.erase(bag.begin() + dropIdx);
        cout << "!!! 慌乱逃跑中! 你不慎遗落了 " << Q_TAG[lost.q] << lost.name << " !!!\n";
    } else {
        cout << "! 主任仍在追击! (每回合" << escapeChance << "%概率逃脱)\n";
    }
}

void showHelp() {
    cout << "\n===== 操作说明(v15.0) =====\n";
    cout << "段位: " << RANK_NAMES[currentRank] << " | 目标: " << WIN_MONEY << "元\n";
    cout << "地图大小: " << AREA_COUNT << "个区域 | 物品: " << TOTAL_ITEMS << "个\n";
    cout << "累计赚取: " << totalEarned << "金币\n";

    string diffName = currentDifficulty == 0 ? "普通" : 
                      currentDifficulty == 1 ? "困难" : "噩梦";
    cout << "难度: " << diffName << "\n";

    if (currentDifficulty == 0) {
        cout << "概率: 白70% 绿20% 金6% 紫2.5% 红1% 彩0.5%\n";
    } else if (currentDifficulty == 1) {
        cout << "概率: 白60% 绿22% 金9% 紫5% 红2.5% 彩1% 炫0.4% 神0.1%\n";
    } else {
        cout << "概率: 白55% 绿20% 金10% 紫7% 红4% 彩2.5% 炫1.2% 神0.3%\n";
    }

    if (currentDifficulty == 2) {
        cout << "!!! 噩梦模式: 被Boss追到有15%概率直接淘汰 !!!\n";
    }

    cout << "1~N:移动 F:上下楼 R:进出房 B:返回/商店\n";
    cout << "P:搜寻 S:出售 D:丢弃 U:技能 E:建筑功能 M:地图 H:帮助\n";
    cout << "==========================\n";
}

void clearScreen() {
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_SCREEN_BUFFER_INFO csbi;
    DWORD cellCount;
    COORD homeCoords = {0, 0};
    DWORD count;

    GetConsoleScreenBufferInfo(hConsole, &csbi);
    cellCount = csbi.dwSize.X * csbi.dwSize.Y;
    FillConsoleOutputCharacter(hConsole, ' ', cellCount, homeCoords, &count);
    FillConsoleOutputAttribute(hConsole, csbi.wAttributes, cellCount, homeCoords, &count);
    SetConsoleCursorPosition(hConsole, homeCoords);
}

// ==================== 难度选择 ====================
void selectDifficulty() {
    clearScreen();
    cout << "========================================\n";
    cout << "   选择难度 - 当前段位: " << RANK_NAMES[currentRank] << "\n";
    cout << "   累计金币: " << totalEarned << "\n";
    cout << "========================================\n";

    cout << "[1] 普通难度 - 撤离需要" << DIFFICULTY_WIN_MONEY[0][currentRank] << "元\n";
    cout << "    地图:6-8区域 | Boss:普通\n";

    if (canPlayDifficulty(1)) {
        cout << "[2] 困难难度 - 撤离需要" << DIFFICULTY_WIN_MONEY[1][currentRank] << "元\n";
        cout << "    地图:8-10区域 | Boss:较强 | 炫光品质\n";
    } else {
        cout << "[2] 困难难度 - 需要白银段位(累计赚取3万)\n";
    }

    if (canPlayDifficulty(2)) {
        cout << "[3] 噩梦难度 - 撤离需要" << DIFFICULTY_WIN_MONEY[2][currentRank] << "元\n";
        cout << "    地图:10-12区域 | Boss:极强 | 超神品质 | 可能被淘汰\n";
    } else {
        cout << "[3] 噩梦难度 - 需要黄金段位(累计赚取20万)\n";
    }

    cout << "[4] 赛前道具商店\n";
    cout << "[5] 查看仓库 (" << warehouse.size() << "件藏品)\n";
    cout << "[0] 退出游戏\n";
    cout << "选择: ";

    int choice;
    cin >> choice;

    switch(choice) {
        case 0:
            gameRunning = false;
            break;
        case 1:
            currentDifficulty = 0;
            buyPreGameItems();
            break;
        case 2:
            if (canPlayDifficulty(1)) {
                currentDifficulty = 1;
                buyPreGameItems();
            } else {
                cout << "\n未解锁困难难度! 需要白银段位\n";
                Sleep(2000);
                selectDifficulty();
            }
            break;
        case 3:
            if (canPlayDifficulty(2)) {
                currentDifficulty = 2;
                buyPreGameItems();
            } else {
                cout << "\n未解锁噩梦难度! 需要黄金段位\n";
                Sleep(2000);
                selectDifficulty();
            }
            break;
        case 4:
            buyPreGameItems();
            selectDifficulty();
            break;
        case 5:
            showWarehouse();
            selectDifficulty();
            break;
        default:
            selectDifficulty();
            break;
    }
}

// ==================== 主循环 ====================
signed main() {
    srand((unsigned)time(NULL));
    SetConsoleOutputCP(936);
    SetConsoleCP(936);

    selectDifficulty();
    if (!gameRunning) return 0;

    initGame();

    string cmd;
    showHelp(); cout << "\n按回车继续..."; cin.ignore(); cin.get();

    while (gameRunning) {
        clearScreen();
        showMap();
        showAdjacent();

        cout << "\n[" << getLocDesc() << " T" << turnCount+1
             << " $" << money << "/" << WIN_MONEY
             << " Bag:" << bag.size() << "/" << bagCap
             << " 累计:" << totalEarned;
        if (bossActive) cout << " !!BOSS!!";
        cout << "] >";
        cin >> cmd;

        if (cmd == "Q" || cmd == "q") { gameRunning = false; break; }
        if (cmd == "H" || cmd == "h") { showHelp(); cout << "\n按回车继续..."; cin.ignore(); cin.get(); continue; }
        if (cmd == "M" || cmd == "m") { continue; }

        if (cmd == "P" || cmd == "p") pickItem();
        else if (cmd == "F" || cmd == "f") moveFloor();
        else if (cmd == "R" || cmd == "r") moveRoom();
        else if (cmd == "B" || cmd == "b") {
            if (playerFloor > 0) backToGround();
            else buyShop();
        }
        else if (cmd == "S" || cmd == "s") sellItems();
        else if (cmd == "D" || cmd == "d") dropItem();
        else if (cmd == "U" || cmd == "u") useSkill();
        else if (cmd == "E" || cmd == "e") useBuildingSpecial();
        else {
            int mv = atoi(cmd.c_str()) - 1;
            if (playerFloor > 0) { cout << "楼内请先B返回地面!\n"; Sleep(2000); continue; }
            if (mv >= 0 && mv < ADJ_CNT[playerLoc]) {
                playerLoc = ADJ[playerLoc][mv];
            } else if (atoi(cmd.c_str()) > 0) { cout << "无法前往!\n"; Sleep(2000); continue; }
            else { cout << "未知指令! H查看帮助\n"; Sleep(2000); continue; }
        }

        turnCount++;
        triggerBoss();
        handleBoss();

        if (gameEliminated) {
            selectDifficulty();
            if (gameRunning) {
                resetGameState();
                clearScreen();
                cout << "重新开始! 段位: " << RANK_NAMES[currentRank] 
                     << " | 难度: ";
                string diffName = currentDifficulty == 0 ? "普通" : 
                                  currentDifficulty == 1 ? "困难" : "噩梦";
                cout << diffName << "\n\n";
                showHelp();
                cout << "\n按回车继续..."; cin.ignore(); cin.get();
            }
            continue;
        }

        if (checkWin()) {
            selectDifficulty();
            if (gameRunning) {
                resetGameState();
                clearScreen();
                cout << "开始新游戏! 段位: " << RANK_NAMES[currentRank] 
                     << " | 难度: ";
                string diffName = currentDifficulty == 0 ? "普通" : 
                                  currentDifficulty == 1 ? "困难" : "噩梦";
                cout << diffName << "\n\n";
                showHelp();
                cout << "\n按回车继续..."; cin.ignore(); cin.get();
            }
        }

        Sleep(2000);
    }

    clearScreen();
    cout << "感谢游玩! 最终金币: " << money << "\n";
    cout << "累计通关: " << totalWins << "次 | 累计赚取: " << totalEarned << "金币\n";
    cout << "仓库藏品: " << warehouse.size() << "件\n";
    cout << "最终段位: " << RANK_NAMES[currentRank] << "\n";
    return 0;
}