【小游戏】狼人杀·觉醒之夜

9 篇文章 0 订阅
6 篇文章 0 订阅

代码如下:

#include<iostream>
#include<ctime>
#include<windows.h>
#define sys system("cls");
using namespace std;
struct role{
	bool hp=0;
	int shen;
	int to[11]{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
	int wanto=-1;
	int tod=0;
};
role r[12];
int rad(){
	int lsbl;
	time_t t;
	for(;1;){
		srand(time(&t));
		lsbl=rand()%12;
		if(!(r[lsbl].hp)){
			return lsbl;
		}
	}
}
int btob(int b[12]){
	int maxx=0;
	int maxn,i;
	for(i=0;i<12;i++){
		if(maxx<b[i]){
			maxx=b[i];
			maxn=i;
		}
	}
	return maxn;
}
int main(){
	bool kg=0,gon=0,jisha=1;
	cerr<<"狼人杀·觉醒之夜\n";
	cerr<<"开不开?\n";
	cin>>kg;
	sys;
	time_t d;
	int p=0,l=0,w=0,y=0,j=0,lr=0,l_[l]{},w_=-1,y_=-1,kill=-1,jui=1,du=-1,dud=1,cha=-1,lsbl=0,good,mel=0,hhpp=12,bto[12]{},BTO;
	srand(time(&d));
	int hao;
	hao=rand()%12;
	for(int i=0;i<12;i++){
		q:switch(rand()%6){
			case 0:
				if(p<=4){
					p++;
					r[i].shen=0;
				}else{
					goto q;
				}
				break;
			case 1:
				if(l<=2){
					l++;
					r[i].shen=1;
				}else{
					goto q;
				}
				break;
			case 2:
				if(w<=0){
					w++;
					r[i].shen=2;
				}else{
					goto q;
				}
				break;
			case 3:
				if(y<=0){
					y++;
					r[i].shen=3;
				}else{
					goto q;
				}
				break;
			case 4:
				if(j<=0){
					j++;
					r[i].shen=4;
				}else{
					goto q;
				}
				break;
			case 5:
				if(lr<=1){
					lr++;
					r[i].shen=5;
				}else{
					goto q;
				}
				break;
		}
	}
	if(kg){
		int sh;
        cerr<<"身份";
		cin>>sh;
		for(int i=0;i<12;i++){
			if(r[i].shen==sh){
				hao=i;
				break;
			}
		}
	}
	good=hhpp-l;
    system("cls");
	cerr<<"你的号码是(0-11):"<<hao;
	cerr<<"\n你的身份是:";
	cerr<<"\n";
	switch(r[hao].shen){
		case 0:
			cerr<<"平民\n";
			break;
		case 1:
			cerr<<"狼人\n";
			cerr<<"队友:\n";
			mel=1;
			for(int i=0;i<12;i++){
				if(r[i].shen==1){
					cerr<<i<<" ";
				}
			}
			cerr<<"\n";
			break;
		case 2:
			cerr<<"女巫\n";
			break;
		case 3:
			cerr<<"觉醒预言家\n";
			break;
		case 4:
			cerr<<"执法者\n";
			gon=1;
			break;
		case 5:
			cerr<<"猎人\n";
			gon=1;
			break;
	}
	Sleep(5000);
	int q,i;
	for(;1;){
		for(int i=0;i<12;i++){
			if(r[i].hp==0){
				hhpp++;
			}
		}		
		sys;
		good=hhpp-l;
		srand(time(&d));
		if(l<=0){
			cerr<<"游戏结束!\n";
			if(r[hao].shen==1){
				cerr<<"失败";
			}else{
				cerr<<"成功";
			}
			break;
		}
		if(l>good||l>hhpp){
			cerr<<"游戏结束!\n";
			if(r[hao].shen==1){
				cerr<<"成功";
			}else{
				cerr<<"失败";
			}
			break;
		}
		for(i=0,q=0;i<12;i++){
			if(r[i].hp)
				continue;
			if(r[i].shen==1){
				l_[q]=i;
				q++;
			}
			if(r[i].shen==2){
				w_=i;
			}
			if(r[i].shen==3){
				y_=i;
			}
		}
		if(l!=0){
			if(r[hao].shen==1&&r[hao].hp==0){
				cerr<<"杀谁?\n";
				cin>>kill;
			}else{
				k:kill=rand()%12;
				if(r[kill].hp==1||r[kill].shen==1){
					goto k;
				}
			}
		}
		if(r[hao].shen==2){
			cerr<<"今天"<<kill<<"死亡\n1.不救0.救\n";
			cin>>jui;
			if(jui==0){
				kill=-1;
			}else{
				if(dud==1){
					cerr<<"毒?\n1.不毒0.毒\n";
					cin>>du;
					dud=0;
				}
				if(du==0){
					duu:cerr<<"毒谁?\n";
					cin>>du;
					if(du<0||du>11||du==hao){
						sys;
						goto duu;
					}else{
						r[du].hp=1;
					}
				}
				du=-1;
			}
		}else{
			if(jui==1){
				jui=0;
				kill=-1;
			}
		}
		if(r[hao].shen==3){
			cerr<<"查谁?\n";
			cin>>cha;
			switch(r[cha].shen){
				case 0:
					cerr<<"平民\n";
					break;
				case 1:
					cerr<<"狼人\n";
					break;
				case 2:
					cerr<<"女巫\n";
					break;
				case 3:
					cerr<<"觉醒预言家\n";
					break;
				case 4:
					cerr<<"执法者\n";
					gon=1;
					break;
				case 5:
					cerr<<"猎人\n";
					gon=1;
					break;
			}
			Sleep(2000);
		}else{
			goii:srand(time(&d));
			int ii=rand()%12;
			if(r[ii].hp!=1){
				if(r[ii].shen==1){
					r[y_].wanto=ii;
				}
			}else{
				goto goii;
			}
		}
		sys;
		if(kill!=-1){
			r[kill].hp=1;
		}
		if(du!=-1){
			r[du].hp=1;
		}
		if(kg&&gon){
			cerr<<"狼:";
			for(int i=0;i<12;i++){
				if(r[i].shen==1){
					cerr<<i<<" ";
				}
			}
			cerr<<"\n";
		}
		cerr<<"身份列表:";
		cerr<<"\n	平民:"<<p;
		cerr<<"\n	剩余狼人:"<<l;
		cerr<<"\n	女巫:"<<w;
		cerr<<"\n	觉醒预言家:"<<y;
		cerr<<"\n	执法者:"<<j;
		cerr<<"\n	猎人:"<<lr;
		cerr<<"\n昨晚死亡:";
		if(kill==0-1){
		}else cerr<<kill<<" ";
		if(du==0-1){
		}else cerr<<du<<" ";
		cerr<<"\n";
		if(r[hao].shen==4&&(r[hao].hp!=1)&&jisha){
			zhfa:cerr<<"执法?(Y/N)\n";
			char q;
			cin>>q;
			if(q=='y'||q=='Y'){
				cerr<<"谁?\n";
				cin>>lsbl;
				if(r[lsbl].shen==1){
					l--;
					r[lsbl].hp=1;
					cerr<<"执法成功!\n";
					goto zhfa;
				}else{
					jisha=0;
					r[lsbl].hp=1;
					cerr<<"你击杀了好人,你不能在击杀人了!\n";
				}
			}
		}
		if(r[hao].shen==1){
			cerr<<"队友:\n";
				for(int i=0;i<12;i++){
					if(r[i].shen==1){
						cerr<<i;
					}
				}
		}
		cerr<<"你是"<<hao<<"\n请投票:\n";
		
		for(int i=0;i<12;i++){
			if(r[i].hp)continue;
			if(i==hao){
				cin>>lsbl;
				r[lsbl].tod++;
			}else{
				if(r[i].wanto!=-1){
					r[r[i].wanto].to[r[r[i].wanto].tod]=i;
					r[r[i].wanto].tod++;
					bto[r[i].wanto]++;
					cerr<<i<<"->"<<r[i].wanto<<endl;
				}else if(!(r[i].tod<=0)){
					r[r[i].to[0]].to[r[r[i].to[0]].tod]=i;
					r[r[i].to[0]].tod++;
					bto[r[i].to[0]]++;
					cerr<<i<<"->"<<r[i].to[0]<<endl;
				}else{
					gogogo:lsbl=rad();
					if(r[lsbl].hp){
						goto gogogo;
					}
					r[lsbl].to[r[lsbl].tod]=i;
					r[lsbl].tod++;
					bto[lsbl]++;
					cerr<<i<<"->"<<lsbl<<endl;
				}
			}
			
		}
		for(int i=0;i<12;i++){
			if(r[i].hp){
				bto[i]=0;
				continue;
			}
			bto[i]=r[i].tod;
		}
		if(kg&&r[hao].shen==5&&r[hao].hp==false){
			r[hao].hp=1;
			cerr<<hao<<"被放逐.\n";
			BTO=hao;
		}else{
			BTO=btob(bto);
			if(r[BTO].shen==1){
				l--;
			}
			r[btob(bto)].hp=1;
			cerr<<btob(bto)<<"被放逐.\n";
		}
		if(r[BTO].shen==5){
			if(BTO==hao){
				cerr<<"枪谁?\n";
				cin>>lsbl;
				if(!(lsbl>11||lsbl<0)){
					r[lsbl].hp=1;
				}
			}
		}
		Sleep(2500);
		for(int i=0;i<12;i++){
			r[i].tod=0;
			for(int i1=0;i1<11;i1++){
				r[i].to[i1]=-1;
			}
		}
		BTO=-1;
	}
}

关于开挂:

        开始时,按1,即开挂。

        

 身份表:

        0:平民

        1:狼人

        2:女巫

        3:觉醒预言家

        4:执法者

        5:猎人

希望大家能献出自己宝贵的赞,你们的赞是对我最大的鼓励,

谢谢大家能看到最后,在下感激不尽

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值