游戏(暂未写完)单人可正常
  • 板块灌水区
  • 楼主kong_chen
  • 当前回复14
  • 已保存回复15
  • 发布时间2024/11/9 20:12
  • 上次更新2024/11/9 22:07:06
查看原帖
游戏(暂未写完)单人可正常
1054549
kong_chen楼主2024/11/9 20:12
#include<iostream>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<math.h>
#include<windows.h>
int game;
int jh2,syjh2=0,cs=1,jf2=100;
int a,b,c,jh,syjh=0,wp1=0,wp2=0,wp3=0,wp4=0,gmsp=0,jf=100,bya=0;
int wp1sj=0,wp2sj=0,wp4sj=0,wp5=0,wp5sj=0,wp6=0,wp6sj=0,wp7=0;
char ch;
using namespace std;
void beibao(){//单人查看你所拥有的物品
	cout<<"这是背包系统可查看你所拥有的东西"<<endl;
	if(wp1>0){
		cout<<"你拥有-所有数之和有"<<wp1<<endl;
	}
	if(wp2>0){
		cout<<"你拥有-是几位数"<<wp2<<endl;
	}
	if(wp3>0){
		cout<<"你拥有-告诉你个位数"<<wp3<<endl;
	}
	if(wp4>0){
		cout<<"你拥有-积分翻倍卡下次获得的积分*2 "<<wp4<<endl;
	}
	if(wp7>0){
		cout<<"你拥有-跳关卡,积分+2 "<<wp7<<endl;
	}
}
void chushou(){//单人出售你所拥有的商店物品
	cout<<"这里可以出售物品转化为出售积分给你"<<endl;
	cout<<"这是兑换表"<<endl;
	cout<<"所有数之和(3积分)(a)(1)"<<endl;
	cout<<"是几位数(2积分)(b)(2)"<<endl;
	cout<<"告诉你个位数(4积分)(c)(3)"<<endl;
	cout<<"积分翻倍卡下次获得的积分*2(五回合)(3积分)(d)(4)"<<endl;
	cout<<"跳关卡,积分+2(5积分)(i)(7)"<<endl;
	cout<<"输入Z可退出";
	cout<<"输入转积分的那张卡的英文字母";
	cout<<"清先输入要出售的物品的个数"<<endl;
	int csgs; 
	cin>>csgs;
	for(int i=0;i<csgs;i++){
			cout<<"你拥有这些"<<endl;
			if(wp1>0){
				cout<<"你拥有-所有数之和有"<<wp1<<endl;
			}
			if(wp2>0){
				cout<<"你拥有-是几位数"<<wp2<<endl;
			}
			if(wp3>0){
				cout<<"你拥有-告诉你个位数"<<wp3<<endl;
			}
			if(wp4>0){
				cout<<"你拥有-积分翻倍卡下次获得的积分*2 "<<wp4<<endl;
			}
			if(wp7>0){
				cout<<"你拥有-跳关卡,积分+2 "<<wp7<<endl;
			}
		char zfzm;
		cin>>zfzm;
		if(zfzm=='a'&&wp1>=1){
			wp1--;
			jf+=3;
			cout<<"已出售目前积分是"<<jf<<endl;
		}
		else if(zfzm=='a'&&wp1<=0){
			cout<<"你没有此物品无法转积分"<<endl;
			continue;
		}
		if(zfzm=='b'&&wp2>=1){
			wp2--;
			jf+=2;
			cout<<"已出售目前积分是"<<jf<<endl;
		}
		else if(zfzm=='b'&&wp2<=0){
			cout<<"你没有此物品无法转积分"<<endl;
			continue;
		}
		if(zfzm=='c'&&wp3>=1){
			wp3--;
			jf+=4;
			cout<<"已出售目前积分是"<<jf<<endl;
		}
		else if(zfzm=='c'&&wp1<=0){
			cout<<"你没有此物品无法转积分"<<endl;
			continue;
		}
		if(zfzm=='d'&&wp1>=1){
			wp4--;
			jf+=3;
			cout<<"已出售目前积分是"<<jf<<endl;
		}
		else if(zfzm=='d'&&wp1<=0){
			cout<<"你没有此物品无法转积分"<<endl;
			continue;
		}
		if(zfzm=='i'&&wp7>=1){
			wp7--;
			jf+=5;
			cout<<"已出售目前积分是"<<jf<<endl;
		}
		else if(zfzm=='i'&&wp7<=0){
			cout<<"你没有此物品无法转积分"<<endl;
			continue;
		}
		if(zfzm=='Z'){
			cout<<"已结束"<<endl;
			return;
		}
	}
}
void choujiangtai(){//单人抽奖台抽商店出售物品
	cout<<"这是一个抽奖台可以抽出商店里的所有物品(积分增减除外)"<<endl<<"而且只需1积分1积分1积分!!!!!!";
	int cjsj;
	cout<<"快来抢购吧!!(请输入(1不)(2要))";
	int sfcj;
	cin>>sfcj;
	if(sfcj==1){
		return;
	}
	if(sfcj==2){
		cout<<"几连抽(最少为1,最多为100)";
		int cjcs;
		cin>>cjcs;
		for(int i=0;i<cjcs;i++){
			jf--;	
			cjsj=rand()%(6-1+1)+1;
			if(cjsj==1){
				wp1++;
				cout<<"你抽到的是:所有数之和-价值3积分"<<endl;
			}
			if(cjsj==2){
				wp2++;
				cout<<"你抽到的是:是几位数-价值2积分"<<endl;
			}
			if(cjsj==3){
				wp3++;
				cout<<"你抽到的是:告诉你个位数-价值4积分"<<endl;
			}
			if(cjsj==4){
				wp4+=5;
				cout<<"你抽到的是:积分翻倍卡下次获得的积分*2(五回合)-价值3积分"<<endl;
			}
			if(cjsj==5){
				wp7++;
				cout<<"你抽到的是:跳关卡,积分+2-价值5积分";
			}
			if(cjsj==6){
				cout<<"再接再厉啥也没有抽到"<<endl;
			}
		}
	}
}
void shangdian(){//单人猜数商店用积分兑换
	cout<<"所有数之和(3积分)(a)(1)"<<endl;
	cout<<"是几位数(2积分)(b)(2)"<<endl;
	cout<<"告诉你个位数(4积分)(c)(3)"<<endl;
	cout<<"积分翻倍卡下次获得的积分*2(五回合)(3积分)(d)(4)"<<endl;
	cout<<"跳关卡,积分+2(5积分)(i)(7)"<<endl;
	cout<<"积分+1~100(10积分)(e)"<<endl;
	cout<<"积分-100~+200(20积分)(f)"<<endl;
	cout<<"积分-500~+1000(100积分)(g)"<<endl;
	cout<<"积分-1000~-10000(0积分)(h)"<<endl;
	cout<<"请先输入购买物品数量"<<endl;
	cin>>gmsp;
	for(int i=0;i<gmsp;i++){
		if(gmsp==0){
			cout<<"好的已退出";
			break;
		}
		cout<<"输入你要购买的商品字符";
		cin>>ch;
		if(ch=='a'){
			if(jf>=3){
				jf-=3;
				wp1++;
				cout<<"已购买,play时输入下限-1即可使用";
			}
			else{
				cout<<"钱不足无法购买"<<endl;
			}
		}
		if(ch=='b'){
			if(jf>=2){
				jf-=2;
				wp2++;
				cout<<"已购买,play时下限-2即可使用";
			}
			else{
				cout<<"钱不足无法购买"<<endl;
			}
		}
		if(ch=='c'){
			if(jf>=4){
				jf-=4;
				wp3++;
				cout<<"已购买,play时下限-3即可使用";
			}
			else{
				cout<<"钱不足无法购买"<<endl;
			}
		}
		if(ch=='d'){
			if(jf>=3){
				jf-=3;
				wp4=5;
				cout<<"已购买,下个回合猜对时默认使用"<<endl;
			}
			else{
				cout<<"钱不足无法购买"<<endl;
			}
		}
		if(ch=='e'){
			if(jf>=10){
				jf-=10;
				wp5=1;
				cout<<"已使用"<<endl;
				wp5sj=rand()%(100-1+1)+1;
				cout<<"你抽到了"<<wp5sj<<endl;
				jf+=wp5sj;
				cout<<"你现在的积分是"<<jf<<endl;
				wp5=0;
			}
			else{
				cout<<"钱不足无法购买"<<endl;
			}
		}
		if(ch=='f'){
			if(jf>=0){
				jf-=0;
				wp6=1;
				cout<<"已使用"<<endl;
				wp6sj=rand()%(300-1+1)+1;
				if(wp6sj>200){
					cout<<"你抽到的是"<<wp6sj-300;
					jf=jf+wp6sj-300;
				}
				else{
					cout<<"你抽到的是"<<wp6sj;
					jf=jf+wp6sj;
				}
				cout<<"你现在的积分是"<<jf<<endl;
				wp6=0;
			}
			else{
				cout<<"钱不足无法购买"<<endl;
			}
		}
		if(ch=='g'){
			if(jf>=100){
				jf-=100;
				wp6=1;
				cout<<"已使用"<<endl;
				wp6sj=rand()%(1500-1+1)+1;
				if(wp6sj<=1000){
					cout<<"你抽到的是"<<wp6sj<<endl;
					jf+=wp6sj;
				}
				if(wp6sj>1000){
					cout<<"你抽到的是"<<wp6sj-1500;
					jf=jf+wp6sj-1500;
				}
				cout<<"你现在的积分是"<<jf<<endl;
				wp6=0;
			}
			else{
				cout<<"钱不足无法购买"<<endl;
			}
		}
		if(ch=='h'){
			if(jf>=0){
				jf-=0;
				cout<<"已使用"<<endl;
				wp6sj=rand()%(10000-1000+1)+1;
				cout<<"你抽到"<<wp6sj<<endl;
				jf=jf-wp6sj;
				cout<<"你现在的积分是"<<jf<<endl;
				wp6=0;
			}
			else{
				cout<<"钱不足无法购买"<<endl;
			}
		}
		if(ch=='i'){
			if(jf>=5){
				jf-=5;
				cout<<"购买成功,下回合下限-4使用"<<endl;
				wp7++;	
			}
			else{
				cout<<"钱不足无法购买"<<endl;
			}	
		}
	}
}
void caishu(){//单人猜数主程序
	int sr,ggsr;
	cout<<"机会";
	cin>>jh;
	for(;;){
		cin>>sr;
		syjh++;
		if(wp1>=1&&sr==(b-1)){ 
		wp1sj=0; 
		bya=c;
		while(bya>0){
			wp1sj+=bya%10;
			bya=bya/10;
		}
		cout<<"总和是"<<wp1sj<<endl;
			wp1=wp1-1;
		}
		if(wp2>=1&&sr==(b-2)){
			wp2sj=0;
			bya=c;
			while(bya>0){
				bya=bya/10;
				wp2sj++;
			}
			cout<<"位数为"<<wp2sj<<endl;
			wp2=wp2-1;
		}
		if(wp3>=1&&sr==(b-3)){
			bya=c;
			cout<<"个位上是"<<bya%10<<endl;
			wp3=wp3-1;
		}
		if(wp7>=1&&sr==(b-4)){
			jf+=2;
			wp7--;
			cout<<"先输入上限再输入下限";
			cin>>a>>b;
			c=rand()%(a-b+1)+b;
			cout<<"输入机会";
			cin>>jh;
			syjh=0;
			continue;		
		}
		if(sr==c){
			if(wp4>=1){
				jf+=3;
				wp4--;
			}
			else{
				jf++;
			}
			cout<<"对";
			cout<<"现在积分是"<<jf;
			cout<<"是否继续(0结束,1继续,2召唤商店,3召唤抽奖台,4出售物品,5查看背包)";
			cin>>ggsr;
			if(ggsr==0){
				cout<<"游戏结束";
				break;
			}
			if(ggsr==1){
				cout<<"先输入限再输入上限";
				cin>>a>>b;
				c=rand()%(a-b+1)+b;
				cout<<"输入机会";
				cin>>jh;
				syjh=0;
				continue;
			}
			if(ggsr==2){
				shangdian();
				cout<<"先输入上限再输入下限";
				cin>>a>>b;
				c=rand()%(a-b+1)+b;
				cout<<"输入机会";
				cin>>jh;
				syjh=0;
				continue;
			}
			if(ggsr==3){
				choujiangtai();
				cout<<"先输入上限再输入下限";
				cin>>a>>b;
				c=rand()%(a-b+1)+b;
				cout<<"输入机会";
				cin>>jh;
				syjh=0;
				continue;
			}
			if(ggsr==4){
				chushou();
				cout<<"先输入上限再输入下限";
				cin>>a>>b;
				c=rand()%(a-b+1)+b;
				cout<<"输入机会";
				cin>>jh;
				syjh=0;
				continue;
			}
			if(ggsr==5){
				beibao();
				cout<<"先输入上限再输入下限";
				cin>>a>>b;
				c=rand()%(b-a+1)+a;
				cout<<"输入机会";
				cin>>jh;
				syjh=0;
				continue;				
			}
		}
		if(syjh==jh){
			cout<<"机会用完";
			cout<<endl<<"答案是"<<c<<endl;
			cout<<"是否继续(0结束,1继续,2召唤商店,3召唤抽奖台,4出售物品,5查看背包)";
			cin>>ggsr;
			if(ggsr==0){
				cout<<"游戏结束";
				break;
			}
			if(ggsr==1){
				cout<<"先输入上限再输入下限";
				cin>>a>>b;
				c=rand()%(a-b+1)+b;
				cout<<"输入机会";
				cin>>jh;
				syjh=0;
				continue;
			}
			if(ggsr==2){
				shangdian();
				cout<<"先输入上限再输入下限";
				cin>>a>>b;
				c=rand()%(a-b+1)+b;
				cout<<"输入机会";
				cin>>jh;
				syjh=0;
				continue;
			}
			if(ggsr==3){
				choujiangtai();
				cout<<"先输入上限再输入下限";
				cin>>a>>b;
				c=rand()%(a-b+1)+b;
				cout<<"输入机会";
				cin>>jh;
				syjh=0;
				continue;
			}
			if(ggsr==4){
				chushou();
				cout<<"先输入上限再输入下限";
				cin>>a>>b;
				c=rand()%(a-b+1)+b;
				cout<<"输入机会";
				cin>>jh;
				syjh=0;
				continue;
			}
			if(ggsr==5){
				beibao();
				cout<<"先输入上限再输入下限";
				cin>>a>>b;
				c=rand()%(b-a+1)+a;
				cout<<"输入机会";
				cin>>jh;
				syjh=0;
				continue;				
			}
		}
		if(sr>c){
			cout<<"大"<<endl<<"这是第"<<syjh<<"机会"<<"剩下"<<jh-syjh<<"次机会";
		}	
		if(sr<c){
			cout<<"小"<<endl<<"这是第"<<syjh<<"机会"<<"剩下"<<jh-syjh<<"次机会";
		}		
	}
}
void caishu2(){//双人猜数主程序
	int sr,ggsr;
	cout<<"A机会";
	cin>>jh;
	cout<<"B机会";
	cin>>jh2;
	cout<<"先A后B"; 
	for(;;){
		cin>>sr;
		if(cs%2==0){
			cs++;
			syjh++;
		}
		else{
			cs++;
			syjh2++;
		}
		if(wp1>=1&&sr==(b-1)){ 
		wp1sj=0; 
		bya=c;
		while(bya>0){
			wp1sj+=bya%10;
			bya=bya/10;
		}
		cout<<"总和是"<<wp1sj<<endl;
			wp1=wp1-1;
		}
		if(wp2>=1&&sr==(b-2)){
			wp2sj=0;
			bya=c;
			while(bya>0){
				bya=bya/10;
				wp2sj++;
			}
			cout<<"位数为"<<wp2sj<<endl;
			wp2=wp2-1;
		}
		if(wp3>=1&&sr==(b-3)){
			bya=c;
			cout<<"个位上是"<<bya%10<<endl;
			wp3=wp3-1;
		}
		if(wp7>=1&&sr==(b-4)){
			jf+=2;
			wp7--;
			cout<<"先输入上限再输入下限";
			cin>>a>>b;
			c=rand()%(a-b+1)+b;
			cout<<"输入机会";
			cin>>jh;
			syjh=0;
			continue;		
		}
		if(sr==c){
			if(wp4>=1){
				jf+=3;
				wp4--;
			}
			if(cs%2==0){
				cout<<"A对";
				jf++;
				cout<<"A现在积分是"<<jf;				
			}
			else{
				cout<<"B对";
				jf2++;
				cout<<"现在积分是"<<jf;			
			}
			cout<<"是否继续(0结束,1继续,2召唤商店,3召唤抽奖台,4出售物品,5查看背包)";
			cin>>ggsr;
			if(ggsr==0){
				cout<<"游戏结束";
				break;
			}
			if(ggsr==1){
				cout<<"先输入限再输入上限";
				cin>>a>>b;
				c=rand()%(a-b+1)+b;
				cout<<"输入机会";
				cin>>jh;
				syjh=0;
				continue;
			}
			if(ggsr==2){
				shangdian();
				cout<<"先输入上限再输入下限";
				cin>>a>>b;
				c=rand()%(a-b+1)+b;
				cout<<"输入机会";
				cin>>jh;
				syjh=0;
				continue;
			}
			if(ggsr==3){
				choujiangtai();
				cout<<"先输入上限再输入下限";
				cin>>a>>b;
				c=rand()%(a-b+1)+b;
				cout<<"输入机会";
				cin>>jh;
				syjh=0;
				continue;
			}
			if(ggsr==4){
				chushou();
				cout<<"先输入上限再输入下限";
				cin>>a>>b;
				c=rand()%(a-b+1)+b;
				cout<<"输入机会";
				cin>>jh;
				syjh=0;
				continue;
			}
			if(ggsr==5){
				beibao();
				cout<<"先输入上限再输入下限";
				cin>>a>>b;
				c=rand()%(b-a+1)+a;
				cout<<"输入机会";
				cin>>jh;
				syjh=0;
				continue;				
			}
		}
		if((syjh==jh||syjh>jh)&&(syjh2==jh2||syjh2>jh2)){
			cout<<"机会用完";
			cout<<endl<<"答案是"<<c<<endl;
			cout<<"是否继续(0结束,1继续,2召唤商店,3召唤抽奖台,4出售物品,5查看背包)";
			cin>>ggsr;
			if(ggsr==0){
				cout<<"游戏结束";
				break;
			}
			if(ggsr==1){
				cout<<"先输入上限再输入下限";
				cin>>a>>b;
				c=rand()%(a-b+1)+b;
				cout<<"输入机会";
				cin>>jh;
				syjh=0;
				continue;
			}
			if(ggsr==2){
				shangdian();
				cout<<"先输入上限再输入下限";
				cin>>a>>b;
				c=rand()%(a-b+1)+b;
				cout<<"输入机会";
				cin>>jh;
				syjh=0;
				continue;
			}
			if(ggsr==3){
				choujiangtai();
				cout<<"先输入上限再输入下限";
				cin>>a>>b;
				c=rand()%(a-b+1)+b;
				cout<<"输入机会";
				cin>>jh;
				syjh=0;
				continue;
			}
			if(ggsr==4){
				chushou();
				cout<<"先输入上限再输入下限";
				cin>>a>>b;
				c=rand()%(a-b+1)+b;
				cout<<"输入机会";
				cin>>jh;
				syjh=0;
				continue;
			}
			if(ggsr==5){
				beibao();
				cout<<"先输入上限再输入下限";
				cin>>a>>b;
				c=rand()%(b-a+1)+a;
				cout<<"输入机会";
				cin>>jh;
				syjh=0;
				continue;				
			}
		}
		if(sr>c){
			if(jh%2==0){
				cout<<"A回答大"<<endl<<"这是第"<<syjh<<"机会"<<"剩下"<<jh-syjh<<"次机会";				
			}
			else{
				cout<<"B回答大"<<endl<<"这是第"<<syjh2<<"机会"<<"剩下"<<jh2-syjh2<<"次机会"	;	
			}

		}	
		if(sr<c){
			if(jh%2==0){
				cout<<"A回答小"<<endl<<"这是第"<<syjh<<"机会"<<"剩下"<<jh-syjh<<"次机会";				
			}
			else{
				cout<<"B回答小"<<endl<<"这是第"<<syjh2<<"机会"<<"剩下"<<jh2-syjh2<<"次机会";		
			}
			
		}		
	}
}
int main(){
	cout<<"请问是单人游戏/双人游戏"<<endl; 
	cout<<"单人输入1,双人输入2"<<endl; 
	cin>>game;
	if(game==1){
		cout<<"好的,已经为你切换为单人游戏"<<endl;
		cout<<"先输入上限再输入下限";//开始的输入
		cin>>a>>b;
		srand(time(0));
		c=rand()%(a-b+1)+b;
		caishu();//单人主程序的开端
	}
	if(game==2){
		cout<<"好的,已经为你切换为双人游戏"; 
		cout<<"请A输入上限";//开始的输入
		cin>>a;
		cout<<"请B输入下限";
		cin>>b; 
		srand(time(0));
		c=rand()%(a-b+1)+b;
		caishu2();//双人主程序的开端
	} 
	return 0;
}

2024/11/9 20:12
加载中...