至于作弊,请看最后一段。
代码如下:
#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;
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){
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(r[hao].shen==1){
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;
if(r[cha].shen==1){
cerr<<"狼人!\n";
}else{
cerr<<"好人.\n";
}
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<<"身份列表:\n";
cerr<<" 平民:"<<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)){
cerr<<"执法?(Y/N)\n";
char q;
cin>>q;
if(q=='y'||q=='Y'){
cerr<<"谁?\n";
cin>>lsbl;
if(r[lsbl].shen==1){
r[lsbl].hp=1;
cerr<<"执法成功!\n";
}else{
r[hao].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:猎人
攻略后面会出。
希望大家能献出自己宝贵的赞,你们的赞是对我最大的鼓励,
谢谢大家能看到最后,在下感激不尽。