跳到正文

个人记录

三角洲摸金模拟器(可存档)

WJX114514约 10 分钟
原文

这是 2025年12月25日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

收录
2025年12月12日
更新
2026年1月4日
篇幅
约 10 分钟

版本

  1. v2当前
  2. v1
C++
#include<bits/stdc++.h>
#include<windows.h>
#include <fstream>
#include<conio.h>
using namespace std;
struct thing{
	string name;
	int money,big,color;
};
int cmp(thing a,thing b){
	if(a.color==b.color) return a.name<=b.name;
	else return a.color<b.color;
}
int yyckgz=0;
vector<thing> v,ck;
int gl_bx[100];//概率数组(大保险),红(0)5%,金(1)10%,紫(2)35%,蓝(3)50%
thing bx_red[9],bx_gold[2],bx_pur[4],bx_blue[3];
void newbx(){
	for(int i=0;i<=9;i++) gl_bx[i]=1;
	for(int i=10;i<=44;i++) gl_bx[i]=2;
	for(int i=45;i<=49;i++) gl_bx[i]=0;
	for(int i=50;i<=99;i++) gl_bx[i]=3;
	//红 
	bx_red[0].name="非洲之心"; bx_red[0].money=13141314; bx_red[0].big=1; bx_red[0].color=0;
	bx_red[1].name="主战坦克模型"; bx_red[1].money=2000000; bx_red[1].big=9; bx_red[1].color=0;
	bx_red[2].name="滑膛枪"; bx_red[2].money=600000; bx_red[2].big=4; bx_red[2].color=0;
	bx_red[3].name="名贵机械表"; bx_red[3].money=350000; bx_red[3].big=1; bx_red[3].color=0;
	bx_red[4].name="怀表"; bx_red[4].money=200000; bx_red[4].big=1; bx_red[4].color=0;
	bx_red[5].name="化石"; bx_red[5].money=300000; bx_red[5].big=2; bx_red[5].color=0;
	bx_red[6].name="金条"; bx_red[6].money=330000; bx_red[6].big=2; bx_red[6].color=0;
	bx_red[7].name="半身人像"; bx_red[7].money=2100000; bx_red[7].big=3; bx_red[7].color=0;
	bx_red[8].name="步战车模型"; bx_red[8].money=1600000; bx_red[8].big=6; bx_red[8].color=0;
	//金 
	bx_gold[0].name="金币"; bx_gold[0].money=60000; bx_gold[0].big=1; bx_gold[0].color=1;
	bx_gold[1].name="金杯"; bx_gold[1].money=50000; bx_gold[1].big=1; bx_gold[1].color=1;
	//紫 
	bx_pur[0].name="典仪匕首"; bx_pur[0].money=100000; bx_pur[0].big=6; bx_pur[0].color=2;
	bx_pur[1].name="牛角"; bx_pur[1].money=20000; bx_pur[1].big=2; bx_pur[1].color=2;
	bx_pur[2].name="水壶"; bx_pur[2].money=20000; bx_pur[2].big=2; bx_pur[2].color=2;
	bx_pur[3].name="黄金肩章"; bx_pur[3].money=20000; bx_pur[3].big=2; bx_pur[3].color=2;
	//蓝
	bx_blue[0].name="海盗望远镜"; bx_blue[0].money=15000; bx_blue[0].big=2; bx_blue[0].color=3;
	bx_blue[1].name="起舞的兔女郎"; bx_blue[1].money=15000; bx_blue[1].big=2; bx_blue[1].color=3;
	bx_blue[2].name="银币"; bx_blue[2].money=10000; bx_blue[2].big=1; bx_blue[2].color=3;
}
void sjwp(){
	int x=rand()%100;
	if(gl_bx[x]==0){
		v.push_back(bx_red[rand()%9]);
	}else if(gl_bx[x]==1){
		v.push_back(bx_gold[rand()%2]);
	}else if(gl_bx[x]==2){
		v.push_back(bx_pur[rand()%4]);
	}else{
		v.push_back(bx_blue[rand()%3]);
	}
}
void bx_have(){
	system("cls");
	v.erase(v.begin(),v.end());
	int x=rand()%4+1;
	for(int i=1;i<=x;i++){
		sjwp();
	}
	for(int i=0;i<x;i++){
		cout<<v[i].big<<"格 ";
		//搜索时间 
		if(v[i].color==0) Sleep(2500);
		else if(v[i].color==1) Sleep(2000);
		else if(v[i].color==2) Sleep(1500);
		else Sleep(1000);
		//更改字体颜色 
		if(v[i].color==0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x04);
		else if(v[i].color==1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x0E);
		else if(v[i].color==2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x0D);
		else SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x09);
		cout<<v[i].name;
		//调回白色 
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x07);
		cout<<" 市场估价:"<<v[i].money<<endl;
	}
	cout<<"请输入你要拾取的编号:";
	string s; cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]>='0'&&s[i]<='9') ck.push_back(v[s[i]-'0'-1]);
	}
	return;
}
void open_ck(){
	system("cls");
	long long ckjz=0;
	sort(ck.begin(),ck.end(),cmp);
	for(int i=0;i<ck.size();i++){
		if(ck[i].color==0) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x04);
		else if(ck[i].color==1) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x0E);
		else if(ck[i].color==2) SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x0D);
		else SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x09);
		cout<<ck[i].name<<endl;
		ckjz+=ck[i].money;
		//调回白色 
		SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),0x07);
	}
	cout<<"仓库价值:"<<ckjz<<endl;
	cout<<"按下任意键返回";
	_getch();
	return;
}
void jiazai(){
	system("cls");
	int xx;
	ifstream infile("sjzmnq.txt");
	if(!infile.is_open()){
		return;
	}
	infile>>xx;
	for(int i=0;i<xx;i++){
		string name; int color,money,big;
		infile>>name>>color>>money>>big;
		thing aa; aa.big=big; aa.color=color; aa.money=money; aa.name=name;
		ck.push_back(aa);
	}
	infile.close();
}
void baocun(){
	system("cls");
	ofstream infile("sjzmnq.txt");
	if(!infile.is_open()){
		return;
	}
	infile<<ck.size()<<endl;
	for(int i=0;i<ck.size();i++){
		infile<<ck[i].name<<" "<<ck[i].color<<" "<<ck[i].money<<" "<<ck[i].big<<endl;
	}
	infile.close();
}
void zhujiemian(){
	system("cls");
	cout<<"1.开启保险箱"<<endl;
	cout<<"2.仓库"<<endl;
	char a; while(a<'0'||a>'9') a=_getch();
	if(a=='1'){
		bx_have();
		baocun();
	}else{
		open_ck();
	}
	zhujiemian();
}
int main(){
	srand(time(0));
	jiazai();
	newbx();
	zhujiemian();
	return 0;
}