#include<bits/stdc++.h>
#include<windows.h>
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>
using namespace std;
typedef BOOL (WINAPI *PROCSETCONSOLEFONT)(HANDLE, DWORD);
PROCSETCONSOLEFONT SetConsoleFont;
/*
普通图(普通、封锁、强化封锁):
农场-Garden
山谷-Desert
北部山区-Ocean
军港-Ant Hell
矿区-Jungle

高级图(封锁,强化封锁):
前线要塞-Sewer
电视台-Hel
*/
void Color(int a){//白 绿 黄 蓝 紫 红 青 粉 淡绿 
    if(a==0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
    
    if(a==1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_GREEN); 
    
    if(a==2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_GREEN);
    
    if(a==3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_BLUE); 
    
    if(a==4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED|FOREGROUND_BLUE);
    
    if(a==5) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_RED);
    
    if(a==6) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN|FOREGROUND_BLUE); 
    
    if(a==7) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_RED|FOREGROUND_BLUE); 
    
    if(a==8) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY|FOREGROUND_GREEN); 
}
string level[9]={"空","Common","Unusual","Rare","Epic","Legendary","Mythic","Ultra","Super"};
double mer[9]={0,7000,4000,1500,500,100,30,1,0};

int prize[9]={0,10,100,1000,5000,25000,100000,750000,1500000};//卡牌价格 
int cost[9]={0,0,7,11,19,34,65,128,253};//神使制作的成本 

int m_s[8]={0,10,14,16,8,20,10,8};//地图大小 

int baolv[8][9]={//概率计算以万分之一为基础单位,此为普通
	{0,0,0,0,0,0,0,0,0},
	{0,10000,5000,1500,100,1,0,0,0},
	{0,10000,4500,1750,150,2,0,0,0},
	{0,10000,4750,1800,175,2,0,0,0},
	{0,10000,5500,2000,200,5,1,0,0},
	{0,10000,5000,2000,175,3,1,0,0},
	{0,0,10000,2500,250,6,3,1,0},
	{0,0,10000,3000,500,8,4,1,0}
};
int f_c(int ply,double mul){//捡到卡牌等级,危险区*1.2,封锁*1.5,强封*1.7 
	for(int i=8;i>=1;i--){
		if((double)(rand()%10000+1) <= (double)baolv[ply][i]*mul){
			return i;
		}
	}
}

int e_mob[8][9]={//生成概率计算以万分之一为基础单位,此为普通
	{0,0,0,0,0,0,0,0,0},
	{0,10000,5000,1500,400,1,0,0,0},
	{0,10000,4500,1750,450,2,0,0,0},
	{0,10000,4750,1800,475,3,1,0,0},
	{0,10000,5500,2000,500,10,3,1,0},
	{0,10000,5000,2000,475,5,2,1,0},
	{0,0,10000,5000,600,400,70,7,1},
	{0,0,10000,5500,1000,500,100,10,2}
};
int ec_m(int ply,long double mul){//怪物等级,危险区*1.2,封锁*1.4,强封*1.7 
	for(int i=8;i>=1;i--){
		if((rand()%10000+1)*1.0 <= e_mob[ply][i]*mul){
			return i;
		}
	}
}

int e_human_lv[4][8]={
	{0,0,0,0,0,0,0,0},
	{0,1,7,7,13,10,0,0},
	{0,15,20,25,35,30,50,60},
	{0,75,90,100,200,150,400,450}
};
int e_human_card[8][9]={//卡牌携带计算以万分之一为基础单位,此为普通
	{0,0,0,0,0,0,0,0,0},
	{0,10000,4000,700,200,1,1,0,0},
	{0,10000,6000,1000,300,2,2,1,0},
	{0,10000,6500,1500,400,3,2,1,0},
	{0,10000,7500,3000,750,10,4,3,1},
	{0,10000,7000,2000,600,5,2,2,1},
	{0,0,0,10000,5000,1500,450,40,5},
	{0,0,0,10000,6000,2000,500,50,7}
};
int ec_h(int ply,long double mul){//人机玩家携带卡牌的的等级,危险区*1.2,封锁*1.63,强封*1.79 
	if(mul==1.5 || mul==1.8){
		mul/=1.5;
		mul*=1.63;
	}
	else if(mul==1.7 || mul==2.04){
		mul/=1.7;
		mul*=1.79;
	}
	for(int i=8;i>=1;i--){
		if((rand()%10000+1)*1.0 <= e_human_card[ply][i]*mul){
			return i;
		}
	}
}

POINT Windowpos(){
    POINT pt;
    GetCursorPos(&pt);
    HWND h=GetForegroundWindow();
    ScreenToClient(h,&pt);
    pt.x/=8;pt.y/=16;
    return pt;
}

void SetPos(int x,int y){
    COORD pos;
    pos.X=x,pos.Y=y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}

int wh[9],bp[9],wp[11],kl,lv=1,Exp,money=5000;
bool flag;

void game(int p_m,int dgr);
void fight_m(int elv);
void fight_p(int elv,int at,int x,int y);
void liaison(int who);

void Read(){
	double qwq=0;
	int iakioi;
    ifstream in("florr突围存档.txt");
    in>>lv>>kl>>Exp;
    if(!lv){
    	in.close();
    	return ;
    }
    qwq+=lv*0.37+kl*0.73+Exp*1.14;
    for(int i=1;i<=8;i++){
    	in>>wh[i];
    	qwq+=wh[i]*4.29;
    }
    for(int i=1;i<=10;i++){
    	in>>wp[i];
    	qwq+=wp[i]*8.12;
    }
    in>>money;
    qwq+=money*7.62;
    in>>iakioi;
    in.close();
    if((int)qwq!=iakioi){
    	cout<<"因为版本问题或擅自修改代码,存档无法正常读取。"<<endl;
    	Sleep(500);
    	cout<<"没事的,我会尽力保证这份存档还可以继续使用,但是我希望你自己没有改存档。"<<endl;
		Sleep(500); 
		cout<<"这边如果是版本问题的话,个人建议您重开一个档,不然可能会发生运行错误"<<endl;
		Sleep(1000); 
    }
}
void Save(){
	double qwq=0;
    ofstream out("florr突围存档.txt");
    out<<lv<<' '<<kl<<' '<<Exp<<endl;
    qwq+=lv*0.37+kl*0.73+Exp*1.14;
    for(int i=1;i<=8;i++){
    	out<<wh[i]<<' ';
    	qwq+=wh[i]*4.29;
    }
    out<<endl;
    for(int i=1;i<=10;i++){
    	out<<wp[i]<<' ';
    	qwq+=wp[i]*8.12;
    }
    out<<endl<<money;
    qwq+=money*7.62;
    out<<endl<<(int)qwq;
    out.close();
}

