当前位置: 首页 > news >正文

c++狼人杀

#include<bits/stdc++.h>
#include<windows.h>
#define /*白色*/white SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
#define /*初始色*/original SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
#define /*红色*/red SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED);
#define /*绿色*/green SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_GREEN);
#define /*蓝色*/blue SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_BLUE);
#define /*黄色*/yellow SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED |FOREGROUND_GREEN);
#define /*粉色*/pink SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED |FOREGROUND_BLUE);
#define /*淡蓝*/lightblue SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_GREEN |FOREGROUND_BLUE);
using namespace std;
int life[7]={1,1,1,1,1,1};
int potions[5]={-1,1};
int vote[7]={0};
string name[7]={"预言家","女巫","平民","平民","狼人","狼人"};
int seer(int x,int y,int n,int p1,int p2,int l1,int l2)
{
int rescued;
int die;
int die_potions;
bool gameover=false;
while(gameover==false)
{
cout<<endl<<"下一天:----------------------------"<<endl;
for(int i=1;i<=4;i++)
{
if(i==1&&(life[l1]>=0 or life[l2]>=0))
{
cout<<"狼人:"<<endl;
srand((unsigned)time(NULL));
die=rand()%6;
while(name[die]=="狼人"||life[die]==-1) die=rand()%6;
life[die]--;
cout<<"狼人杀了"<<name[die]<<endl;
}
if(i==2&&life[x]>=0)
{
cout<<"预言家:"<<endl;
cout<<"你是预言家,请输入0~5的编号(代表相应的人)(除了"<<x<<"号)来预言"<<endl;
int res;
cin>>res;
if(name[res]=="平民"||name[res]=="女巫"||name[res]=="预言家") cout<<"好人"<<endl;
if(name[res]=="狼人") cout<<"坏人"<<endl;
}
if(i==3&&life[n]>=0)
{
cout<<"女巫:"<<endl;
int dor;
srand((unsigned)time(NULL));
dor=rand()%3;
if(dor==0)
{
die_potions=rand()%6;
while(name[die_potions]=="女巫"||life[die_potions]<=0) die_potions=rand()%6;
life[die_potions]--;
potions[dor]++;
cout<<"女巫杀了"<<name[die_potions]<<endl;
}
if(dor==1)
{
int help;
for(int i=0;i<6;i++) if(life[i]==0) life[i]++,help=i;
potions[dor]--;
cout<<"女巫救了"<<name[help]<<endl;
}
if(dor==2)
{
cout<<"没用药"<<endl;
}
}
if(i==4)
{
int sum_die=0;
cout<<"今晚";
for(int j=0;j<6;j++)
{
if(life[j]==0)
{
sum_die++;
life[j]--;
cout<<j<<"号"<<name[j]<<"死了";
}
}
if(sum_die==0) cout<<"是平安夜";
int fl=0,fp=0;
for(int j=0;j<6;j++)
{
if(life[j]==1)
{
if(name[j]=="狼人") fl++;
else fp++;
}
}
if(fl==0)
{
cout<<endl<<"平民赢了"<<endl;
gameover=true;
continue;
}
if(fp==0)
{
cout<<endl<<"狼人赢了"<<endl;
gameover=true;
continue;
}
cout<<endl<<"投票"<<endl;
int a[7]={0,0,0,0,0,0};
for(int j=0;j<6;j++)
{
if(j==x&&life[x]==1)
{
cout<<"请投0~5号你认为是狼人的";
int ps;
cin>>ps;
a[ps]++;
}
else if(life[j]==1)
{
srand((unsigned)time(NULL));
int cs;
cs=rand()%6;
while(life[cs]!=1||cs==j) cs=rand()%6;
a[cs]++;
}
}
cout<<"投票结果:"<<endl;
cout<<"0 1 2 3 4 5"<<endl;
for(int j=0;j<6;j++) cout<<a[j]<<" ";
cout<<endl;
int max=-1,mp;
for(int j=0;j<6;j++) if(a[j]>=max) max=a[j],mp=j;
cout<<mp<<"号"<<name[mp]<<"出局"<<endl<<endl;
life[mp]=-1;
int good=0,bad=0;
for(int j=0;j<6;j++)
{
if(life[j]==1&&(name[j]=="平民"||name[j]=="女巫"||name[j]=="预言家")) good++;
if(life[j]==1&&name[j]=="狼人") bad++;
}
if(bad==0)
{
cout<<"平民赢了"<<endl;
gameover=true;
}
if(good==0)
{
cout<<"狼人赢了"<<endl;
gameover=true;
}
}
}
system("pause");
}
return 0;
}
int Lycan(int x,int y,int n,int p1,int p2,int l1,int l2)
{
int rescued;
int die;
int die_potions;
bool gameover=false;
while(gameover==false)
{
cout<<endl<<"下一天:----------------------------"<<endl;
for(int i=1;i<=4;i++)
{
if(i==1&&life[x]>=0)
{
cout<<"狼人:"<<endl;
cout<<"你是狼人,请输入0~5的编号(代表相应的人)(除了"<<x<<"和"<<l1+l2-x<<"号)来杀死"<<endl;
cin>>die;
life[die]--;
cout<<"狼人杀了"<<name[die]<<endl;
}
if(i==1&&life[x]==-1&&life[l1+l2-x]>=0)
{
cout<<"狼人:"<<endl;
srand((unsigned)time(NULL));
die=rand()%6;
while(name[die]=="狼人"||life[die]==-1) die=rand()%6;
life[die]--;
cout<<"狼人杀了"<<name[die]<<endl;
}
if(i==2&&life[y]>=0)
{
cout<<"预言家:"<<endl;
cout<<"预言完毕"<<endl;
}
if(i==3&&life[n]>=0)
{
cout<<"女巫:"<<endl;
int dor;
srand((unsigned)time(NULL));
dor=rand()%3;
if(dor==0)
{
die_potions=rand()%6;
while(name[die_potions]=="女巫"||life[die_potions]<=0) die_potions=rand()%6;
life[die_potions]--;
potions[dor]++;
cout<<"女巫杀了"<<name[die_potions]<<endl;
}
if(dor==1)
{
int help;
for(int i=0;i<6;i++) if(life[i]==0) life[i]++,help=i;
potions[dor]--;
cout<<"女巫救了"<<name[help]<<endl;
}
if(dor==2)
{
cout<<"没用药"<<endl;
}
}
if(i==4)
{
int sum_die=0;
cout<<"今晚";
for(int j=0;j<6;j++)
{
if(life[j]==0)
{
sum_die++;
life[j]--;
cout<<j<<"号"<<name[j]<<"死了";
}
}
if(sum_die==0) cout<<"是平安夜";
int fl=0,fp=0;
for(int j=0;j<6;j++)
{
if(life[j]==1)
{
if(name[j]=="狼人") fl++;
else fp++;
}
}
if(fl==0)
{
cout<<endl<<"平民赢了"<<endl;
gameover=true;
continue;
}
if(fp==0)
{
cout<<endl<<"狼人赢了"<<endl;
gameover=true;
continue;
}
cout<<endl<<"投票"<<endl;
int a[7]={0,0,0,0,0,0};
for(int j=0;j<6;j++)
{
if(j==x&&life[x]==1)
{
cout<<"请投0~5号你认为是狼人的";
int ps;
cin>>ps;
a[ps]++;
}
else if(life[j]==1)
{
srand((unsigned)time(NULL));
int cs;
cs=rand()%6;
while(life[cs]!=1||cs==j) cs=rand()%6;
a[cs]++;
}
}
cout<<"投票结果:"<<endl;
cout<<"0 1 2 3 4 5"<<endl;
for(int j=0;j<6;j++) cout<<a[j]<<" ";
cout<<endl;
int max=-1,mp;
for(int j=0;j<6;j++) if(a[j]>=max) max=a[j],mp=j;
cout<<mp<<"号"<<name[mp]<<"出局"<<endl<<endl;
life[mp]=-1;
int good=0,bad=0;
for(int j=0;j<6;j++)
{
if(life[j]==1&&(name[j]=="平民"||name[j]=="女巫"||name[j]=="预言家")) good++;
if(life[j]==1&&name[j]=="狼人") bad++;
}
if(bad==0)
{
cout<<"平民赢了"<<endl;
gameover=true;
}
if(good==0)
{
cout<<"狼人赢了"<<endl;
gameover=true;
}
}
}
system("pause");
}
return 0;
}
int witch(int x,int y,int n,int p1,int p2,int l1,int l2)
{
int rescued;
int die;
int die_potions;
bool gameover=false;
while(gameover==false)
{
cout<<endl<<"下一天:----------------------------"<<endl;
for(int i=1;i<=4;i++)
{
if(i==1&&(life[l1]>=0 or life[l2]>=0))
{
cout<<"狼人:"<<endl;
srand((unsigned)time(NULL));
die=rand()%6;
while(name[die]=="狼人"||life[die]==-1) die=rand()%6;
life[die]--;
cout<<"狼人杀了"<<name[die]<<endl;
}
if(i==2&&life[y]>=0)
{
cout<<"预言家:"<<endl;
cout<<"预言完毕"<<endl;
}
if(i==3&&life[n]>=0)
{
cout<<"女巫:"<<endl;
cout<<"你是女巫,请输入d、r、n。d代表要杀、r代表要救,n代表不用药"<<endl;
char dor;
cin>>dor;
if(dor=='d')
{
cout<<"请输入0~5号你要杀的人(除了"<<n<<"号)"<<endl;
cin>>die_potions;
life[die_potions]--;
potions[0]++;
cout<<"女巫杀了"<<name[die_potions]<<endl;
}
if(dor=='r')
{
int help;
for(int i=0;i<6;i++) if(life[i]==0) life[i]++,help=i;
potions[1]--;
cout<<"女巫救了"<<name[help]<<endl;
}
if(dor=='n')
{
cout<<"没用药"<<endl;
}
}
if(i==4)
{
int sum_die=0;
cout<<"今晚";
for(int j=0;j<6;j++)
{
if(life[j]==0)
{
sum_die++;
life[j]--;
cout<<j<<"号"<<name[j]<<"死了";
}
}
if(sum_die==0) cout<<"是平安夜";
int fl=0,fp=0;
for(int j=0;j<6;j++)
{
if(life[j]==1)
{
if(name[j]=="狼人") fl++;
else fp++;
}
}
if(fl==0)
{
cout<<endl<<"平民赢了"<<endl;
gameover=true;
continue;
}
if(fp==0)
{
cout<<endl<<"狼人赢了"<<endl;
gameover=true;
continue;
}
cout<<endl<<"投票"<<endl;
int a[7]={0,0,0,0,0,0};
for(int j=0;j<6;j++)
{
if(j==x&&life[x]==1)
{
cout<<"请投0~5号你认为是狼人的";
int ps;
cin>>ps;
a[ps]++;
}
else if(life[j]==1)
{
srand((unsigned)time(NULL));
int cs;
cs=rand()%6;
while(life[cs]!=1||cs==j) cs=rand()%6;
a[cs]++;
}
}
cout<<"投票结果:"<<endl;
cout<<"0 1 2 3 4 5"<<endl;
for(int j=0;j<6;j++) cout<<a[j]<<" ";
cout<<endl;
int max=-1,mp;
for(int j=0;j<6;j++) if(a[j]>=max) max=a[j],mp=j;
cout<<mp<<"号"<<name[mp]<<"出局"<<endl<<endl;
life[mp]=-1;
int good=0,bad=0;
for(int j=0;j<6;j++)
{
if(life[j]==1&&(name[j]=="平民"||name[j]=="女巫"||name[j]=="预言家")) good++;
if(life[j]==1&&name[j]=="狼人") bad++;
}
if(bad==0)
{
cout<<"平民赢了"<<endl;
gameover=true;
}
if(good==0)
{
cout<<"狼人赢了"<<endl;
gameover=true;
}
}
}
system("pause");
}
return 0;
}
int commoner(int x,int y,int n,int p1,int p2,int l1,int l2)
{
int rescued;
int die;
int die_potions;
bool gameover=false;
while(gameover==false)
{
cout<<endl<<"下一天:----------------------------"<<endl;
for(int i=1;i<=4;i++)
{
if(i==1&&(life[l1]>=0 or life[l2]>=0))
{
cout<<"狼人:"<<endl;
srand((unsigned)time(NULL));
die=rand()%6;
while(name[die]=="狼人"||life[die]==-1) die=rand()%6;
life[die]--;
cout<<"狼人杀了"<<name[die]<<endl;
}
if(i==2&&life[y]>=0)
{
cout<<"预言家:"<<endl;
cout<<"预言完毕"<<endl;
}
if(i==3&&life[n]>=0)
{
cout<<"女巫:"<<endl;
int dor;
srand((unsigned)time(NULL));
dor=rand()%3;
if(dor==0)
{
die_potions=rand()%6;
while(name[die_potions]=="女巫"||life[die_potions]<=0) die_potions=rand()%6;
life[die_potions]--;
potions[dor]++;
cout<<"女巫杀了"<<name[die_potions]<<endl;
}
if(dor==1)
{
int help;
for(int i=0;i<6;i++) if(life[i]==0) life[i]++,help=i;
potions[dor]--;
cout<<"女巫救了"<<name[help]<<endl;
}
if(dor==2)
{
cout<<"没用药"<<endl;
}
}
if(i==4)
{
int sum_die=0;
cout<<"今晚";
for(int j=0;j<6;j++)
{
if(life[j]==0)
{
sum_die++;
life[j]--;
cout<<j<<"号"<<name[j]<<"死了";
}
}
if(sum_die==0) cout<<"是平安夜";
int fl=0,fp=0;
for(int j=0;j<6;j++)
{
if(life[j]==1)
{
if(name[j]=="狼人") fl++;
else fp++;
}
}
if(fl==0)
{
cout<<endl<<"平民赢了"<<endl;
gameover=true;
continue;
}
if(fp==0)
{
cout<<endl<<"狼人赢了"<<endl;
gameover=true;
continue;
}
cout<<endl<<"投票"<<endl;
int a[7]={0,0,0,0,0,0};
for(int j=0;j<6;j++)
{
if(j==x&&life[x]==1)
{
cout<<"请投0~5号你认为是狼人的";
int ps;
cin>>ps;
a[ps]++;
}
else if(life[j]==1)
{
srand((unsigned)time(NULL));
int cs;
cs=rand()%6;
while(life[cs]!=1||cs==j) cs=rand()%6;
a[cs]++;
}
}
cout<<"投票结果:"<<endl;
cout<<"0 1 2 3 4 5"<<endl;
for(int j=0;j<6;j++) cout<<a[j]<<" ";
cout<<endl;
int max=-1,mp;
for(int j=0;j<6;j++) if(a[j]>=max) max=a[j],mp=j;
cout<<mp<<"号"<<name[mp]<<"出局"<<endl<<endl;
life[mp]=-1;
int good=0,bad=0;
for(int j=0;j<6;j++)
{
if(life[j]==1&&(name[j]=="平民"||name[j]=="女巫"||name[j]=="预言家")) good++;
if(life[j]==1&&name[j]=="狼人") bad++;
}
if(bad==0)
{
cout<<"平民赢了"<<endl;
gameover=true;
}
if(good==0)
{
cout<<"狼人赢了"<<endl;
gameover=true;
}
}
}
system("pause");
}
return 0;
}
int main()
{
begin:
white
cout<<" 狼人杀"<<endl;
yellow
cout<<"1个预言家 ";
yellow
cout<<"1个女巫 " ;
yellow
cout<<"2个平民 ";
green
cout<<" 2个狼人"<<endl;
original
Sleep(1000);
srand((unsigned)time(NULL));
for(int i=1;i<=1000;i++)
{
int x=rand()%6;
int y=rand()%6;
swap(name[x],name[y]);
}
int player=rand()%6;
cout<<"你是";
red
cout<<name[player]<<endl;
original
cout<<"您的编号是"<<player<<endl<<endl;
Sleep(2000);
int l1,l2,l=1;
int y;
int n;
int p1,p2,p=1;
for(int i=0;i<6;i++)
{
if(name[i]=="狼人"&&l==1)
{
l1=i;
l++;
continue;
}
if(name[i]=="狼人"&&l==2) l2=i,l++;
if(name[i]=="预言家") y=i;
if(name[i]=="女巫") n=i;
if(name[i]=="平民"&&p==1)
{
p1=i;
p++;
continue;
}
if(name[i]=="平民"&&p==2) p2=i,p++;
}
if(player==y) seer(player,y,n,p1,p2,l1,l2);
if(player==l1 or player==l2) Lycan(player,y,n,p1,p2,l1,l2);
if(player==n) witch(player,y,n,p1,p2,l1,l2);
if(player==p1 or player==p2) commoner(player,y,n,p1,p2,l1,l2);
else return 0;
}

