跳到正文

休闲·娱乐

挖矿游戏

WYSY034约 38 分钟
原文
文章信息与版本

文章信息

发布
2026年5月1日
收录
2026年5月16日
更新
2026年11月16日
篇幅
约 38 分钟

版本

  1. v2当前
  2. v1

不喜勿喷

有点无聊,休闲随便写的,有保存功能(别删save.txt这是存档)。

C++
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#include<climits>
#define endl "\n"
using namespace std;
const int inf=INT_MAX;
const string m_namelist[]={"[石]","[煤]","[青]","[铜]","[银]","[金]","[钻]","[合]","[铀]"};
const int m_co[]={8,8,9,5,15,6,11,4,2};
const int m_pr[]={1,2,4,5,8,10,15,20,30};
const int m_ha[]={0,0,1,2,2,2,3,4,5};
const int m_weight[]={35,30,15,10,8,7,2,1,1};
const string sm_namelist[]={"[镭]","[翡]","[铱]","[铑]"};
const int sm_co[]={10,12,15,15};
const int sm_pr[]={50,55,60,50};
const int sm_ha[]={6,6,6,6};
const string ma_namelist[]={"[手]","[木稿]","[石稿]","[铜稿]","[铁稿]","[钻稿]","[合金稿]"};
const int manu_ha[]={0,1,2,2,3,4,5};
const double manu_ef[]={1.0,0.9,0.8,0.7,0.6,0.5,0.4};
const int manu_dur[]={inf,60,132,191,251,1562,2032};
const string fucking[]={"mother","sister","fuck","dame","suck","shit","bitch","testicle","your","idiot","and","lick","sexy","hole","dick","eat","orgasm","gay"};
void sc(int c){
    HANDLE h=GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(h,c);
}
void gotoxy(int x,int y){
    COORD pos;
    pos.X=x;
    pos.Y=y;
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);
}
mt19937 gen(time(0));
int ran(int a,int b){
    if(a>b)swap(a,b);
    uniform_int_distribution<int>dist(a,b);
    return dist(gen);
}
string ranstr(int length){
    const string chars="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()_+-=[]{}|;:,.<>?";
    string str;
    for(int i=0;i<length;i++){
        str+=chars[ran(0,chars.size()-1)];
    }
    return str;
}
void c_r(string s){
    for(char c:s){
        cout<<c;
        Sleep(40);
    }
}
void c_r2(string s){
    c_r(s);
    cout<<endl;
}
void c_r3(string s){
    for(char c:s){
        sc(ran(1,15));
        cout<<c;
        Sleep(40);
    }
    sc(7);
    cout<<endl;
}
struct mineral{
    int weight,purity,m_level,mh_level,m_prize;
    string m_name;
};
struct manuscript{
    int ma_level,mah_level,dur;
    double eff;
    string ma_name;
};
struct player{
    string p_name;
    int money,bp_level;
    vector<mineral>bp;
    manuscript man;
}p1;
void save(){
    ofstream f("save.txt");
    if(!f)return;
    f<<p1.p_name<<endl;
    f<<p1.money<<endl;
    f<<p1.bp_level<<endl;
    f<<p1.man.ma_level<<endl;
    f<<p1.man.dur<<endl;
    f<<p1.bp.size()<<endl;
    for(auto&m:p1.bp){
        f<<m.m_level<<" "<<m.weight<<" "<<m.purity<<endl;
    }
    f.close();
    c_r2("游戏已自动保存!");
    Sleep(500);
}
bool has_save(){
    ifstream f("save.txt");
    return f.good();
}
void name_in(){
    cout<<"请输入你的名字:";
    cin>>p1.p_name;
    p1.p_name='['+p1.p_name+']';
    system("cls");
}
void start(){
    for(int i=1;i<=10;i++)cout<<endl;
    cout<<"                                           <=====<挖矿游戏>=====>\n";
    cout<<"                                           |   (发育小游戏)     |\n";
    cout<<"                                           |按 下 任 意 键 开 始|\n";
    cout<<"                                           <====================>";
    getch();
    system("cls");
}
void update_manu(int level){
    p1.man.ma_level=level;
    p1.man.dur=manu_dur[level];
    p1.man.eff=manu_ef[level];
    p1.man.ma_name=ma_namelist[level];
    p1.man.mah_level=manu_ha[level];
}
void update_player(){
    p1.bp_level=20;
    p1.money=120;
    update_manu(0);
}
void update_mineral(int lv,mineral &m1){
	m1.mh_level=m_ha[lv];
    m1.m_level=lv;
    m1.m_name=m_namelist[lv];
    m1.purity=ran(60,100);
    m1.weight=ran(1,3);
    if(m1.mh_level>=6)m1.m_prize=sm_pr[m1.m_level]*m1.weight*(m1.purity/50.0);
	else m1.m_prize=m_pr[m1.m_level]*m1.weight*(m1.purity/50.0);
}
void update_smineral(int lv,mineral &m1){
	m1.mh_level=sm_ha[lv];
    m1.m_level=lv;
    m1.m_name=sm_namelist[lv];
    m1.purity=ran(80,100);
    m1.weight=ran(1,3);
}
int pick_ore(){
    vector<int>ok;
    for(int i=0;i<9;i++){
        if(m_ha[i]<=p1.man.mah_level){
            ok.push_back(i);
        }
    }
    int sum=0;
    for(int i:ok)sum+=m_weight[i];
    int r=ran(1,sum);
    int cur=0;
    for(int i:ok){
        cur+=m_weight[i];
        if(r<=cur)return i;
    }
    return ok[0];
}
void load(){
    ifstream f("save.txt");
    if(!f)return;
    getline(f,p1.p_name);
    f>>p1.money;
    f>>p1.bp_level;
    int lv;
    f>>lv;
    update_manu(lv);
    f>>p1.man.dur;
    int sz;
    f>>sz;
    p1.bp.clear();
    for(int i=0;i<sz;i++){
        mineral m;
        f>>m.m_level;
        f>>m.weight;
        f>>m.purity;
        m.m_name=m_namelist[m.m_level];
        m.mh_level=m_ha[m.m_level];
        p1.bp.push_back(m);
    }
    f.close();
}
void show_p(){
    system("cls");
    cout<<"<=======<主菜单>=======>"<<endl;
    cout<<"名称:"<<p1.p_name<<endl;
    cout<<"$金币$:"<<p1.money<<endl;
    cout<<"工具:"<<p1.man.ma_name<<" 效率:"<<fixed<<setprecision(1)<<p1.man.eff<<" 耐久:"<<(p1.man.dur==inf?"无限":to_string(p1.man.dur))<<endl;
    cout<<"背包容量:"<<p1.bp_level<<endl;
    cout<<"背包已装:"<<p1.bp.size()<<"/"<<p1.bp_level<<endl;
    cout<<"<======================>"<<endl;
}
void show_bag(){
    system("cls");
    c_r2("<===<你的背包>===>");
    if(p1.bp.empty()){
        c_r2("背包空空如也...");
    }else{
        for(int i=0;i<p1.bp.size();i++){
            auto&m=p1.bp[i];
            if(m.mh_level>=6)sc(sm_co[m.m_level]);
			else sc(m_co[m.m_level]);
            cout<<i+1<<". "<<m.m_name<<" 纯度:"<<m.purity<<" 重量:"<<m.weight<<endl;
        }
    }
    sc(7);
    c_r2("\n按任意键返回...");
    _getch();
}
void sell_all(){
    if(p1.bp.empty()){
        c_r2("背包里没有矿物可以卖!");
        Sleep(800);
        return;
    }
    int total=0;
    for(auto&m:p1.bp){
    	int price;
        if(m.mh_level>=6)price+=sm_pr[m.m_level]*m.weight*(m.purity/50.0);
		else price+=m_pr[m.m_level]*m.weight*(m.purity/50.0);
        total+=price;
    }
    p1.money+=total;
    p1.bp.clear();
    c_r("卖出所有矿物,获得 $");
    cout<<total<<endl;
    Sleep(1000);
}
bool game(){
	system("cls");
	show_p();
	c_r("特殊矿时刻!!!");
	int progress=0;
	for(int round=1;round<=7;round++){
		string game="[---------------------]";
		int location=ran(1,21); 
		game[location]='|';
		show_p();
		cout<<"\n进度:[";
		for(int i=1;i<=progress;i++)cout<<'$';
		for(int i=progress+1;i<=10;i++)cout<<' ';
		cout<<"]\n";
		bool got=false;
		for(int j=1;j<=21;j++){
			gotoxy(0,0);
			show_p();
			cout<<"\n进度:[";
			for(int i=1;i<=progress;i++)cout<<'$';
			for(int i=progress+1;i<=10;i++)cout<<' ';
			cout<<"]\n";
			for(int i=0;i<game.size();i++){
				if(i==j)cout<<"{}";
				else cout<<game[i];
			}
			cout<<endl;
			if(_kbhit()){
				char k=_getch();
				if(k==' '){
					if(abs(j-location)<=3){
						c_r2("Perfect!!");
						progress += 2;
						if(progress>10)progress=10;
					}else c_r2("Miss~~");
					Sleep(500);
					got=1;
					break;
				}
			}
			Sleep(35);
		}
		if(!got){
			c_r2("超时!!");
			Sleep(500);
		}
	}
	system("cls");
	if(progress>=10){
		c_r2("挑战成功!获得稀有矿石!");
		Sleep(1000);
		return true;
	}else{
		c_r2("挑战失败!");
		Sleep(1000);
		return false;
	}
}
void buy_man(){
    system("cls");
    c_r2("<===<商店>===>");
    cout<<"1.木稿(60$) 2.石稿(120$) 3.铜稿(180$)"<<endl;
    cout<<"4.铁稿(250$) 5.钻稿(600$) 6.合金稿(1200$)"<<endl;
    cout<<"7.背包升级+10格(200$)"<<endl;
    c_r("请选择: ");
    char ch=_getch();
    int cost[]={0,60,120,180,250,600,1200,200};
    int lv=ch-'0';
    if(lv>=1&&lv<=6){
        if(p1.money>=cost[lv]){
            p1.money-=cost[lv];
            update_manu(lv);
            c_r2("购买成功!");
        }else{
            c_r2("金币不足!");
        }
    }
    else if(lv==7){
        if(p1.money>=200){
            p1.money-=200;
            p1.bp_level+=10;
            c_r2("背包升级成功!容量+10");
        }else{
            c_r2("金币不足!");
        }
    }
    else{
        c_r2("无效选择!");
    }
    Sleep(800);
}
void conversation(){
    string sn,an;
    system("cls");
    cout<<"<==AI聊天==>"<<endl;
    cout<<"|--out退出--|"<<endl;
    while(1){
        cout<<p1.p_name<<':';
        cin>>sn;
        if(sn=="out")return;
        if(sn=="/give"){
        	if(p1.bp.size()>=p1.bp_level){
		        c_r2("背包已满!请先出售矿物!");
		        Sleep(1000);
		        return;
		    }else{
			    cin>>sn;
	        	if(sn=="mineral"){
	        		int n;
	        		cin>>n;
	        		mineral m2;
				    update_mineral(n,m2);
				    m2.purity=100;
				    m2.weight=3;
	        		p1.bp.push_back(m2);
				}else if(sn=="manuscript"){
					int n1;
					cin>>n1;
					update_manu(n1);
				}else if(sn=="money"){
					int n2;
					cin>>n2;
					p1.money+=n2;
				}
				cout<<"[system]:";
				c_r2("Accept "+p1.p_name+" op command.");
			}
		}else if(sn.find("fuck")!=string::npos){
			string s2;
			cout<<"[FUCK_AI]:"<<p1.p_name<<' ';
			for(int i=1;i<=ran(10,30);i++)s2+=(fucking[ran(0,17)]+' ');
			s2+='.';
			c_r3(s2);
		}else{
			if(sn=="out")return;
			cout<<"[AI]:";
	        an=ranstr(ran(1,30));
	        c_r3("大SB"+p1.p_name+an);
		}
        if(sn=="out")return;
    }
    system("cls");
}
void main_dig(){
    show_p();
    if(p1.man.dur<=0){
        c_r2("你的工具坏了!先去买新的!");
        Sleep(1000);
        return;
    }
    c_r2("正在挖矿中...");
    int k=ran(1,10)*1000;
    for(int i=1;i<=int(k*p1.man.eff)/1000;i++){
        gotoxy(0,0);
        show_p();
        cout<<"正在挖矿中..."<<endl;
        cout<<'[';
        for(int j=1;j<=i;j++)cout<<'\\';
        cout<<']'<<endl;
        Sleep(1000*p1.man.eff+200);
    }
    if(p1.bp.size()>=p1.bp_level){
        c_r2("背包已满!请先出售矿物!");
        Sleep(1000);
        return;
    }
    mineral m1;
    int smr=ran(1,25);
    if(smr==16){
    	if(game()){
    		int r1=ran(0,3);
    		update_smineral(r1,m1);
    		sc(sm_co[r1]);
    		if(p1.man.dur!=inf)p1.man.dur-=1+2*sm_ha[r1];
		}else return;
	}else{
		int r=pick_ore();
	    update_mineral(r,m1);
	    sc(m_co[r]);
		if(p1.man.dur!=inf)p1.man.dur-=1+2*m_ha[r];
	}
	c_r("你挖到了 ");
	cout<<m1.m_name<<"x"<<m1.weight<<endl;
	p1.bp.push_back(m1);
    if(p1.man.dur<0)p1.man.dur=0;
    Sleep(1000);
    sc(7);
}
void menu(){
    show_p();
    c_r2("1.挖矿  2.背包  3.商店  4.出售  5.AI聊天  6.退出");
    c_r("选择:");
    char op=_getch();
    switch(op){
        case '1':main_dig();break;
        case '2':show_bag();break;
        case '3':buy_man();break;
        case '4':sell_all();break;
        case '5':conversation();break;
        case '6':save();exit(0);
    }
}
int main(){
    if(has_save()){
        load();
        c_r2("读取存档成功!");
        Sleep(1000);
		system("cls");
    }
    start();
    if(!has_save()){
        name_in();
        update_player();
    }
    while(1)menu();
}