char xxx;
int main(){
	CONSOLE_CURSOR_INFO cursor_info={1,0}; 
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE),&cursor_info);
	srand(time(NULL));
	int cnt=0,x,y,hcsl;
	kl=5;
	for(int i=1;i<=5;i++){
		wp[i]=1;
		wh[1]++;
	}
	cout<<"是否读档?y/n"<<endl;
	cin>>xxx;
	if(xxx=='y'){
		Read(); 
	}
	Sleep(500);
	while(1){
		system("cls");
		cout<<"1.仓库"<<endl<<"2.合成"<<endl<<"3.联络人"<<endl<<"4.进入florr"<<endl;
		cnt=0;
		while(cnt<1 || cnt>4){
			cin>>cnt;
		}
		if(cnt==1){
			while(1){
				system("cls");
				cout<<"你的等级:"<<lv<<' '<<"你所拥有的Coin数量:"<<money<<endl;
				Sleep(50);
				cout<<"你目前携带的卡牌配置为:"<<endl;
				for(int i=1;i<=kl;i++){
					cout<<i<<": ";
					Color(wp[i]);
					cout<<level[wp[i]];
					Color(0);
					cout<<endl;
				}
				Sleep(100);
				cout<<"你现在仓库内所有的卡牌:"<<endl;
				for(int i=1;i<=8;i++){
					cout<<i<<".";
					Color(i);
					cout<<level[i];
					Color(0);
					cout<<": "<<wh[i]<<"张"<<endl;
				}
				Sleep(100);
				cout<<"请输入你要替换的卡牌(两个数字),输入0退出"<<endl;
				cin>>x;
				if(x==0){
					break;
				}
				cin>>y;
				if(x<1 || x>kl || y<1 || y>8 || wh[y]==0){
					cout<<"替换失败";
					Sleep(500);
					continue;
				}
				wh[y]--;
				wh[wp[x]]++;
				wp[x]=y;
				cout<<"替换成功!";
				Sleep(500);
			}
			Save();
		}
		else if(cnt==2){
			while(1){
				system("cls");
				cout<<"你现在仓库内所有的卡牌:"<<endl;
				for(int i=1;i<=8;i++){
					cout<<i<<".";
					Color(i);
					cout<<level[i];
					Color(0);
					cout<<": "<<wh[i]<<"张"<<endl;
				}
				cout<<"请输入你要合成的卡牌,输入0退出"<<endl;
				x=-1;
				while(x<0 || x>7){
					cin>>x;
				}
				if(x==0){
					break;
				}
				if(wh[x]<5){
					cout<<"卡牌不足";
				}
				else{
					hcsl=0;
					cout<<"1.合成一次 2.一键合成"<<endl;
					cnt=0;
					while(cnt<1 || cnt>2){
						cin>>cnt;
					}
					if(cnt==1){
						wh[x]-=5;
						if(rand()%20000+2>=20000-mer[x]*2){
							hcsl++;
						}	
						else{
							wh[x]+=1+rand()%4;
						}
					}
					else{
						while(wh[x]>=5){
							wh[x]-=5;
							if(rand()%20000+2>=20000-mer[x]*2){
								hcsl++;
							}
							else{
								cnt=1+rand()%4;
								wh[x]+=cnt;
							}
						}
					}
					cout<<"你获得了"<<hcsl<<"张";
					Color(x+1);
					cout<<level[x+1];
					Color(0);
					cout<<"等级的卡牌!";
					wh[x+1]+=hcsl;
					Sleep(500);
					Save();
				}
			}
		}
		else if(cnt==3){
			while(1){
				system("cls");
				cout<<"1.Trader"<<endl<<"2.Oracle"<<endl<<"0.退出"<<endl;
				cnt=-1;
				while(cnt<0 || cnt>2){
					cin>>cnt;
				}
				if(cnt==0){
					break;
				}
				liaison(cnt);
			}
		}
		else if(cnt==4){
			system("cls");
			cout<<"请选择要进入的模式,输入0退出"<<endl<<"1.战术行动"<<endl<<"2.封锁区(入场费1500Coin)"<<endl<<"3.强化封锁(入场费5000Coin)"<<endl;
			y=-1;
			while(y<0 || y>3){
				cin>>y;
			}
			if(y==0){
				continue;
			}
			else{
				if(y==1){
					cout<<"请选择要进入的地图,输入0退出"<<endl<<"1.Garden"<<endl<<"2.Desert"<<endl<<"3.Ocean"<<endl<<"4.Ant Hell"<<endl<<"5.Jungle"<<endl;
					x=-1;
					while(x<0 || x>5){
						cin>>x;
					}
					if(x==0){
						continue;
					}
				}
				else{
					if((y==2 && money<1500)||(y==3 && money<5000)){
						cout<<"入场费不足,无法进入!"<<endl;
						Sleep(1000);
					}
					cout<<"请选择要进入的地图,输入0退出"<<endl<<"1.Garden"<<endl<<"2.Desert"<<endl<<"3.Ocean"<<endl<<"4.Ant Hell"<<endl<<"5.Jungle"<<endl<<"6.Sewer"<<endl<<"7.Hel"<<endl;
					x=-1;
					while(x<0 || x>7){
						cin>>x;
					}
					if(x==0){
						continue;
					}
				}
				if(y==2){
					money-=1500;
				}
				if(y==3){
					money-=5000;
				}
				game(x,y);
				Save();
			}
		}
	}
	return 0;
}
void fight_m(int elv){
	flag=1;
	int hp=175+lv*25,ehp=pow(3,elv-1)*(50-10+rand()%21),cnt,at=1,dam=0;
	while(hp>0 && ehp>0){
		system("cls");
		cout<<"你的血量:"<<hp<<"怪物血量:"<<ehp;
		Sleep(500);
		if(at){
			cout<<endl<<"1.攻击 2.迂回偷袭(概率失败) 3.逃跑"<<endl;
			cnt=0;
			while(cnt<1 || cnt>3)
				cin>>cnt;
			if(cnt==1){
				if(rand()%1000<=950){
					for(int i=1;i<=kl;i++){
						dam+=pow(3,wp[i]-1)*(5+rand()%11);
					}
					cout<<"你打出了"<<dam<<"点伤害!";
					ehp-=dam;
				}
				else{
					cout<<"怪物躲过了你的攻击!";
				}
			}
			else if(cnt==2){
				if(rand()%5000<=1500){
					for(int i=1;i<=kl;i++){
						dam+=pow(3,wp[i]-1)*(15+rand()%26);
					}
					cout<<"偷袭成功,对怪物造成了"<<dam<<"点伤害!";
					ehp-=dam;
				}
				else{
					dam=pow(2,elv-1)*(1+rand()%10);
					cout<<"偷袭失败,怪物对你造成了"<<dam<<"点伤害!";
					hp-=dam; 
				}
			}
			else{ 
				if(rand()%1000<=elv*125){
					cout<<"你逃跑了...";
					return ;
				}
				else{
					cout<<"怪物紧追不舍...";
				}
			}
		}
		else{
			if(rand()%1000<=850){
				dam=pow(3,elv-1)*(5+rand()%21);
				cout<<endl<<"怪物对你造成了"<<dam<<"点伤害!";
				hp-=dam;
			}
			else{
				cout<<endl<<"你躲过了怪物的攻击!";
			}
		}
		at=!at;
		Sleep(1000);
	}
	if(hp<1){
		Color(5);
		cout<<endl<<"你被怪物击败了!";
		Sleep(1000);
		Color(0);
		cout<<endl<<"你身上携带的所有卡牌全部丢失";
		for(int i=1;i<=kl;i++){
			wp[i]=0;
		}
		for(int i=1;i<=8;i++){
			bp[i]=0;
		}
		Sleep(1000);
		flag=0;
	}
	else{
		cnt=pow(2,elv)*(rand()%5+1);
		Color(2);
		cout<<endl<<"你击败了怪物!";
		Sleep(500);
		cout<<endl<<"你获得了"<<cnt<<"点经验值!"<<endl;
		Sleep(500);
		Exp+=cnt;
		while(Exp>=(5+5*lv)){
			cout<<"你升级了!"<<endl;
			Exp-=(5+5*lv);
			lv++;
			Sleep(250);
		}
		Color(0);
		cout<<endl<<"你获得了以下战利品:";
		cnt=(rand()%1000)%2+1;
		Color(elv);
		cout<<endl<<level[elv];
		Color(0);
		cout<<"卡牌"<<cnt<<"张";
		bp[elv]+=cnt;
		cnt=pow(2,elv);
		if(elv!=8 && rand()%(cnt*2)==cnt){
			Sleep(500);
			Color(elv+1);
			cout<<endl<<level[elv+1];
			Color(0);
			cout<<"卡牌1张";
			bp[elv+1]++;
		}
		Sleep(1000);
	}
}

