骗子酒馆
liweihang_OvO_ · · 休闲·娱乐
以下是“骗子酒馆”游戏的c++程序,欢迎游玩:
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int tt[15];
int c1[105],c2[105],c3[105],c4[105],fff=1;
string s=" JQKA";
int r1,r2,r3,r4,R1,R2,R3,R4;
char ssss;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
int RANDD(int i){
cout<<"开枪中..."<<endl;
Sleep(2500);
if(i==1){
r1++;
if(r1==R1){
cout<<"你死了,游戏结束";
return 1;
}
else{
cout<<"你:"<<r1<<"/10"<<endl;
}
}
if(i==2){
r2++;
if(r2==R2){
cout<<"玩家二死了,游戏结束";
return 1;
}
else{
cout<<"玩家二:"<<r2<<"/10"<<endl;
}
}
if(i==3){
r3++;
if(r3==R3){
cout<<"玩家三死了,游戏结束";
return 1;
}
else{
cout<<"玩家三:"<<r3<<"/10"<<endl;
}
}
if(i==4){
r4++;
if(r4==R4){
cout<<"玩家四死了,游戏结束";
return 1;
}
else{
cout<<"玩家四:"<<r4<<"/10"<<endl;
}
}
}
int AI1(int cnt,string s1,char ch,int i){
bool f=0;
int ii=i-1;
if(ii==0){
ii=4;
}
cout<<"Lair!!!"<<endl<<endl<<s1<<endl<<endl;
for(int j=0;j<s1.size();j++){
if(s1[j]!=ch&&s1[j]!='J'){
f=1;
break;
}
}
if(f){
if(i==1){
cout<<"你"<<"开赢了"<<" ";
}
else{
cout<<"玩家"<<i<<"开赢了"<<" ";
}
cout<<endl<<endl;
if(i==2){
cout<<"你将要开枪"<<endl;
Sleep(1500);
return 1+RANDD(1);
}
else{
cout<<"玩家"<<ii<<"将要开枪"<<endl<<endl;
Sleep(1500);
return 1+RANDD(ii);
}
}
else{
if(i==1){
cout<<"你"<<"开输了"<<" ";
}
else{
cout<<"玩家"<<i<<"开输了"<<" ";
}
cout<<endl<<endl;
if(i==1){
cout<<"你将要开枪"<<endl<<endl;
Sleep(1500);
return 1+RANDD(i);
}
cout<<"玩家"<<i<<"将要开枪"<<endl<<endl;
Sleep(1500);
return 1+RANDD(i);
}
}
int AI(string s1,char ch){
int cnt=0;
for(int i=2;i<=4;i++){
cout<<"玩家"<<i<<":";
int x=rand()%30+1;
bool f=0;
if(s1.size()==1&&x<=4){
return AI1(cnt,s1,ch,i);
}
else if((x==1&&cnt==1)){
return AI1(cnt,s1,ch,i);
}
else if(((x==2||x==3)&&cnt==2)){
return AI1(cnt,s1,ch,i);
}
else if((x<=10)){
return AI1(cnt,s1,ch,i);
}
else if(s1.size()==3&&x<=18&&x>=3){
return AI1(cnt,s1,ch,i);
}
else if(s1.size()==3&&x<=8&&cnt<3){
return AI1(cnt,s1,ch,i);
}
else{
int yy=rand()%3+1;
s1.clear();
for(int j=0;j<yy;j++){
int xx=rand()%4+1;
if(i==2){
while(c2[xx]==0){
xx=rand()%4+1;
}
if(c2[s.find(ssss)]!=0){
int xxxx=rand()%2;
if(xxxx==1){
xx=s.find(ssss);
}
}
s1+=s[xx];
c2[xx]--;
}
if(i==3){
while(c3[xx]==0){
xx=rand()%4+1;
}
if(c2[s.find(ssss)]!=0){
int xxxx=rand()%2;
if(xxxx==1){
xx=s.find(ssss);
}
}
s1+=s[xx];
c3[xx]--;
}
if(i==4){
while(c4[xx]==0){
xx=rand()%4+1;
}
if(c2[s.find(ssss)]!=0){
int xxxx=rand()%2;
if(xxxx==1){
xx=s.find(ssss);
}
}
s1+=s[xx];
c4[xx]--;
}
} cout<<yy<<"张"<<ch<<endl;
Sleep(2000);
cnt++;
}
}cout<<"你是否要开玩家四?(T/F)";
char ccc;
cin>>ccc;
if(ccc=='T'){
return AI1(cnt,s1,ch,1);
}
return 0;
}
int main(){
srand((unsigned int)time(nullptr));
R1=(rand()%10)+1;
R2=(rand()%10)+1;
R3=(rand()%10)+1;
R4=(rand()%10)+1;
cout<<R1<<" "<<R2<<" "<<R3<<" "<<R4<<endl;
SetConsoleTextAttribute(hConsole, 14);
cout<<"****** * "<<" "<<" ********* "<<" "<<"* ***** "<<" "<<" * * "<<endl;
cout<<" * ******** "<<" "<<" * "<<" "<<" * * * "<<" "<<" ****** * "<<endl;
cout<<"* * * * "<<" "<<" * "<<" "<<" ********* "<<" "<<"* * * ********"<<endl;
cout<<"* * ******** "<<" "<<" * "<<" "<<"* * * * * "<<" "<<" * * **** * "<<endl;
cout<<"****** * "<<" "<<"*************"<<" "<<" * * * * * "<<" "<<" * **** "<<endl;
cout<<" * * * * * * "<<" "<<" * "<<" "<<" * ** *** "<<" "<<" * * "<<endl;
cout<<"****** * * *** * "<<" "<<" * "<<" "<<" * * ***** * "<<" "<<" * ***** "<<endl;
cout<<" * * * *** * "<<" "<<" * * "<<" "<<" * * *"<<" "<<" * * * * "<<endl;
cout<<" * * * * "<<" "<<" * "<<" "<<"* ********* "<<" "<<" * ***** "<<endl;
Sleep(2000);
cout<<endl<<endl<<endl<<endl<<endl;
SetConsoleTextAttribute(hConsole, 7);
cout<<"游戏开始";
Sleep(2000);
cout<<endl<<endl;
int i=1;
while(1){
if(fff){
cout<<endl<<"第"<<i<<"轮"<<endl<<endl;
memset(tt,0,sizeof(tt));
memset(c1,0,sizeof(c1));
memset(c2,0,sizeof(c2));
memset(c3,0,sizeof(c3));
memset(c4,0,sizeof(c4));
while(c1[1]+c1[2]+c1[3]+c1[4]<5){
int x=rand()%4+1;
if(x!=1&&tt[x]<6){
c1[x]++;
tt[x]++;
}
else if(x==1&&tt[x]<2){
c1[x]++;
tt[x]++;
}
}
while(c2[1]+c2[2]+c2[3]+c2[4]<5){
int x=rand()%4+1;
if(x!=1&&tt[x]<6){
c2[x]++;
tt[x]++;
}
else if(x==1&&tt[x]<2){
c2[x]++;
tt[x]++;
}
}
while(c3[1]+c3[2]+c3[3]+c3[4]<5){
int x=rand()%4+1;
if(x!=1&&tt[x]<6){
c3[x]++;
tt[x]++;
}
else if(x==1&&tt[x]<2){
c3[x]++;
tt[x]++;
}
}
while(c4[1]+c4[2]+c4[3]+c4[4]<5){
int x=rand()%4+1;
if(x!=1&&tt[x]<6){
c4[x]++;
tt[x]++;
}
else if(x==1&&tt[x]<2){
c4[x]++;
tt[x]++;
}
}int xx=rand()%4+1;
while(xx==1){
xx=rand()%4+1;
}
ssss=s[xx];
cout<<"本轮赌牌:"<<s[xx]<<endl<<endl;
}
Sleep(1500);
cout<<"你的牌:";
for(int i=1;i<=4;i++){
for(int j=1;j<=c1[i];j++){
cout<<s[i]<<" ";
}
}
Sleep(1000);
string s1;
cout<<endl<<"请选择你要出的牌:"<<endl;
cin>>s1;
bool ff=0;
int cc[105];
memset(cc,0,sizeof(cc));
if(s1.size()>3){
SetConsoleTextAttribute(hConsole, 12); // 红色
cout<<"数量过多,请出1~3张" <<endl;
SetConsoleTextAttribute(hConsole, 7);
ff=1;
}
for(int i=0;i<s1.size();i++){
cc[s.find(s1[i])]++;
if(c1[s.find(s1[i])]==0||cc[s.find(s1[i])]>c1[s.find(s1[i])]){
SetConsoleTextAttribute(hConsole, 12); // 红色
cout<<"牌数错误" <<endl;
SetConsoleTextAttribute(hConsole, 7);
ff=1;
break;
}
}
while(ff==1){
memset(cc,0,sizeof(cc));
cin>>s1;
ff=0;
if(s1.size()>3){
SetConsoleTextAttribute(hConsole, 12); // 红色
cout<<"数量过多,请出1~3张" <<endl;
SetConsoleTextAttribute(hConsole, 7);
ff=1;
}
for(int i=0;i<s1.size();i++){
if(c1[s.find(s1[i])]==0||cc[s.find(s1[i])]>c1[s.find(s1[i])]){
SetConsoleTextAttribute(hConsole, 12); // 红色
cout<<"牌数错误" <<endl;
SetConsoleTextAttribute(hConsole, 7);
ff=1;
break;
}
cc[s.find(s1[i])]++;
}
}
for(int i=0;i<s1.size();i++){
c1[s.find(s1[i])]--;
}
if(ff==0){
cout<<"你:"<<s1.size()<<"张"<<ssss<<endl<<endl;
}
bool f1f=0;
int f2f=AI(s1,ssss);
if(f2f==2){
return 0;
}
if(c1[1]==c1[2]&&c1[2]==c1[3]&&c1[3]==c1[4]&&c1[4]==0){
f1f=1;
SetConsoleTextAttribute(hConsole, 12); // 红色
cout<<"有一人所持牌数为0,将重新发牌" <<endl;
SetConsoleTextAttribute(hConsole, 7);
}
else if(c2[1]==c1[2]&&c2[2]==c2[3]&&c2[3]==c2[4]&&c2[4]==0){
f1f=1;
SetConsoleTextAttribute(hConsole, 12); // 红色
cout<<"有一人所持牌数为0,将重新发牌" <<endl;
SetConsoleTextAttribute(hConsole, 7);
}
else if(c3[1]==c3[2]&&c3[2]==c3[3]&&c3[3]==c3[4]&&c3[4]==0){
f1f=1;
SetConsoleTextAttribute(hConsole, 12); // 红色
cout<<"有一人所持牌数为0,将重新发牌" <<endl;
SetConsoleTextAttribute(hConsole, 7);
}
else if(c4[1]==c4[2]&&c4[2]==c4[3]&&c4[3]==c4[4]&&c4[4]==0){
f1f=1;
SetConsoleTextAttribute(hConsole, 12); // 红色
cout<<"有一人所持牌数为0,将重新发牌" <<endl;
SetConsoleTextAttribute(hConsole, 7);
}
if(f2f||f1f){
fff=1;
}
else{
fff=0;
}
i++;
}
}