还有AIAI版

C++
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#include<climits>
#define endl "\n"
using namespace std;

const int inf=INT_MAX;
const string m_namelist[]={"[石]","[煤]","[青]","[铜]","[银]","[金]","[钻]","[合]","[铀]"};
const int m_co[]={8,8,9,5,15,6,11,4,2};
const int m_pr[]={1,2,4,5,8,10,15,20,30};
const int m_ha[]={0,0,1,2,2,2,3,4,5};
const int m_weight[]={35,30,15,10,8,7,2,1,1};
const string ma_namelist[]={"[手]","[木稿]","[石稿]","[铜稿]","[铁稿]","[钻稿]","[合金稿]"};
const int manu_ha[]={0,1,2,2,3,4,5};
const double manu_ef[]={1.0,0.9,0.8,0.7,0.6,0.5,0.4};
const int manu_dur[]={inf,60,132,191,251,1562,2032};
const int cost[]={0,60,120,180,250,600,1200,200};

void sc(int c){
	HANDLE h=GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleTextAttribute(h,c);
}

mt19937 gen(time(0));
int ran(int a,int b){
	if(a>b)swap(a,b);
	uniform_int_distribution<int>dist(a,b);
	return dist(gen);
}

string ranstr(int length){
	const string chars="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#$%^&*()_+-=[]{}|;:,.<>?";
	string str;
	for(int i=0;i<length;i++){
		str+=chars[ran(0,chars.size()-1)];
	}
	return str;
}