int wp_e[9];

void fight_p(int elv,int at,int x,int y){
	flag=1;
	int hp=175+lv*25,ehp=175+elv*25,cnt,dam=0;
	for(int i=1;i<=kl;i++){
		wp_e[i]=ec_h(x,y);
	}
	while(hp>0 && ehp>0){
		system("cls");
		cout<<"你的血量:"<<hp<<"对方血量:"<<ehp<<endl<<"对方卡牌配置:"<<endl;;
		for(int i=1;i<=kl;i++){
			Color(wp_e[i]);
			cout<<level[wp_e[i]]<<endl;
		}
		Color(0);
		Sleep(500);
		if(at){
			cout<<endl<<"1.攻击 2.迂回偷袭(概率失败) 3.逃跑"<<endl;
			cnt=0;
			while(cnt<1 || cnt>3)
				cin>>cnt;
			if(cnt==1){
				if(rand()%2000<=1700-elv){
					cnt=rand()%kl+1;
					for(int i=1;i<=cnt;i++){
						dam+=pow(3,wp[i]-1)*(5+rand()%11);
					}
					cout<<"你打出了"<<dam<<"点伤害!";
					ehp-=dam;
				}
				else{
					cout<<"敌人躲过了你的攻击!";
				}
			}
			else if(cnt==2){
				if(rand()%10000<=3000){
					for(int i=1;i<=kl;i++){
						dam+=pow(3,wp[i]-1)*(15+rand()%26);
					}
					cout<<"偷袭成功,对敌人造成了"<<dam<<"点伤害!";
					ehp-=dam;
				}
				else{
					cout<<"敌人躲过了你的偷袭!";
				}
			}
			else{ 
				cout<<"你逃跑了...";
				return ;
			}
		}
		
		else{
			if(hp>=ehp*3){
				if(rand()%5000<=1500){
					for(int i=1;i<=kl;i++){
						dam+=pow(3,wp_e[i]-1)*(15+rand()%26);
					}
					cout<<"敌人偷袭了你,造成了"<<dam<<"点伤害!";
					hp-=dam;
				}
				else{
					cout<<"你躲过了敌人的偷袭!";
				}
			}
			else{
				if(rand()%2000<=1700-lv){
					cnt=rand()%kl+1;
					for(int i=1;i<=cnt;i++){
						dam+=pow(3,wp_e[i]-1)*(5+rand()%11);
					}
					cout<<endl<<"敌人对你造成了"<<dam<<"点伤害!";
					hp-=dam;
				}
				else{
					cout<<endl<<"你躲过了敌人的攻击!";
				}
			}
		}
		at=!at;
		Sleep(1000);
	}
	if(hp<1){
		Color(5);
		cout<<endl<<"你被敌人击败了!";
		Sleep(1000);
		Color(0);
		cout<<endl<<"你身上携带的所有卡牌全部丢失";
		for(int i=1;i<=kl;i++){
			wp[i]=0;
		}
		for(int i=1;i<=8;i++){
			bp[i]=0;
		}
		Sleep(1000);
		flag=0;
	}
	else{
		cnt=elv*5+5;
		Color(2);
		cout<<endl<<"你击败了敌人!";
		Sleep(500);
		cout<<endl<<"你获得了"<<cnt<<"点经验值!"<<endl;
		Sleep(500);
		Exp+=cnt;
		while(Exp>=(5+5*lv)){
			cout<<"你升级了!"<<endl;
			Exp-=(5+5*lv);
			lv++;
			Sleep(250);
		}
		Color(0);
		cout<<"你获得了如下战利品:";
		for(int i=1;i<=kl;i++){
			Color(wp_e[i]);
			cout<<endl<<level[wp_e[i]];
			Color(0);
			cout<<"卡牌一张;";
			bp[wp_e[i]]++;
		}
		cnt=rand()%kl+1;
		Color(wp_e[cnt]);
		cout<<endl<<level[wp_e[cnt]];
		Color(0);
		cout<<"卡牌一张;";
		bp[wp_e[cnt]]++;
		
		Color(0);
		Sleep(1000);
		flag=1;
	}
}

void game(int p_m,int dgr){
	int hp=90+10*lv,cnt,rage=rand()%5+m_s[p_m]-2,card,clocknum,x,y;
	double mul;
	if(dgr==1){
		mul=1;
	}
	else if(dgr==2){
		mul=1.4;
	}
	else{
		mul=1.7;
	}
	while(hp>0){
		system("cls");
		cout<<"你离撤离点还有"<<rage<<"单位距离"<<endl;
		if(rage==m_s[p_m]/2){
			Color(5);
			cout<<"你现在处于危险区域!敌人强度和爆率均有提升!"<<endl;
			Color(0);
		}
		Sleep(250);
		cout<<"1.在附近闲逛 2.向撤离点移动 3.整理背包"<<endl;
		cnt=0;
		while(cnt<1 || cnt>3)
			cin>>cnt;
		if(cnt==1){
			cout<<"闲逛中...";
			Sleep(500);
			if(rand()%1000<=600){
				card=f_c(p_m,mul);
				if(rage==m_s[p_m]/2){
					card=f_c(p_m,mul*1.2);
				}
				cout<<endl<<"你在闲逛途中捡到了一张";
				Color(card);
				cout<<level[card];
				Color(0);
				cout<<"等级的卡牌!"; 
				bp[card]++;
			} 
			else if(rand()%1000<=700){
				cnt=ec_m(p_m,mul);;
				if(rage==m_s[p_m]/2){
					cnt+=ec_m(p_m,mul*1.2);
				}
				cout<<endl<<"你遭遇了一只";
				Color(cnt);
				cout<<level[cnt];
				Color(0);
				cout<<"等级的怪物!";
				Sleep(1000);
				fight_m(cnt); 
				if(!flag){
					return ;
				}
			}
			else if(rand()%1000<=500){
				cnt=e_human_lv[dgr][p_m]-2+rand()%5;
				if(cnt<1) cnt=1;
				cout<<endl<<"你遭遇了一名"<<cnt<<"级的敌人!";
				Sleep(1000);
				fight_p(cnt,rand()%2,p_m,mul); 
				if(!flag){
					return ;
				}
			}
			else{
				cout<<"...但是无事发生";
				Sleep(1000); 
			}
		}
		else if(cnt==2){
			cout<<"正在移动中..."<<endl;
			Sleep(500);
			if(rand()%1000<=250 && rage!=1){
				card=f_c(p_m,mul);
				cout<<endl<<"你在路上捡到了一张";
				Color(card);
				cout<<level[card];
				Color(0);
				cout<<"等级的卡牌!"; 
				bp[card]++;
			} 
			
			if(rand()%1000<=600 && rage!=1){
				cnt=ec_m(p_m,mul);
				cout<<endl<<"你遭遇了一只";
				Color(cnt);
				cout<<level[cnt];
				Color(0);
				cout<<"等级的怪物!";
				Sleep(1000);
				fight_m(cnt); 
				if(!flag){
					return ;
				}
			}
			else if(rand()%1000<=300 && rage!=1){
				cnt=e_human_lv[dgr][p_m]-2+rand()%5;
				if(cnt<1) cnt=1;
				if(rage==5){
					cnt+=rand()%3+1;
				}
				cout<<endl<<"你遭遇了一名"<<cnt<<"级的敌人!";
				Sleep(1000);
				fight_p(cnt,1,p_m,mul); 
				if(!flag){
					return ;
				}
			}
			rage--;
			if(rage==0){
				cout<<"你已经抵达撤离点,正在等待传送..."<<endl;
				Sleep(1000);
				for(int i=10;i>=1;i--){
					system("cls");
					cout<<"撤离倒计时:"<<i;
					clocknum=clock();
					while(clock()-clocknum<1000);
					if(rand()%1000<=(11-i)*20){
						cnt=ec_m(p_m,mul);
						cout<<endl<<"你遭遇了一只";
						Color(cnt);
						cout<<level[cnt];
						Color(0);
						cout<<"等级的怪物!";
						Sleep(1000);
						fight_m(cnt); 
						if(!flag){
							return ;
						}
					}
					else if(rand()%1000<=(11-i)*10){
						cnt=e_human_lv[dgr][p_m]-2+rand()%5;
						if(cnt<1) cnt=1;
						cout<<endl<<"你遭遇了一名"<<cnt<<"级的敌人!";
						Sleep(1000);
						fight_p(cnt,rand()%2,p_m,mul); 
						if(!flag){
							return ;
						}
					}
				}
				system("cls");
				cout<<"撤离成功!!"<<endl;
				Sleep(1000);
				cout<<"你带出了如下物资:"<<endl;
				for(int i=1;i<=8;i++){
					if(bp[i]!=0){
						Sleep(1000);
						Color(i);
						cout<<endl<<level[i];
						Color(0);
						cout<<"卡牌"<<bp[i]<<"张;";
						wh[i]+=bp[i];
						bp[i]=0;
					}
				}
				Sleep(1000);
				return ; 
			}
		}
		else{
			while(1){
				system("cls");
				cout<<"你的等级:"<<lv<<"   距离下次升级还需要:"<<5+(5*lv)-Exp<<endl;
				Sleep(50);
				cout<<"你目前的卡牌配置为:"<<endl;
				for(int i=1;i<=kl;i++){
					cout<<i<<": ";
					Color(wp[i]);
					cout<<level[wp[i]];
					Color(0);
					cout<<endl;
				}
				Sleep(100);
				cout<<"你现在背包内所有的卡牌:"<<endl;
				for(int i=1;i<=8;i++){
					if(bp[i]){
						cout<<i<<".";
						Color(i);
						cout<<level[i];
						Color(0);
						cout<<": "<<bp[i]<<"张"<<endl;
					}
				}
				Sleep(100);
				cout<<"请输入你要替换的卡牌(两个数字),输入0退出"<<endl;
				cin>>x;
				if(x==0){
					break;
				}
				cin>>y;
				if(x<1 || x>kl || y<1 || y>8 || bp[y]==0){
					cout<<"替换失败";
					Sleep(500);
					continue;
				}
				bp[y]--;
				bp[wp[x]]++;
				wp[x]=y;
				cout<<"替换成功!";
				Sleep(500);
			}
		}
		Sleep(500);
	}
}

