#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
const int daytime=0,night=1;
int day=0, during_time=daytime, player_number, my_number;
HWND hwnd=GetForegroundWindow();//窗口定义
/*设置颜色*/
const int blue=0,yellow=1,red=2,green=3,purple=4,white=5;//颜色常量
void color(int c){
switch(c)
{
case red:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);break;
case green:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);break;
case yellow:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);break;
case blue:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_BLUE);break;
case white:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN | FOREGROUND_BLUE);break;
case purple:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_BLUE);break;
}
}
int idx_police=-1;
/*控制光标在控制台的位置 */
void gotoxy(int x,int y){
COORD position;
position.X=x;
position.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), position);
}
/*初始化窗口*/
void init_Show_Window(){
system("mode con lines=60 cols=188");//全屏
ShowWindow(hwnd,SW_MAXIMIZE);//窗口最大化
DeleteMenu(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE, MF_BYCOMMAND);
DrawMenuBar(GetConsoleWindow());//删除×字符
}
/*玩家类*/
const int nvwu=0,cunmin=1,yuyanjia=2,langren=3,lieren=4,shouwei=5,good=6,die=1,life=2;
class player{
public:
int type;
int die_or_life;
int how(){
return die_or_life;
}
int is_light;//是否已经公布
int killer;
};
player players[1000];
/*转换白天模式*/
void change_daytime(){
during_time=daytime;
day++;
}
/*转换黑夜模式*/
void change_night(){
during_time=night;
}
int nnvwu=0,ncunmin=0,nyuyanjia=0,nlangren=0,nlieren=0,nshouwei=0;
int idxnvwu,idxshouwei,idxyuyanjia,idxlieren,idxlangren[4]={-1,-1,-1,-1};
/*b是否在Arr中*/
bool is_include(int arr[],int b,int l){
for(int i=0;i<l;i++){
if(arr[i]==b)
return true;
}
return false;
}
/*初始化人数*/
void init_players(){
my_number=rand()%player_number;
if(player_number==12) nlangren=4;
else if(player_number>=10) nlangren=3;
else nlangren=2;
for(int i=0;i<player_number;i++)
{
players[i].die_or_life=life;
players[i].is_light=0;
players[i].type=-1;
players[i].killer=2147483647;
}
for(int i=0;i<nlangren;i++)
{
int p=rand()%player_number;
if(!is_include(idxlangren,p,4))
idxlangren[i]=p,players[p].type=langren;
else
i--;
Sleep(rand()%80+100);
}
if(player_number==12)
{
do{
idxshouwei=rand()%player_number;
}while(players[idxshouwei].type!=-1);
players[idxshouwei].type=shouwei;
}
do{
idxnvwu=rand()%player_number;
}while(players[idxnvwu].type!=-1);
players[idxnvwu].type=nvwu;
if(player_number>=10)
{
do{
idxlieren=rand()%player_number;
}while(players[idxlieren].type!=-1);
players[idxlieren].type=lieren;
}
do{
idxyuyanjia=rand()%player_number;
}while(players[idxyuyanjia].type!=-1);
players[idxyuyanjia].type=yuyanjia;
for(int i=0;i<player_number;i++)
if(players[i].type==-1)
players[i].type=cunmin,
ncunmin++;
if(players[my_number].type==langren)
{
for(int i=0;i<nlangren;i++)
{
players[idxlangren[i]].is_light=1;
}
}
players[my_number].is_light=1;
}
/*在屏幕上打印东西*/
void print(){
gotoxy(0,0);
gotoxy(90,0);
if(during_time==night)
color(red);
else
color(blue);
printf("第%d天 | ",day);
if(during_time==night) cout<<"黑夜";
else cout<<"白天";
gotoxy(0,3);
color(blue);
cout<<" 我的号位:"<<my_number+1;
for(int i=0;i<player_number;i++){
gotoxy(i*8+1,4);
if(i==idx_police) color(yellow);
else color(blue);
cout<<i+1<<"号位";
gotoxy(i*8+1,5);
if(players[i].how()==die){
color(red);
cout<<"死 亡";
}else{
color(green);
cout<<"存 活";
}
gotoxy(i*8+1,6);
color(blue);
if(players[i].is_light){
if(players[i].is_light==1){
switch(players[i].type){
case nvwu: cout<<"女 巫";break;
case yuyanjia: cout<<"\b预言家";break;
case cunmin: cout<<"村 民";break;
case langren:cout<<"狼 人"; break;