void c_r(string s){
	for(char c:s){
		cout<<c;
		Sleep(40);
	}
}

void c_r2(string s){
	c_r(s);
	cout<<endl;
}

void c_r3(string s){
	for(char c:s){
		sc(ran(0,15));
		cout<<c;
		Sleep(40);
	}
	sc(7);
	cout<<endl;
}

struct mineral{
	int weight,purity,m_level,mh_level;
	string m_name;
};

struct manuscript{
	int ma_level,mah_level,dur;
	double eff;
	string ma_name;
};

struct player{
	string p_name;
	int money,bp_level;
	vector<mineral>bp;
	manuscript man;
}p1;

void save();
bool has_save();
void name_in();
void start();
void update_manu(int level);
void update_player();
int pick_ore();
void load();
void show_p();
void show_bag();
void sell_all();
void buy_man();
void conversation();
void main_dig();
void menu();
void ai_auto_dig();
void ai_buy_best_tool();
void ai_upgrade_bag();

void ai_buy_best_tool(){
	int best = -1;
	for(int i=6;i>=1;i--){
		if(p1.money >= cost[i]){
			best = i;
			break;
		}
	}
	if(best != -1 && best > p1.man.ma_level){
		p1.money -= cost[best];
		update_manu(best);
		c_r2("[AI] 自动购买了更好的工具!");
		Sleep(500);
	}
}