void liaison(int who){
	int cnt,x;
	char xxx;
	cout<<"正在连线中...";
	Sleep(500);
	
	if(who==1){
		while(1){
			system("cls");
			cout<<"嗨!我是Trader,缺卡还是缺钱,我都能解决!"<<endl;
			cout<<"请问您有什么需要?"<<endl<<"1.购买卡牌"<<endl<<"2.售卖卡牌"<<endl<<"0.离开"<<endl;
			cnt=-1;
			while(cnt<0 || cnt>2){
				cin>>cnt;
			}
			if(cnt==0){
				cout<<"好吧,那记得常来看看啊!说不定哪天你就需要什么了。";
				Sleep(1000);
				break ;
			}
			if(cnt==1){
				while(1){
					system("cls");
					cout<<"那你可找对人了!至于价格嘛,嘿嘿,那就要看我随机翻出来的那张卡有多贵啦。"<<endl;
					cout<<"你所拥有的Coin数量:"<<money<<endl; 
					for(int i=1;i<=8;i++){
						cout<<i<<".购买一张";
						Color(i);
						cout<<level[i];
						Color(0);
						cout<<"卡牌"<<endl;
					}
					cout<<"0.退出"<<endl;
					cnt=-1;
					while(cnt<0 || cnt>8){
						cin>>cnt;
					}
					if(cnt==0){
						cout<<"如果又需要卡了,随时来啊!";
						Sleep(1000); 
						break;
					}
					x=(int)((double)prize[cnt]*(rand()%41+80)/100.0);
					cout<<"这张";
					Color(cnt);
					cout<<level[cnt];
					Color(0);
					cout<<"卡牌的价值是"<<x<<"个Coin,要不要?(y/n)"<<endl;
					cin>>xxx;
					if(xxx=='y'){
						if(money<x){
							cout<<"额,抱歉啦哥们儿,你买不起。";
						}
						else{
							cout<<"好嘞!您拿好啦。";
							money-=x;
							wh[cnt]++; 
							Save();
						}
					}
					else{
						cout<<"好吧,你说不定要再考虑一下。";
					}
					Sleep(1000);
				}
			}
			else if(cnt==2){
				while(1){
					system("cls");
					cout<<"想要卖卡?来吧,品质决定我出的钱。"<<endl;
					cout<<"你所拥有的Coin数量:"<<money<<endl; 
					for(int i=1;i<=8;i++){
						cout<<i<<".出售库存为"<<wh[i]<<"张的";
						Color(i);
						cout<<level[i];
						Color(0);
						cout<<"卡牌"<<endl;
					}
					cout<<"0.退出"<<endl;
					cnt=-1;
					while(cnt<0 || cnt>8){
						cin>>cnt;
					}
					if(cnt==0){
						cout<<"好吧,下次有什么用不着的好货记得来找我哟!";
						Sleep(1000); 
						break;
					}
					if(wh[cnt]==0){
						cout<<"抱歉啦,你似乎没有这种卡牌";
						Sleep(750);
						continue; 
					}
					cout<<"1.出售一张(大概获得:"<<(int)((double)prize[cnt]/1.2)<<"Coin)"<<endl<<"2.全部出售(大概获得:"<<(int)((double)prize[cnt]/1.2)*wh[cnt]<<"Coin)"<<endl<<"0.不出售"<<endl;
					x=-1;
					while(x<0 || x>2)
						cin>>x;
					if(x==0){
						cout<<"好吧,你说不定要再考虑一下。";
					}
					else if(x==1){
						x=(int)((double)prize[cnt]*(rand()%41+80)/120.0);
						cout<<"好嘞!这是你应得的钱。"<<endl<<"你获得了"<<x<<"个Coin!";
						money+=x;
						wh[cnt]--; 
						Save();
					}
					else{
						x=0;
						for(int i=1;i<=wh[cnt];i++){
							x+=(int)((double)prize[cnt]*(rand()%41+80)/120.0);
						}
						cout<<"好嘞!这是你应得的钱。"<<endl<<"你获得了"<<x<<"个Coin!";
						money+=x;
						wh[cnt]=0; 
						Save();
					}
					Sleep(1000);
				}
			}
		}
	}
	if(who==2){
		while(1){
			system("cls");
			cout<<"当人们考虑到某个特定的未来时,就是一种模糊的异常,这种事真是令人烦恼..."<<endl;
			cout<<"一次,一次,又一次...小心你的愿望,陌生人。"<<endl;
			cout<<"1.兑换卡牌"<<endl<<"0.退出"<<endl;
			cnt=-1;
			while(cnt<0 || cnt>1){
				cin>>cnt;
			}
			if(cnt==0){
				cout<<"为不可预见的后果做好准备,陌生人...我能看见未来。";
				Sleep(1000);
				break;
			}
			else if(cnt==1){
				while(1){
					system("cls");
					cout<<"我们可以公平地交换..."<<endl;
					cout<<"陌生人,你最好明智地做选择。"<<endl;
					for(int i=1;i<=8;i++){
						cout<<i<<".";
						Color(i);
						cout<<level[i];
						Color(0);
						cout<<"卡牌,库存"<<wh[i]<<"张   ";
						if(i==1){
							cout<<"(无法兑换)"<<endl;
						}
						else{
							cout<<"(需要"<<cost[i]<<"张";
							Color(i-1);
							cout<<level[i-1];
							Color(0);
							cout<<"卡)"<<endl;
						}
					}
					cout<<"0.退出"<<endl<<"(输入你想要兑换的卡牌)"<<endl;
					cnt=-1;
					while(cnt<0 || cnt>8){
						cin>>cnt;
					}
					if(cnt==0){
						cout<<"‘如果’并不是一个我常用的词...但如果不是现在,又是什么时候呢...";
						Sleep(1000);
						break; 
					}
					if(cnt==1){
						cout<<"我似乎患有盲点...陌生人,解释一下...";
						Sleep(1000);
						continue;
					}
					cout<<"(确定花费"<<cost[cnt]<<"张";
					Color(cnt-1);
					cout<<level[cnt-1];
					Color(0);
					cout<<"卡牌来兑换一张";
					Color(cnt);
					cout<<level[cnt];
					Color(0);
					cout<<"卡牌吗?  y/n)"<<endl; 
					cin>>xxx;
					if(xxx=='y'){
						if(wh[cnt-1]<cost[cnt]){
							cout<<"(你的库存似乎不支持你兑换这张卡)";
						}
						else{
							cout<<"我一直在等待这一刻...";
							Sleep(500);
							cout<<endl<<"早有人寓言,这就是那一刻..."<<endl;
							Sleep(500);
							cout<<"(你获得了一张";
							Color(cnt);
							cout<<level[cnt];
							Color(0);
							cout<<"卡牌!)"; 
							wh[cnt-1]-=cost[cnt];
							wh[cnt]++;
							Save();
						}
					}
					else{
						cout<<"不要害怕承诺,陌生人...";
					}
					Sleep(1000);
				}
			}
		}
	}
}
3007 5 6363
5 49 47 22 3 11 6 12 
8 8 8 8 8 0 0 0 0 0 
10613653
80885395
#include <bits/stdc++.h>
#include <windows.h>
#include <stdio.h>
#include <fstream>
#include <conio.h>
#include <time.h>
using namespace std;
const long long p1 = 998244353, p2 = 1000000007;
long long pw(long long a, long long b) {
	long long sum = 1;
	while (b) {
		if (b & 1) {
			sum *= a;
			sum %= p2;
		}a *= a;
		a %= p2;
		b /= 2;
	}return sum;
}

