骗子酒馆 c++ 代码(最终终极版)(New)

#include<bits/stdc++.h>
using namespace std;
	int ay,a1,a2,a3;
	int js=0;
	int yp,p1,p2,p3;
	char y[999];
	int vis[999];
	int visp[999];//这个位置有没有 
	int vist[999];//张数t 
	int vispt[999];
char sj(){
	int t=rand()%4;
	switch(t){
		case 0:return 'A';break;
		case 1:return 'J';break;
		case 2:return 'Q';break;
		case 3:return 'K';break;
	}
	return 'A';
}
	char flag;
void gl(int a,int b,int c,int d,char flag){
			system("cls");
			printf("You:(%d/6) CPU1:(%d/6) CPU2:(%d/6) CPU3:(%d/6)\n\n",a,b,c,d);
			if(flag!='A'&&flag!='J'&&flag!='Q'&&flag!='K')cout<<"错误警报!"; 
			cout<<flag;
			cout<<"的桌子"<<endl<<endl;
			cout<<"你的牌是:";
			for(int i=1;i<=5;i++){
				if(visp[i]==1){
					cout<<y[i]<<" ";
				}
			}
			cout<<endl<<endl;
}
int main(){
		ay=0,a1=0,a2=0,a3=0;
	while(1){
		yp=5,p1=5,p2=5,p3=5;
		for(int i=1;i<=5;i++)vis[i]=0,visp[i]=1,vist[i]=0;
		srand((int)time(0));
		flag=sj();
		for(int i=1;i<=5;i++){
			y[i]=sj();
			vis[y[i]]++;
			vist[y[i]]++;
		}
		js=0;
		cout<<ay<<a1<<a2<<a3; 
		while(js==0){
			gl(ay,a1,a2,a3,flag);
			int t=999;
			while(t>3){
				cout<<"请输出你要出牌的数量(最多三张):";
				cin>>t;
			}
			//cout<<"t:"<<t;
			int flaggg=-1;
			char tt[10];
			while(flaggg<0){//出牌 
				flaggg=-1;
				for(int i=1;i<=999;i++){
					vist[i]=vis[i];
				}
				for(int i=1;i<=5;i++){
					vispt[i]=visp[i];
				}
				cout<<"请出牌(空格间隔):";
				for(int i=1;i<=t;i++){
					cin>>tt[i];
				} 
				for(int i=1;i<=t;i++){
					if(vis[tt[i]]==0||vist[tt[i]]<1){
						if(flaggg==-1){
							cout<<"没有"<<tt[i];
							flaggg=-2;
						}
						else if(flaggg==-2){
							cout<<","<<tt[i];
						}
					}
					else{
						vist[tt[i]]--;
						int ffflag=0;
						for(int j=1;j<=5;j++){
							if(ffflag==1)continue;
							if(y[j]==tt[i]&&vispt[j]==1){
								vispt[j]=0;
								ffflag=1;
							}
						}
					}
				}
				if(flaggg<-1){
					cout<<"这张牌,请重新输入所有牌:"<<endl;
				}
				else{
					flaggg=999;
				}
			}
			/*for(int i=1;i<=5;i++){
				cout<<visp[i]<<" ";
			}cout<<endl;*/
			for(int i=1;i<=999;i++){
				vis[i]=vist[i];
			}
			for(int i=1;i<=5;i++){
				visp[i]=vispt[i];
			}
			cout<<"您已出牌:";
			int co=0;
			for(int i=1;i<=t;i++){
				cout<<tt[i]<<" ";
				if(tt[i]!=flag)co=1;
			} 
			cout<<endl;
			yp=yp-t;
			if(rand()%5==1||yp==0){
				cout<<"对方开了你的牌";
				if(co==1){
					switch(flag){
						case 'A':cout<<"你的牌不是A请开一枪(q):";break;
						case 'J':cout<<"你的牌不是J请开一枪(q):";break;
						case 'Q':cout<<"你的牌不是Q请开一枪(q):";break;
						case 'K':cout<<"你的牌不是K请开一枪(q):";break;
					}
					char kq;
					cin>>kq;
					if(rand()%6+1<=ay){
						cout<<"您已死亡,游戏结束";
						return 0; 
					}
					else{
						ay++;
						gl(ay,a1,a2,a3,flag);
						js=1;
						continue;
					}
				}
				else{
					if(rand()%6+1<=a1){
						cout<<"CPU1已死亡游戏结束";
						return 0;
					}
					else{
						cout<<"CPU1未中弹,游戏继续(任意英文字母):"; 
						a1++;
						char tg;
						cin>>tg;
						js=1;
						continue;
					}
				}
			}
			else{
				cout<<"对方没有开你的牌,游戏继续"<<endl;
			}
			
			int ttttt=rand()%3+1;if(p1-ttttt<0)ttttt=p1;p1=p1-ttttt;
			cout<<"CPU1出了"<<ttttt<<"张牌,他还剩"<<p1<<"张牌;"<<endl;;
			
			if(rand()%5+1==1||p1==0){
				cout<<"CPU2开了CPU1的牌,CPU1的牌全是"<<flag;
				if(rand()%6+1<=a2){
					cout<<"CPU2中弹了,游戏结束。";return 0;
				}
				else{
					cout<<"CPU2没有中弹,游戏继续(q):";
					char ttg;
					cin>>ttg;
					a2++;
					js=1;
					gl(ay,a1,a2,a3,flag);
					continue;
				}
			}
			else if(rand()%5+1==1){
				cout<<"CPU2开了CPU1的牌,CPU1的牌不全是"<<flag;
				if(rand()%6+1<=a1){
					cout<<"CPU1中弹了,游戏结束。";return 0;
				}
				else{
					cout<<"CPU1没有中弹,游戏继续(q):";
					char ttg;
					cin>>ttg;
					a1++;
					js=1;
					gl(ay,a1,a2,a3,flag);
					continue;
				}
			}
			else{
				ttttt=rand()%3+1;if(p2-ttttt<0)ttttt=p2;p2=p2-ttttt;
				cout<<"CPU2出了"<<ttttt<<"张牌,他还剩"<<p2<<"张牌;"<<endl;
			} 
			if(rand()%5+1==1||p2==0){
				cout<<"CPU3开了CPU2的牌,CPU2的牌全是"<<flag;
				if(rand()%6+1<=a3){
					cout<<"CPU3中弹了,游戏结束。";return 0;
				}
				else{
					cout<<"CPU3没有中弹,游戏继续(q):";
					char ttg;
					cin>>ttg;
					a3++;
					js=1;
					gl(ay,a1,a2,a3,flag);
					continue;
				}
			}
			else if(rand()%5+1==1){
				cout<<"CPU3开了CPU2的牌,CPU1的牌不全是"<<flag;
				if(rand()%6+1<=a1){
					cout<<"CPU2中弹了,游戏结束。";return 0;
				}
				else{
					cout<<"CPU2没有中弹,游戏继续(q):";
					char ttg;
					cin>>ttg;
					a2++;
					js=1;
					gl(ay,a1,a2,a3,flag);
					continue;
				}
			}
			else{
				ttttt=rand()%3+1;if(p3-ttttt<0)ttttt=p3;p3=p3-ttttt;
				cout<<"CPU3出了"<<ttttt<<"张牌,他还剩"<<p3<<"张牌;"<<endl;
			} 
			
			cout<<"您是否开您的上家的牌(y/n):";
			char tabc;
			cin>>tabc;
			if(tabc=='y'||p3==0){
				if(rand()%3==1){
					//switch(t):
					cout<<"您开了他的牌或他没有牌你自动开了,他的牌中不全是"<<flag<<endl<<endl;
					if(rand()%6+1<=a3){
						cout<<"CPU3已死亡游戏结束";
						return 0; 
					}
					else{
						cout<<"CPU3未中弹,游戏继续(任意英文字母):"; 
						a3++;
						char tg;
						cin>>tg;
						js=1;
					}
				}
				else{
					cout<<"您开了他的牌或他没有牌你自动开了,他的牌都是"<<flag<<",请开一枪(q):";
					char tg;
					cin>>tg;
					if(rand()%6+1<=ay){
						cout<<"您已死亡,游戏结束";
						return 0; 
					}
					else{
						cout<<"您未死亡,游戏继续(q):";
						cin>>tg;
						ay++;
						gl(ay,a1,a2,a3,flag);
						js=1;
						continue;
					}
				}
			}
			else{
				cout<<"游戏继续(任意英文字母):"<<endl; 
				char tg;
				cin>>tg;
			}
		}
	}
	return 0;
}
8 个赞

刚修复好了 bug,还有 bug 请在评论去说

2 个赞

@莫骐豪 又更新了一个,最终版的

2 个赞

okok

1 个赞

@徐熙喆 你身为管理员居然带头搞游戏代码!!!太好玩了,我也要玩 :smiling_face_with_tear:

2 个赞