void ai_upgrade_bag(){
    if(p1.money >= 200){
        p1.money -= 200;
        p1.bp_level += 10;
        c_r2("[AI] 自动升级背包!");
        Sleep(300);
    }
}

void ai_auto_dig(){
	if(p1.money < 100){
		c_r2("[AI] 启动失败!需要 100 金币才能开启自动挖矿!");
		Sleep(1500);
		return;
	}
	p1.money -= 100;
	c_r2("[AI] 已扣除 100 金币,启动成功!");
	c_r2("[AI] 按 Q 退出挂机");
	Sleep(1500);
	while(true){
		if(_kbhit()){
			char ch = _getch();
			if(ch == 'q' || ch == 'Q'){
				c_r2("\n[AI] 已退出挂机模式!");
				Sleep(1000);
				return;
			}
		}
		show_p();
		if(p1.man.dur <= 0){
			c_r2("[AI] 工具损坏,自动卖矿维修!");
			sell_all();
			ai_buy_best_tool();
			continue;
		}
		if(p1.bp.size() >= p1.bp_level){
			c_r2("[AI] 背包已满,自动出售所有矿物!");
			sell_all();
			ai_upgrade_bag();
			ai_buy_best_tool();
			continue;
		}
		c_r2("[AI] 正在挖矿中...");
		int k=ran(1,10)*1000;
		for(int i=1;i<=int(k*p1.man.eff)/1000;i++){
			if(_kbhit()) break;
			system("cls");
			show_p();
			cout<<"[AI] 正在挖矿中..."<<endl;
			cout<<'[';
			for(int j=1;j<=i;j++)cout<<'\\';
			cout<<']'<<endl;
			Sleep(1000*p1.man.eff+200);
		}
		if(p1.bp.size()>=p1.bp_level){
			c_r2("[AI] 背包已满!请先出售矿物!");
			Sleep(1000);
			continue;
		}
		int r=pick_ore();
		mineral m;
		m.m_level=r;
		m.m_name=m_namelist[r];
		m.mh_level=m_ha[r];
		m.weight=ran(1,2);
		m.purity=ran(60,100);
		sc(m_co[r]);
		c_r("[AI] 挖到了 ");
		cout<<m.m_name<<"x"<<m.weight<<endl;
		p1.bp.push_back(m);
		if(p1.man.dur!=inf){
			p1.man.dur-=1+2*m.mh_level;
		}
		if(p1.man.dur<0)p1.man.dur=0;
		Sleep(1000);
		sc(7);
	}
}