int rond() {
	return (((rand() * 39989) % 1000003) + rand()) % 1000003;
}


inline void HideCursor() {
	CONSOLE_CURSOR_INFO cursor_info = {1, 0};
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
inline void SetPos(int x, int y) {
	COORD pos;
	pos.X = y * 2, pos.Y = x;
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
inline void aa_print(string s) {
	int len = s.size();
	for (int i = 0; i < len; i++) {
		cout << s[i];
		Sleep(50);
	}
	return;
}
inline void Color(int a) {
	if (a == 0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
	if (a == 1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE);
	if (a == 2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
	if (a == 3) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 5);
	if (a == 4) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
	if (a == 5) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);
	if (a == 6) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
	if (a == 7) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
	if (a == 8) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
	if (a == 9) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
}//白蓝绿紫红靛黄 深灰 浅灰 粉


POINT Windowpos() {
	//鼠标位置
	POINT pt;
	GetCursorPos(&pt);
	HWND h = GetForegroundWindow();
	ScreenToClient(h, &pt);
	pt.x /= 8;
	pt.y /= 16;
	return pt;
}

char ch;
int craft_q[500010], E = 3;//-1:不能合成 -2:合成失败
char name[10][10];
int c[10] = {0};

bool is_suc[105];//成就是否获得
long long suc_time[105];
int sucE = 0, suc_lookE;//成就已有个数以及已看个数


/*

1. [梦的开始]得到Commmon
2. [更进一步]得到Unusual
3. [由浅至深]得到蓝
4. [日益熟练]得到紫
5. [传奇的!]得到红
6. [神话传说]得到青
7. [拿捏!]得到粉
8. [闪!]得到超
9. [非你莫属]连续十次合卡成功
10.[欧非守恒]连续十次合卡失败
11.

*/


bool r_craft_common = 0;
bool r_craft_unusual = 0;
bool r_craft_rare = 0;
bool r_craft_epic = 0;
bool r_craft_lege = 0;


void fileOut();
bool fileIn();

inline void print_card(int x) {
	switch (x) {
		case 1:
			Color(2);
			printf("Common");
			Color(0);
			break;
		case 2:
			Color(6);
			printf("Unusual");
			Color(0);
			break;
		case 3:
			Color(5);
			printf("Rare");
			Color(0);
			break;
		case 4:
			Color(3);
			printf("Epic");
			Color(0);
			break;
		case 5:
			Color(4);
			printf("Legendary");
			Color(0);
			break;
		case 6:
			Color(1);
			printf("Mythic");
			Color(0);
			break;
		case 7://0白1蓝2绿3紫4红5靛6黄
			Color(9);
			printf("Ultra");
			Color(0);
			break;
		case 8:
			Color(rond() % 7);
			printf("Super");
			Color(0);
			break;
	}
	return;
}
inline void print_suc(int x, bool is) {//成就序号,是否第一次

	if (is) {
		Color(6);
	}else {
		Color(7);
	}
	switch (x) {
		case 1:
			printf("[梦的开始]得到Common卡");
			break;
		case 2:
			printf("[更进一步]得到Unusual卡");
			break;
		case 3:
			printf("[由浅至深]得到Rare卡");
			break;
		case 4:
			printf("[日益熟练]得到Epic卡");
			break;
		case 5:
			printf("[传奇的!]得到Legendary卡");
			break;
		case 6:
			printf("[神话传说]得到Mythic卡");
			break;
		case 7:
			printf("[拿捏!]得到Ultra卡");
			break;
		case 8:
			printf("[闪!]得到Super卡");
			break;
		case 9:
			printf("[非你莫属]连续十次合卡成功");
			break;
		case 10:
			printf("[欧非守恒]连续十次合卡失败");
			break;
	}
	if (is)printf("  time : %.4lf s", suc_time[x] / 1000.0);
	Color(0);
	return;
}

/*

1. [梦的开始]得到Commmon
2. [更进一步]得到Unusual
3. [由浅至深]得到蓝
4. [日益熟练]得到紫
5. [传奇的!]得到红
6. [神话传说]得到青
7. [拿捏!]得到粉
8. [闪!]得到超
9. [非你莫属]连续十次合卡成功
10.[欧非守恒]连续十次合卡失败
11.

*/

int ac_len, nc_len;//成功与失败次数

int get_common, jiatime, start_time, now_time;
inline void craft(int x, bool is) {
	if (c[x] >= 5) {
		int op = rond() % 100;
		if (op < (1 << (8 - x - 1))) {
			nc_len = 0;
			ac_len++;
			if (ac_len >= 10) {
				if (!is_suc[9]) {
					suc_time[9] = now_time - start_time;
					is_suc[9] = 1;
					sucE++;
				}
			}
			if (!is_suc[x + 1]) {
				suc_time[x + 1] = now_time - start_time;
				is_suc[x + 1] = 1;
				sucE++;
			}
			if (is)craft_q[++E] = x + 1;
			if (E > 1e5) {
				E = 3;
			}
			c[x] -= 5;
			c[x + 1]++;
			if (c[x + 1] >= 1e5) {
				c[x + 1] = 1e5 - 1;
			}
		}else {
			ac_len = 0;
			nc_len++;
			if (nc_len >= 10) {
				if (!is_suc[10]) {
					suc_time[10] = now_time - start_time;
					is_suc[10] = 1;
					sucE++;
				}
			}
			c[x] -= (rond() % 4) + 1;
			if (is)craft_q[++E] = -2;
			if (E > 1e5) {
				E = 3;
			}
		}
	} else {
		craft_q[++E] = -1;
		if (E > 1e5) {
			E = 3;
		}
	}
	return;
}
inline void start() {
	SetPos(0, 17);
	aa_print("------赌徒の游戏------");
	SetPos(1, 17);
	aa_print("--Gambler Recreation--");

	SetPos(3, 18);
	printf("-------------------");
	SetPos(4, 18);
	printf("|                 |");
	SetPos(5, 18);
	printf("| 读档[r]/新档[n] |");
	SetPos(6, 18);
	printf("|                 |");
	SetPos(7, 18);
	printf("-------------------");
	char ch = _getch();
	while (ch != 'r' && ch != 'n') {
		ch = _getch();
	}
	if (ch == 'r') {
		if (!fileIn()) {
			SetPos(9, 18);
			Color(4);
			printf("未找到存档,已自动建立新档");
			Sleep(2000);
			start_time = clock();
		} else {
			//有读档不需要开始时间更新
		}
	} else {
		start_time = clock();
	}
	return;
}
int lg_cnt = 0;
bool is_rsave;//是否自动保存

int jiem_id;//界面id,0为一般界面,1为设置,2为说明,3为成就,4为更新日志
inline void print_1() {//打印一般界面
	if (get_common) {
		if (GetAsyncKeyState(VK_SPACE) & 0x8000) {
			if (!is_suc[1]) {
				suc_time[1] = now_time - start_time;
				is_suc[1] = 1;
				sucE++;
			}
			craft_q[++E] = 1;
			if (E > 1e5) {
				E = 3;
			}
			c[1]++;
			if (c[1] >= 1e5) {
				c[1] = 1e5 - 1;
			} 
			while (GetAsyncKeyState(VK_SPACE) & 0x8000);
		}
	} else {
		if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
			if (!is_suc[1]) {
				suc_time[1] = now_time - start_time;
				is_suc[1] = 1;
				sucE++;
			}
			craft_q[++E] = 1;
			if (E > 1e5) {
				E = 3;
			}
			c[1]++;
			if (c[1] >= 1e5) {
				craft(1, 0);
			}
			while (GetAsyncKeyState(VK_LBUTTON) & 0x8000);
		}
	}//特殊的,Common的获取仅限于主界面

	POINT ps = Windowpos();

	SetPos(0, 40);
	printf("目前时间:%.3lfs", (now_time - start_time) / 1000.0);
	SetPos(2, 0);
	//0白 1蓝 2绿 3紫 4红 5靛 6黄 7深灰 8浅灰
	Color(2);
	printf("Common");
	Color(0);
	printf(":%5d ", c[1]);
	Color(6);
	printf("Unusual");
	Color(0);
	printf(":%5d ", c[2]);
	Color(5);
	printf("Rare");
	Color(0);
	printf(":%5d ", c[3]);
	Color(3);
	printf("Epic");
	Color(0);
	printf(":%5d ", c[4]);
	Color(4);
	printf("Legendary");
	Color(0);
	printf(":%5d ", c[5]);
	Color(1);
	printf("Mythic");
	Color(0);
	printf(":%5d ", c[6]);
	Color(9);
	printf("Ultra");
	Color(0);
	printf(":%5d ", c[7]);
	Color(rond() % 7);
	printf("Super");
	Color(0);
	printf(":%5d      ", c[8]);
	SetPos(1, 0);
	printf("按下 c键可清除下方消息队列");
	for (int i = E; i >= max(4, E - 19); i--) {
		SetPos(E - i + 4, 4);
		if (craft_q[i] < 0) {
			if (craft_q[i] == -1) {
				Color(4);
				printf("数量不足                   ");
				Color(0);
			} else {
				Color(4);
				printf("合成失败                   ");
				Color(0);
			}
		} else {
			printf("你得到了一张");
			print_card(craft_q[i]);
			printf("卡!   ");
		}
	}
	for (int j = max(4, E - 19) - 1; j >= E - 19; j--) {
		SetPos(E - j + 4, 4);
		printf("                           ");
	}
	SetPos(0, 0);
	printf("赌徒游戏v1.06");
	if (is_rsave && lg_cnt % 60 <= 1) {
		SetPos(6, 18);
		Color(2);
		printf("已自动保存");
		Color(0);
	} else {
		SetPos(6, 18);
		printf("          ");
	}
	SetPos(4, 18);
	if (ps.y == 4 && ps.x >= 36 && ps.x <= 39) {
		printf("设置[q]");
		if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
			while (GetAsyncKeyState(VK_LBUTTON) & 0x8000);
			jiem_id = 1;
			system("cls");
			return;
		}
	}else {
		Color(7);
		printf("设置[q]");
		Color(0);
	}
	if (GetAsyncKeyState(81)&0x8000) {//q
		while (GetAsyncKeyState(81)&0x8000);
		jiem_id = 1;
		system("cls");
		return;
	}
	SetPos(4, 22);
	if (ps.y == 4 && ps.x >= 44 && ps.x <= 47) {
		printf("说明[w]");
		if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
			while (GetAsyncKeyState(VK_LBUTTON) & 0x8000);
			jiem_id = 2;
			system("cls");
			return;
		}
	} else {
		Color(7);
		printf("说明[w]");
		Color(0);
	}
	if (GetAsyncKeyState(87)&0x8000) {//q
		while (GetAsyncKeyState(87)&0x8000);
		jiem_id = 2;
		system("cls");
		return;
	}
	SetPos(4, 26);
	if (ps.y == 4 && ps.x >= 52 && ps.x <= 55) {
		printf("成就[e]");
		if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
			while (GetAsyncKeyState(VK_LBUTTON) & 0x8000);
			jiem_id = 3;
			system("cls");
			return;
		}
	} else {
		if (sucE == suc_lookE)Color(7);
		else {
			if (lg_cnt % 2) {
				Color(7);
			} else {
				Color(2);
			}
		}
		printf("成就[e]");
		Color(0);
	}
	if (GetAsyncKeyState(69)&0x8000) {//q
		while (GetAsyncKeyState(69)&0x8000);
		jiem_id = 3;
		system("cls");
		return;
	}
	SetPos(4, 32);
	if (ps.y == 4 && ps.x >= 64 && ps.x <= 71) {
		printf("筹码游戏[r]");
		if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
			while (GetAsyncKeyState(VK_LBUTTON) & 0x8000);
			jiem_id = 4;
			system("cls");
			return;
		}
	} else {
		Color(7);
		printf("筹码游戏[r]");
		Color(0);
	}
	if (GetAsyncKeyState(82)&0x8000) {//q
		while (GetAsyncKeyState(82)&0x8000);
		jiem_id = 4;
		system("cls");
		return;
	}
	return;
}
void print_2() {
	POINT ps = Windowpos();
//	SetPos(0, 0);
//	cout << ps.x << ":" << ps.y << endl;
	Color(4);
	SetPos(0, 49);
	printf("---");
	SetPos(1, 49);
	if (ps.y >= 0 && ps.y <= 2 && ps.x >= 98 && ps.x <= 100) {
		Color(0);
		printf("[x]");
		Color(4);
	} else {
		printf("[x]");
	}
	SetPos(2, 49);
	printf("---");
	Color(0);

	SetPos(2, 2);
	printf("[C]ommon自动合成: ");
	if (r_craft_common) {
		if (ps.y == 2 && ps.x >= 4 && ps.x <= 23) {
			Color(0);
		}else Color(2);
		printf("开");
	} else {
		if (ps.y == 2 && ps.x >= 4 && ps.x <= 23) {
			Color(0);
		}else Color(4);
		printf("关");
	}
	Color(0);
	
	SetPos(3, 2);
	printf("[U]nusual自动合成: ");
	if (r_craft_unusual) {
		if (ps.y == 3 && ps.x >= 4 && ps.x <= 24) {
			Color(0);
		}else Color(2);
		printf("开");
	} else {
		if (ps.y == 3 && ps.x >= 4 && ps.x <= 24) {
			Color(0);
		}else Color(4);
		printf("关");
	}
	Color(0);
	
	SetPos(4, 2);
	printf("[R]are自动合成: ");
	if (r_craft_rare) {
		if (ps.y == 4 && ps.x >= 4 && ps.x <= 21) {
			Color(0);
		}else Color(2);
		printf("开");
	} else {
		if (ps.y == 4 && ps.x >= 4 && ps.x <= 21) {
			Color(0);
		}else Color(4);
		printf("关");
	}
	Color(0);
	
	SetPos(5, 2);
	printf("[E]pic自动合成: ");
	if (r_craft_epic) {
		if (ps.y == 5 && ps.x >= 4 && ps.x <= 21) {
			Color(0);
		}else Color(2);
		printf("开");
	} else {
		if (ps.y == 5 && ps.x >= 4 && ps.x <= 21) {
			Color(0);
		}else Color(4);
		printf("关");
	}
	Color(0);
	
	SetPos(6, 2);
	printf("[L]egendary自动合成: ");
	if (r_craft_lege) {
		if (ps.y == 6 && ps.x >= 4 && ps.x <= 26) {
			Color(0);
		}else Color(2);
		printf("开");
	} else {
		if (ps.y == 6 && ps.x >= 4 && ps.x <= 26) {
			Color(0);
		}else Color(4);
		printf("关");
	}
	Color(0);
	
	SetPos(7, 2);
	printf("[T]Common获取方法:");
	if (ps.y == 7 && ps.x >= 4 && ps.x <= 26) {
		Color(0);
	} else Color(8);
	if (get_common) {
		printf("空格");
	} else {
		printf("鼠标");
	}
	Color(0);

	SetPos(8, 2);
	printf("[S]自动保存(60s):");
	if (is_rsave) {
		if (ps.y == 8 && ps.x >= 4 && ps.x <= 22) {
			Color(0);
		} else Color(2);
		printf("开");
	} else {
		if (ps.y == 8 && ps.x >= 4 && ps.x <= 22) {
			Color(0);
		} else Color(4);
		printf("关");
	}
	if (GetAsyncKeyState(88) & 0x8000) {
		while (GetAsyncKeyState(88) & 0x8000);
		jiem_id = 0;
		system("cls");
		return;
	}
	if (ps.y >= 0 && ps.y <= 2 && ps.x >= 98 && ps.x <= 100) {
		if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
			while (GetAsyncKeyState(VK_LBUTTON) & 0x8000);
			jiem_id = 0;
			system("cls");
			return;
		}
	}
	if (GetAsyncKeyState(67) & 0x8000) {
		while (GetAsyncKeyState(67) & 0x8000);
		r_craft_common = !r_craft_common;
	}
	if (ps.y == 2 && ps.x >= 4 && ps.x <= 23) {
		if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
			while (GetAsyncKeyState(VK_LBUTTON) & 0x8000);
			r_craft_common = !r_craft_common;
		}
	}
	if (GetAsyncKeyState(85) & 0x8000) {
		while (GetAsyncKeyState(85) & 0x8000);
		r_craft_unusual = !r_craft_unusual;
	}
	if (ps.y == 3 && ps.x >= 4 && ps.x <= 24) {
		if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
			while (GetAsyncKeyState(VK_LBUTTON) & 0x8000);
			r_craft_unusual = !r_craft_unusual;
		}
	}
	if (GetAsyncKeyState(82) & 0x8000) {
		while (GetAsyncKeyState(82) & 0x8000);
		r_craft_rare = !r_craft_rare;
	}
	if (ps.y == 4 && ps.x >= 4 && ps.x <= 21) {
		if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
			while (GetAsyncKeyState(VK_LBUTTON) & 0x8000);
			r_craft_rare = !r_craft_rare;
		}
	}
	if (GetAsyncKeyState(69) & 0x8000) {
		while (GetAsyncKeyState(69) & 0x8000);
		r_craft_epic = !r_craft_epic;
	}
	if (ps.y == 5 && ps.x >= 4 && ps.x <= 21) {
		if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
			while (GetAsyncKeyState(VK_LBUTTON) & 0x8000);
			r_craft_epic = !r_craft_epic;
		}
	}
	if (GetAsyncKeyState(76) & 0x8000) {
		while (GetAsyncKeyState(76) & 0x8000);
		r_craft_lege = !r_craft_lege;
	}
	if (ps.y == 6 && ps.x >= 4 && ps.x <= 26) {
		if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
			while (GetAsyncKeyState(VK_LBUTTON) & 0x8000);
			r_craft_lege = !r_craft_lege;
		}
	}
	if (GetAsyncKeyState(84) & 0x8000) {
		while (GetAsyncKeyState(84) & 0x8000);
		get_common = !get_common;
	}
	if (ps.y == 7 && ps.x >= 4 && ps.x <= 26) {
		if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
			while (GetAsyncKeyState(VK_LBUTTON) & 0x8000);
			get_common = !get_common;
		}
	}
	if (GetAsyncKeyState(83) & 0x8000) {
		while (GetAsyncKeyState(83) & 0x8000);
		is_rsave = !is_rsave;
	}
	if (ps.y == 8 && ps.x >= 4 && ps.x <= 22) {
		if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
			while (GetAsyncKeyState(VK_LBUTTON) & 0x8000);
			is_rsave = !is_rsave;
		}
	}
	return;
}
void print_3() {//说明
	//白蓝绿紫红靛黄 深灰 浅灰
	SetPos(1, 2);
	printf("规则:");
	SetPos(2, 2);
	printf("本游戏中共有八种卡牌:");
	Color(2);
	printf("Common");
	Color(0);
	printf(",");
	Color(6);
	printf("Unusual");
	Color(0);
	printf(",");
	Color(5);
	printf("Rare");
	Color(0);
	printf(",");
	Color(3);
	printf("Epic");
	Color(0);
	printf(",");
	Color(4);
	printf("Legendary");
	Color(0);
	printf(",");
	Color(1);
	printf("Mythic");
	Color(0);
	printf(",");
	Color(9);
	printf("Ultra");
	Color(0);
	printf(",");
	Color(rond() % 7);
	printf("Super");
	Color(0);
	SetPos(3, 2);
	printf("通过鼠标或空格(方式可在设置中改变)可获得一张基础Common卡牌");
	SetPos(4, 2);
	printf("同时,若设Common卡牌为lv.1,则按下数字键x可自动将5张lv.x等级的卡牌合成一张lv.x+1等级的卡牌");
	SetPos(5, 2);
	printf("每次合成有(2^(7-x))%的几率成功,若失败,则随机失去1至4张卡牌(与florr的合卡机制相同)");
	SetPos(6, 2);
	printf("同时卡牌数量上限为10^5(注:削挂机类玩家)");
	SetPos(7, 2);
	printf("对于一张 3级及以上的卡牌(即");
	Color(5);
	printf("Rare");
	Color(0);
	printf("及以上)每 x-2秒能使lv.x-2卡牌增加一张(如同打怪)");
	SetPos(8, 2);
	printf("玩得开心!");

	Color(8);
	SetPos(13, 2);
	printf("关于作者:");
	SetPos(14, 2);
	printf("可于洛谷uid.474470联系,也可微信wizardMarshall62442");
	SetPos(15, 2);
	printf("欢迎反馈本游戏存在的问题");
	Color(0);
	Color(4);
	SetPos(0, 49);
	printf("---");
	SetPos(1, 49);
	printf("[x]");
	SetPos(2, 49);
	printf("---");
	Color(0);
	POINT ps = Windowpos();
	if (ps.y >= 0 && ps.y <= 2 && ps.x >= 98 && ps.x <= 100) {
		SetPos(1, 49);
		printf("[x]");
		if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
			while (GetAsyncKeyState(VK_LBUTTON) & 0x8000);
			jiem_id = 0;
			system("cls");
			return;
		}
	}
	if (GetAsyncKeyState(88) & 0x8000) {
		while (GetAsyncKeyState(88) & 0x8000);
		jiem_id = 0;
		system("cls");
		return;
	}
	return;
}
void print_4() {//成就
	POINT ps = Windowpos();
	Color(4);
	SetPos(0, 49);
	printf("---");
	Color(0);
	SetPos(1, 49);
	if (ps.y >= 0 && ps.y <= 2 && ps.x >= 98 && ps.x <= 100) {
		Color(0);
		printf("[x]");
		if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
			while (GetAsyncKeyState(VK_LBUTTON) & 0x8000);
			jiem_id = 0;
			suc_lookE = sucE;
			system("cls");
			return;
		}
	}else {
		Color(4);
		printf("[x]");
		Color(0);
	}
	if (GetAsyncKeyState(88) & 0x8000) {
		while (GetAsyncKeyState(88) & 0x8000);
		jiem_id = 0;
		suc_lookE = sucE;
		system("cls");
		return;
	}
	Color(4);
	SetPos(2, 49);
	printf("---");
	Color(0);
	if (!sucE) {
		SetPos(2, 2);
		printf("这个家伙很懒,什么也没有留下");
	}else {
		for (int i = 1; i <= 10; i++) {
			SetPos(i + 1, 2);
			print_suc(i, is_suc[i]);
			if (i == 1)printf("                             ");
		}
	}
	return;
}
void print_5() {
	POINT ps = Windowpos();
	Color(4);
	SetPos(2, 49);
	printf("---");
	Color(0);
	Color(4);
	SetPos(0, 49);
	printf("---");
	Color(0);
	SetPos(1, 49);
	if (ps.y >= 0 && ps.y <= 2 && ps.x >= 98 && ps.x <= 100) {
		SetPos(1, 49);
		printf("[x]");
		if (GetAsyncKeyState(VK_LBUTTON) & 0x8000) {
			while (GetAsyncKeyState(VK_LBUTTON) & 0x8000);
			jiem_id = 0;
			system("cls");
		}
	} else {
		Color(4);
		printf("[x]");
		Color(0);
	}
	if (GetAsyncKeyState(88) & 0x8000) {
		while (GetAsyncKeyState(88) & 0x8000);
		jiem_id = 0;
		system("cls");
		return;
	}
	SetPos(2, 2);
	printf("功能开发中……");
	//	printf("                o\n");
	//	printf("               o o\n");
	//	printf("              o o o\n");
	//	printf("             o o o o\n");
	//	printf("            o o o o o\n");
	//	printf("           o o o o o o\n");
	//	printf("          o o o o o o o\n");
	//	printf("         o o o o o o o o\n");
	//	printf("        o o o o o o o o o\n");
	//	printf("       o o o o o o o o o o\n");
	//	printf("      o o o o o o o o o o o\n");
	//	printf("     o o o o o o o o o o o o\n");
	//	printf("    o o o o o o o o o o o o o\n");
	//	printf("   o o o o o o o o o o o o o o\n");
	//	printf("  o o o o o o o o o o o o o o o\n");
	//	printf(" o o o o o o o o o o o o o o o o\n");
	//	printf("o o o o o o o o o o o o o o o o o\n");
	//退出的时候还在掉落的收回!
	return;
}
/*

500 20 5 3 2 0 1 1 1 1 1 0 2 3 5 20 500

*/ 