http://www.jsqmd.com/news/115945/

相关文章:

  • 宠物识别丨基于弱监督学习的宠物视频内容自动标注技术实践 - 指南
  • 朴易天下:道家修行的专业术语分享
  • 个人投资者的落地路径:从“说人话,做量化”到实盘前的三道关
  • 神经网络中的 block 和 module
  • item13--使用对象管理资源
  • 深入解析:蓝桥杯基础算法精讲:模拟与高精度运算实战指南
  • item12-- 拷贝一个对象的所有组成部分
  • sub_match
  • sub_match
  • 抽奖机随机号码生成:3 种算法实现 + 测试全解析(附完整代码)
  • 【零基础精通】Python 字符串全解析:从字符序列到不可变对象的深度构建
  • item14--谨慎考虑资源管理类的拷贝行为
  • python django flask酒店客房管理系统数据可视化分析系统_gq8885n3--论文md5
  • python django flask鹿幸公司员工食堂在线点餐餐饮餐桌预约管理系统的设计与实现_utcnqqs0--论文
  • error_code
  • 虚拟化初步了解
  • Miloco 深度打通 Home Assistant,实现设备级精准控制
  • 好用的大型牛场水滴粉碎机技术强的
  • set_value
  • 日记1217
  • function的类型擦除
  • function bind
  • 日记12,19
  • Item10--令赋值操作符返回一个
  • Item9--绝不在构造和析构过程中调用虚函数
  • python django flask考研互助交流平台_c62p51fu--论文
  • 日记12.18
  • 离散化遍历
  • Ubuntu上使用VScode创建Maven项目
  • 线程(2)