void save(){
	ofstream f("save.txt");
	if(!f)return;
	f<<p1.p_name<<endl;
	f<<p1.money<<endl;
	f<<p1.bp_level<<endl;
	f<<p1.man.ma_level<<endl;
	f<<p1.man.dur<<endl;
	f<<p1.bp.size()<<endl;
	for(auto&m:p1.bp){
		f<<m.m_level<<" "<<m.weight<<" "<<m.purity<<endl;
	}
	f.close();
	c_r2("游戏已自动保存!");
	Sleep(500);
}

bool has_save(){
	ifstream f("save.txt");
	return f.good();
}

void name_in(){
	cout<<"请输入你的名字:";
	cin>>p1.p_name;
	p1.p_name='['+p1.p_name+']';
	system("cls");
}

void start(){
	for(int i=1;i<=10;i++)cout<<endl;
	cout<<"                                           <=====<挖矿游戏>=====>\n";
	cout<<"                                           |   (发育小游戏)     |\n";
	cout<<"                                           |按 下 任 意 键 开 始|\n";
	cout<<"                                           <====================>";
	getch();
	system("cls");
}

void update_manu(int level){
	p1.man.ma_level=level;
	p1.man.dur=manu_dur[level];
	p1.man.eff=manu_ef[level];
	p1.man.ma_name=ma_namelist[level];
	p1.man.mah_level=manu_ha[level];
}