signed main() {
//	c[5] = 101;
//	c[4] = 17;
	//空格为32,数字为48+x
	srand(time(NULL));
	SetConsoleTitle("赌徒游戏");
	system("mode con cols=101 lines=25");
	HideCursor();
	SetWindowLongPtrA(GetConsoleWindow(), GWL_STYLE, GetWindowLongPtrA(GetConsoleWindow(), GWL_STYLE) & ~WS_SIZEBOX & ~WS_MAXIMIZEBOX & ~WS_MINIMIZEBOX);
	start();
	system("cls");
	get_common = 0;
	jiatime = clock();
	r_craft_common = 0, r_craft_unusual = 0, r_craft_rare = 0;
	lg_cnt = 0;
	while (1) {
		now_time = clock();
		if (now_time - jiatime >= 1000) {
			jiatime = now_time;
			lg_cnt++;
			if (lg_cnt % 60 == 0 && is_rsave) {
				fileOut();
			}
			for (int i = 3; i <= 8; i++) {
				if (lg_cnt % (i - 2) == 0) {
					c[i - 2] += c[i];
					if (c[i - 2] >= 1e5)c[i - 2] = 1e5 - 1;
				}
			}
		}
		if (r_craft_common) {
			while (c[1] >= 5) {
				craft(1, 0);
			}
		}
		if (r_craft_unusual) {
			while (c[2] >= 5) {
				craft(2, 0);
			}
		}
		if (r_craft_rare) {
			while (c[3] >= 5) {
				craft(3, 0);
			}
		}
		if (r_craft_epic) {
			while (c[4] >= 5) {
				craft(4, 0);
			}
		}
		if (r_craft_lege) {
			while (c[5] >= 5) {
				craft(5, 0);
			}
		}
		if (kbhit()) {
			char ch = _getch();
			if (ch >= '1' && ch <= '7') {
				craft(ch - '0', 1);
			} else if (ch == 'c') {
				E = 3;
			}
		}
		if (jiem_id == 0)print_1();
		else if (jiem_id == 1)print_2();
		else if (jiem_id == 2)print_3();
		else if (jiem_id == 3)print_4();
		else if (jiem_id == 4)print_5();
	}
	return 0;
}