void update_player(){
	p1.bp_level=20;
	p1.money=inf;
	update_manu(0);
}

int pick_ore(){
	vector<int>ok;
	for(int i=0;i<9;i++){
		if(m_ha[i]<=p1.man.mah_level){
			ok.push_back(i);
		}
	}
	int sum=0;
	for(int i:ok)sum+=m_weight[i];
	int r=ran(1,sum);
	int cur=0;
	for(int i:ok){
		cur+=m_weight[i];
		if(r<=cur)return i;
	}
	return ok[0];
}

void load(){
	ifstream f("save.txt");
	if(!f)return;
	getline(f,p1.p_name);
	f>>p1.money;
	f>>p1.bp_level;
	int lv;
	f>>lv;
	update_manu(lv);
	f>>p1.man.dur;
	int sz;
	f>>sz;
	p1.bp.clear();
	for(int i=0;i<sz;i++){
		mineral m;
		f>>m.m_level;
		f>>m.weight;
		f>>m.purity;
		m.m_name=m_namelist[m.m_level];
		m.mh_level=m_ha[m.m_level];
		p1.bp.push_back(m);
	}
	f.close();
}

void show_p(){
	system("cls");
	cout<<"<=======<主菜单>=======>"<<endl;
	cout<<"名称:"<<p1.p_name<<endl;
	cout<<"$金币$:"<<p1.money<<endl;
	cout<<"工具:"<<p1.man.ma_name<<" 效率:"<<fixed<<setprecision(1)<<p1.man.eff<<" 耐久:"<<(p1.man.dur==inf?"无限":to_string(p1.man.dur))<<endl;
	cout<<"背包容量:"<<p1.bp_level<<endl;
	cout<<"背包已装:"<<p1.bp.size()<<"/"<<p1.bp_level<<endl;
	cout<<"<======================>"<<endl;
}

void show_bag(){
	system("cls");
	c_r2("<===<你的背包>===>");
	if(p1.bp.empty()){
		c_r2("背包空空如也...");
	}else{
		for(int i=0;i<p1.bp.size();i++){
			auto&m=p1.bp[i];
			sc(m_co[m.m_level]);
			cout<<i+1<<". "<<m.m_name<<" 纯度:"<<m.purity<<" 重量:"<<m.weight<<endl;
		}
	}
	sc(7);
	c_r2("\n按任意键返回...");
	_getch();
}

void sell_all(){
	if(p1.bp.empty()){
		c_r2("背包里没有矿物可以卖!");
		Sleep(800);
		return;
	}
	int total=0;
	for(auto&m:p1.bp){
		int price=m_pr[m.m_level]*m.weight*(m.purity/50.0);
		total+=price;
	}
	p1.money+=total;
	p1.bp.clear();
	c_r("卖出所有矿物,获得 $");
	cout<<total<<endl;
	Sleep(600);
}

void buy_man(){
	system("cls");
	c_r2("<===<商店>===>");
	cout<<"1.木稿(60$) 2.石稿(120$) 3.铜稿(180$)"<<endl;
	cout<<"4.铁稿(250$) 5.钻稿(600$) 6.合金稿(1200$)"<<endl;
	cout<<"7.背包升级+10格(200$)"<<endl;
	c_r("请选择: ");
	char ch=_getch();
	int lv=ch-'0';
	if(lv>=1&&lv<=6){
		if(p1.money>=cost[lv]){
			p1.money-=cost[lv];
			update_manu(lv);
			c_r2("购买成功!");
		}else{
			c_r2("金币不足!");
		}
	}
	else if(lv==7){
		if(p1.money>=200){
			p1.money-=200;
			p1.bp_level+=10;
			c_r2("背包升级成功!容量+10");
		}else{
			c_r2("金币不足!");
		}
	}
	else{
		c_r2("无效选择!");
	}
	Sleep(800);
}

void conversation(){
	string sn,an;
	system("cls");
	cout<<"<==AI聊天==>"<<endl;
	cout<<"|--out退出--|"<<endl;
	while(1){
		cout<<p1.p_name<<':';
		cin>>sn;
		if(sn=="out")return;
		cout<<"[AI]:";
		an=ranstr(ran(1,30));
		c_r3("大SB"+p1.p_name+an);
	}
	system("cls");
}

void main_dig(){
	show_p();
	if(p1.man.dur<=0){
		c_r2("你的工具坏了!先去买新的!");
		Sleep(1000);
		return;
	}
	c_r2("正在挖矿中...");
	int k=ran(1,10)*1000;
	for(int i=1;i<=int(k*p1.man.eff)/1000;i++){
		system("cls");
		show_p();
		cout<<"正在挖矿中..."<<endl;
		cout<<'[';
		for(int j=1;j<=i;j++)cout<<'\\';
		cout<<']'<<endl;
		Sleep(1000*p1.man.eff+200);
	}
	if(p1.bp.size()>=p1.bp_level){
		c_r2("背包已满!请先出售矿物!");
		Sleep(1000);
		return;
	}
	int r=pick_ore();
	mineral m;
	m.m_level=r;
	m.m_name=m_namelist[r];
	m.mh_level=m_ha[r];
	m.weight=ran(1,2);
	m.purity=ran(60,100);
	sc(m_co[r]);
	c_r("你挖到了 ");
	cout<<m.m_name<<"x"<<m.weight<<endl;
	p1.bp.push_back(m);
	if(p1.man.dur!=inf){
		p1.man.dur-=1+2*m.mh_level;
	}
	if(p1.man.dur<0)p1.man.dur=0;
	Sleep(1000);
	sc(7);
}

void menu(){
	show_p();
	c_r2("1.挖矿  2.背包  3.商店  4.出售  5.AI聊天  6.退出  7.AI挂机");
	c_r("选择:");
	char op=_getch();
	switch(op){
		case '1':main_dig();break;
		case '2':show_bag();break;
		case '3':buy_man();break;
		case '4':sell_all();break;
		case '5':conversation();break;
		case '6':save();exit(0);break;
		case '7':ai_auto_dig();break;
	}
}

int main(){
	if(has_save()){
		load();
		c_r2("读取存档成功!");
		Sleep(1000);
		system("cls");
	}
	start();
	if(!has_save()){
		name_in();
		update_player();
	}
	while(1)menu();
}
原文