void fileOut() {
	ofstream out("GRcd.txt");
	out << now_time - start_time << ' ' << c[8] << ' ' << c[2] << ' ' << c[7] << ' ' << c[4] << ' ' << c[5] << ' ' << c[3] << ' ' << c[6] << ' ' << c[1] << ' ';
	out << sucE << ' ' << suc_lookE << ' ';
	int sum = 0;
	for (int i = 1; i <= 10; i++) {
		if (is_suc[i])sum |= (1 << i);
	}out << sum << ' ';
	for (int i = 1; i <= 10; i++) {
		out << suc_time[i] << ' ';
	}
	out.close();
	return;
}

bool fileIn() {
	ifstream in("GRcd.txt");
	int t_time;
	if (in >> t_time >> c[8] >> c[2] >> c[7] >> c[4] >> c[5] >> c[3] >> c[6] >> c[1] >> sucE >> suc_lookE) {
		int sum;in >> sum;
		for (int i = 1; i <= 10; i++) {
			is_suc[i] = ((sum >> i) & 1);
			in >> suc_time[i];
		}
		start_time = clock() - t_time;
		now_time = clock();
		in.close();
		return 1;
	} else {
		fileOut();
		in.close();
		return 0;
	}
}


/*

备忘功能:

1.成就改成解锁类型(灰色->金色)
2.战斗模式
3.筹码游戏

*/
85769250 0 4 12 3 16812 3 384 2 9 9 1790 8370 23626 36190 240983 282593 301498 4832450 0 32291 281765