1 Star 0 Fork 1

saigon/Algorithms

forked from charlieshu/Algorithms 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
狼人杀高级.cpp 43.03 KB
一键复制 编辑 原始数据 按行查看 历史
charlie 提交于 2024-01-09 00:01 . move from github to gitee
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584
#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include <conio.h>
#include<windows.h>
using namespace std;
string wan;
int num;
struct IDname{
int geshu;
string NAME;
};
IDname jue_se[100];
struct ID{
int num;
bool life;
string name;
int know;
int how;
};
ID player[21];
int n, MY, kill1, kill2;
char a;
bool jieyao = 1, duyao = 1;
int lieren, shouwei = 0;
void init1()
{
jue_se[1].NAME = "村民 ";
jue_se[2].NAME = "狼人 ";
jue_se[3].NAME = "女巫 ";
jue_se[4].NAME = "预言家 ";
jue_se[5].NAME = "猎人 ";
jue_se[6].NAME = "守卫 ";
}
void init2(int nn)
{
switch (nn)
{
case 6:
jue_se[1].geshu = 3;
jue_se[2].geshu = 2;
jue_se[3].geshu = 1;
jue_se[4].geshu = 0;
jue_se[5].geshu = 0;
jue_se[6].geshu = 0;
break;
case 7:
jue_se[1].geshu = 3;
jue_se[2].geshu = 2;
jue_se[3].geshu = 1;
jue_se[4].geshu = 1;
jue_se[5].geshu = 0;
jue_se[6].geshu = 0;
break;
case 8:
jue_se[1].geshu = 3;
jue_se[2].geshu = 3;
jue_se[3].geshu = 1;
jue_se[4].geshu = 1;
jue_se[5].geshu = 0;
jue_se[6].geshu = 0;
break;
case 9:
jue_se[1].geshu = 3;
jue_se[2].geshu = 3;
jue_se[3].geshu = 1;
jue_se[4].geshu = 1;
jue_se[5].geshu = 1;
jue_se[6].geshu = 0;
break;
case 10:
jue_se[1].geshu = 4;
jue_se[2].geshu = 3;
jue_se[3].geshu = 1;
jue_se[4].geshu = 1;
jue_se[5].geshu = 1;
jue_se[6].geshu = 0;
break;
case 11:
jue_se[1].geshu = 4;
jue_se[2].geshu = 4;
jue_se[3].geshu = 1;
jue_se[4].geshu = 1;
jue_se[5].geshu = 1;
jue_se[6].geshu = 0;
break;
case 12:
jue_se[1].geshu = 4;
jue_se[2].geshu = 4;
jue_se[3].geshu = 1;
jue_se[4].geshu = 1;
jue_se[5].geshu = 1;
jue_se[6].geshu = 1;
break;
default:
cout << "输入错误,再见" << endl;
exit(0);
break;
}
}
int van[10] = { 7,4,6,43,35,1,2,8,20,19 };
void init3(int nn)
{
srand(time(0));
Sleep(rand() % 44);
int x = 10000;
int t = rand();
srand(time(NULL));
int y = van[(rand() % 100 * van[rand() % 10] + t) % 10];
if (nn <= 6)
x = abs(x * 6 / y) % 3 + 1;
else if (nn <= 8)
x = abs(x * 7 / y) % 4 + 1;
else if (nn <= 11)
x = abs(x * 8 / y) % 5 + 1;
else if (nn <= 14)
x = abs(x * 9 / y) % 6 + 1;
do
{
if (nn <= 6)
x = x % 3 + 1;
else if (nn <= 8)
x = x % 4 + 1;
else if (nn <= 11)
x = x % 5 + 1;
else if (nn <= 14)
x = x % 6 + 1;
if (jue_se[x].geshu > 0)
{
player[nn].name = jue_se[x].NAME;
if (player[nn].name == "猎人 ")
lieren = nn;
if (player[nn].name == "守卫 ")
shouwei = nn;
player[nn].life = 1;
player[nn].num = nn;
player[nn].know = 0;
jue_se[x].geshu--;
player[nn].how = 0;
break;
}
} while (jue_se[x].geshu == 0);
}
void printhhh()
{
int cm = 0;
int sz = 0;
for (int i = 1; i <= n; i++)
{
if (player[i].life == 0)
continue;
else if (player[i].name == "村民 ")
cm++;
else if (player[i].name == "女巫 " || player[i].name == "预言家 " || player[i].name == "猎人 " || player[i].name == "守卫 ")
sz++;
}
if (sz == 0 || cm == 0)
cout << "狼人阵营胜利" << endl;
else
cout << "好人阵营胜利" << endl;
for (int i = 1; i <= n; i++)
{
cout << left << setw(3) << player[i].num << ": " << player[i].name << " ";
if (player[i].life == 0)
cout << "死亡" << "\t";
else
cout << "存活" << "\t";
if (player[i].how == 0)
cout << "最终存活 " << endl;
else if (player[i].how == 1)
cout << "最终被狼人杀死" << endl;
else if (player[i].how == 2)
cout << "最终被投票投死" << endl;
else if (player[i].how == 3)
cout << "最终被女巫毒死" << endl;
else if (player[i].how == 4)
cout << "最终被猎人射杀" << endl;
}
system("pause");
system("pause");
system("pause");
}
void print(int day, int ti)
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
if (ti == 0)
SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY);
else
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
cout << "\t\t\t\t第" << day << "天 ";
if (ti == 0)
cout << "白天" << endl;
else
cout << "夜晚" << endl;
cout << "我的位置:" << MY << "号" << endl;
for (int i = 1; i <= 6; i++)
{
cout << player[i].num << "号位 ";
}
cout << endl;
for (int i = 1; i <= 6; i++)
{
if (player[i].life == 1)
{
if (ti == 0)
SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_GREEN);
else
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
cout << "存活 ";
}
else
{
if (ti == 0)
SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_RED);
else
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
cout << "已死亡 ";
}
}
if (ti == 0)
SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY);
else
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
cout << endl;
for (int i = 1; i <= 6; i++)
{
if (player[i].know == 0)
cout << "未知 ";
else if (player[i].know == 1)
{
if (player[i].name == "狼人 ")
cout << "狼人 ";
else
cout << "好人 ";
}
else if (player[i].know == 2)
cout << player[i].name << " ";
}
cout << endl << endl;
for (int i = 7; i <= n; i++)
{
if (i < 10)
cout << player[i].num << "号位 ";
else
cout << player[i].num << "号位 ";
}
cout << endl;
for (int i = 7; i <= n; i++)
{
if (player[i].life == 1)
{
if (ti == 0)
SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_GREEN);
else
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_GREEN);
cout << "存活 ";
}
else
{
if (ti == 0)
SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_RED);
else
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED);
cout << "已死亡 ";
}
}
if (ti == 0)
SetConsoleTextAttribute(handle, BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY);
else
SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
cout << endl;
for (int i = 7; i <= n; i++)
{
if (player[i].know == 0)
cout << "未知 ";
else if (player[i].know == 1)
{
if (player[i].name == "狼人 ")
cout << "狼人 ";
else
cout << "好人 ";
}
else if (player[i].know == 2)
cout << player[i].name << " ";
}
cout << endl << endl;
}
int shou = 0;
void shoushui(int hhh, int hhhh)
{
int x;
Sleep(3000);
system("cls");
print(hhh, hhhh);
cout << "守~卫~请~睁~眼~~~" << endl;
Sleep(3000);
system("cls");
print(hhh, hhhh);
if (MY == shouwei && player[MY].life == 1)
{
cout << "请问你要守护谁?" << endl << "输入:";
cin >> x;
while (x == shou || x<1 || x>n || player[x].life == 0)
{
cout << "输入错误,请重新输入" << endl << "输入:";
cin >> x;
}
shou = x;
}
else if (player[shouwei].life == 1)
{
cout << "请问你要守护谁?" << endl;
Sleep(rand() % 98);
srand(time(0));
x = rand() % n + 1;
while (x == shou || player[x].life == 0)
{
Sleep(rand() % 98);
srand(time(0));
x = rand() % n + 1;
}
shou = x;
}
else
{
cout << "请问你要守护谁?" << endl;
Sleep(3000);
shou = -1;
}
Sleep(3000);
system("cls");
print(hhh, hhhh);
cout << "守~卫~请~闭~眼~~~" << endl;
}
struct tou
{
int xxx;
int num;
int toupiaoquan;
};
tou TOU[13];
bool cmp(tou x, tou y)
{
if (x.xxx == y.xxx)
return x.num < y.num;
return x.xxx > y.xxx;
}
bool cmp1(tou x, tou y)
{
return x.num < y.num;
}
void toupiao(int ddd, int nnn)
{
//--------1--------
int x;
Sleep(2000);
system("cls");
print(ddd, nnn);
cout << "现在大家请投票";
for (int i = 1; i <= 3; i++)
{
cout << ".";
Sleep(500);
}
cout << endl;
for (int i = 1; i <= n; i++)
{
TOU[i].num = i;
TOU[i].toupiaoquan = 1;
TOU[i].xxx = 0;
}
for (int i = 1; i <= n; i++)
{
if (player[i].life == 1)
{
Sleep(3000);
if (i == MY)
{
cout << "请投票...(0弃权)" << endl;
cin >> x;
while (player[x].life == 0 && x != 0)
{
cin >> x;
}
if (x == 0)
cout << MY << "号玩家弃权" << endl;
else
cout << MY << "号玩家投给了" << x << "号玩家" << endl;
}
else
{
srand(time(0));
if (player[i].name == "狼人 ")
{
x = rand() % (n + 1);
while (x != 0 && (player[x].life == 0 || player[x].name == "狼人 " || x == i))
{
Sleep(rand() % 98);
srand(time(0));
x = rand() % (n + 1);
}
if (x == 0)
cout << i << "号玩家弃权" << endl;
else
cout << i << "号玩家投给了" << x << "号玩家" << endl;
}
else if (player[i].name == "预言家 ")
{
x = rand() % (n + 1);
while (x != 0 && (player[x].life == 0 || player[x].name != "狼人 " || x == i))
{
Sleep(rand() % 98);
srand(time(0));
x = rand() % (n + 1);
}
if (x == 0)
cout << i << "号玩家弃权" << endl;
else
cout << i << "号玩家投给了" << x << "号玩家" << endl;
}
else
{
x = rand() % (n + 1);
while (x != 0 && (player[x].life == 0 || x == i))
{
Sleep(rand() % 98);
srand(time(0));
x = rand() % (n + 1);
}
if (x == 0)
cout << i << "号玩家弃权" << endl;
else
cout << i << "号玩家投给了" << x << "号玩家" << endl;
}
}
if (x != 0)
TOU[x].xxx++;
}
}
Sleep(3000);
sort(TOU + 1, TOU + n + 1, cmp);
if (TOU[2].xxx != TOU[1].xxx)
{
cout << "投票结束," << TOU[1].num << "号投票出局" << endl;
player[TOU[1].num].life = 0;
player[TOU[1].num].how = 2;
Sleep(3000);
return;
}
else
{
TOU[1].toupiaoquan = 0;
TOU[2].toupiaoquan = 0;
system("cls");
print(ddd, nnn);
cout << TOU[1].num << "号," << TOU[2].num << "号";
int i;
for (i = 3; i <= n; i++)
{
if (TOU[i].xxx == TOU[1].xxx)
{
TOU[i].toupiaoquan = 0;
cout << "," << TOU[i].num << "号";
}
else
break;
}
if (i == n + 1)
{
for (int i = 1; i <= n; i++)
TOU[i].toupiaoquan = 1;
}
cout << "平票" << endl;
}
//--------2--------
sort(TOU + 1, TOU + n + 1, cmp1);
cout << "请再次投票";
for (int i = 1; i <= 3; i++)
{
cout << ".";
Sleep(500);
}
cout << endl;
for (int i = 1; i <= n; i++)
{
if (player[i].life == 1 && TOU[i].toupiaoquan == 1)
{
Sleep(3000);
if (i == MY)
{
cout << "请投票...(0弃权)" << endl;
cin >> x;
while ((player[x].life == 0 || TOU[x].toupiaoquan == 1) && x != 0)
{
cin >> x;
}
if (x == 0)
cout << MY << "号玩家弃权" << endl;
else
cout << MY << "号玩家投给了" << x << "号玩家" << endl;
}
else
{
srand(time(0));
if (player[i].name == "狼人 ")
{
x = rand() % (n + 1);
while (x != 0 && (player[x].life == 0 || player[x].name == "狼人 " || x == i || TOU[x].toupiaoquan == 1))
{
srand(time(0));
x = rand() % (n + 1);
}
if (x == 0)
cout << i << "号玩家弃权" << endl;
else
cout << i << "号玩家投给了" << x << "号玩家" << endl;
}
else if (player[i].name == "预言家 ")
{
x = rand() % (n + 1);
while (x != 0 && (player[x].life == 0 || player[x].name != "狼人 " || x == i || TOU[x].toupiaoquan == 1))
{
srand(time(0));
x = rand() % (n + 1);
}
if (x == 0)
cout << i << "号玩家弃权" << endl;
else
cout << i << "号玩家投给了" << x << "号玩家" << endl;
}
else
{
x = rand() % (n + 1);
while (x != 0 && (player[x].life == 0 || x == i || TOU[x].toupiaoquan == 1))
{
srand(time(0));
x = rand() % (n + 1);
}
if (x == 0)
cout << i << "号玩家弃权" << endl;
else
cout << i << "号玩家投给了" << x << "号玩家" << endl;
}
}
if (x != 0 && TOU[i].toupiaoquan == 1)
TOU[x].xxx++;
}
}
Sleep(3000);
sort(TOU + 1, TOU + n + 1, cmp);
if (TOU[2].xxx != TOU[1].xxx)
{
cout << "投票结束," << TOU[1].num << "号投票出局" << endl;
player[TOU[1].num].life = 0;
player[TOU[1].num].how = 2;
Sleep(3000);
return;
}
else
{
TOU[1].toupiaoquan = 0;
TOU[2].toupiaoquan = 0;
system("cls");
print(ddd, nnn);
cout << TOU[1].num << "号," << TOU[2].num << "号";
int i;
for (i = 3; i <= n; i++)
{
if (TOU[i].xxx == TOU[1].xxx)
{
TOU[i].toupiaoquan = 0;
cout << "," << TOU[i].num << "号";
}
else
break;
}
if (i == n + 1)
{
for (int i = 1; i <= n; i++)
TOU[i].toupiaoquan = 1;
}
cout << "平票" << endl;
}
//--------3--------
sort(TOU + 1, TOU + n + 1, cmp1);
cout << "请再次投票";
for (int i = 1; i <= 3; i++)
{
cout << ".";
Sleep(500);
}
cout << endl;
for (int i = 1; i <= n; i++)
{
if (player[i].life == 1 && TOU[i].toupiaoquan == 1)
{
Sleep(3000);
if (i == MY)
{
cout << "请投票...(0弃权)" << endl;
cin >> x;
while ((player[x].life == 0 || TOU[x].toupiaoquan == 1) && x != 0)
{
cin >> x;
}
if (x == 0)
cout << MY << "号玩家弃权" << endl;
else
cout << MY << "号玩家投给了" << x << "号玩家" << endl;
}
else
{
srand(time(0));
if (player[i].name == "狼人 ")
{
x = rand() % (n + 1);
while (x != 0 && (player[x].life == 0 || player[x].name == "狼人 " || x == i || TOU[x].toupiaoquan == 1))
{
srand(time(0));
x = rand() % (n + 1);
}
if (x == 0)
cout << i << "号玩家弃权" << endl;
else
cout << i << "号玩家投给了" << x << "号玩家" << endl;
}
else if (player[i].name == "预言家 " || player[i].name == "猎人 ")
{
x = rand() % (n + 1);
while (x != 0 && (player[x].life == 0 || player[x].name != "狼人 " || x == i || TOU[x].toupiaoquan == 1))
{
srand(time(0));
x = rand() % (n + 1);
}
if (x == 0)
cout << i << "号玩家弃权" << endl;
else
cout << i << "号玩家投给了" << x << "号玩家" << endl;
}
else
{
x = rand() % (n + 1);
while (x != 0 && (player[x].life == 0 || x == i || TOU[x].toupiaoquan == 1))
{
srand(time(0));
x = rand() % (n + 1);
}
if (x == 0)
cout << i << "号玩家弃权" << endl;
else
cout << i << "号玩家投给了" << x << "号玩家" << endl;
}
}
if (x != 0 && TOU[i].toupiaoquan == 1)
TOU[x].xxx++;
}
}
Sleep(3000);
sort(TOU + 1, TOU + n + 1, cmp);
if (TOU[2].xxx != TOU[1].xxx)
{
cout << "投票结束," << TOU[1].num << "号投票出局" << endl;
player[TOU[1].num].life = 0;
player[TOU[1].num].how = 2;
}
else
{
cout << "投票结束,无人出局" << endl;
}
Sleep(5000);
}
bool game_over()
{
int pingmin = 0;
int langren = 0;
int shenzhi = 0;
for (int i = 1; i <= n; i++)
{
if (player[i].life == 0)
continue;
if (player[i].name == "狼人 ")
langren++;
else if (player[i].name == "村民 ")
pingmin++;
else if (player[i].name == "女巫 " || player[i].name == "预言家 " || player[i].name == "猎人 ")
shenzhi++;
}
if (shenzhi == 0 || langren == 0 || pingmin == 0)
return 1;
return 0;
}
void night()
{
system("cls");
system("color 0f");
print(1, 1);
cout << "天~黑~请~闭~眼~~~" << endl;
if (n >= 12)
shoushui(1, 1);
Sleep(3000);
system("cls");
print(1, 1);
cout << "狼~人~请~睁~眼~~~" << endl;
if (player[MY].name == "狼人 ")
{
Sleep(1000);
cout << "你的同伴有:";
for (int i = 1; i <= n; i++)
{
if (i == MY)
continue;
if (player[i].name == "狼人 ")
{
cout << player[i].num << "号 ";
player[i].know = 2;
}
}
Sleep(3000);
cout << endl << "请问你们要杀谁:" << endl << "输入:";
cin >> kill1;
Sleep(1500);
system("cls");
print(1, 1);
cout << "今晚你们要杀的是" << kill1 << "号玩家" << endl;
}
else
{
Sleep(4000);
system("cls");
print(1, 1);
cout << "请问你们要杀谁?" << endl;
do
{
Sleep(rand() % 18);
srand(time(0));
int x = rand() % n + 1;
if (player[x].name != "狼人 " && player[x].life == 1)
{
kill1 = x;
break;
}
} while (1);
Sleep(5000);
}
Sleep(3000);
system("cls");
print(1, 1);
cout << "狼~人~请~闭~眼~~~" << endl;
Sleep(2000);
system("cls");
print(1, 1);
cout << "女~巫~请~睁~眼~~~" << endl;
Sleep(2000);
system("cls");
print(1, 1);
if (player[MY].name == "女巫 " && player[MY].life == 1)
{
Sleep(1000);
if (jieyao == 1)
{
cout << "今晚" << kill1 << "号玩家被杀" << endl;
Sleep(500);
cout << "请问你要救吗???" << endl << "A. 救 B.不救" << endl << "输入:";
cin >> a;
if (a == 'A')
{
system("cls");
print(1, 1);
cout << "请问你要毒吗???" << endl;
Sleep(2000);
system("cls");
print(1, 1);
cout << "今晚" << kill1 << "号玩家被你解救" << endl;
jieyao = 0;
if (shou != kill1)
kill1 = 0;
}
else
{
if (shou == kill1)
kill1 = 0;
Sleep(2000);
system("cls");
print(1, 1);
cout << "请问你要毒吗???" << endl << "A. 毒 B.不毒" << endl << "输入:";
cin >> a;
if (a == 'A')
{
cout << "请问你要毒谁???" << endl << "输入:";
cin >> kill2;
while (player[kill2].life != 1)
{
cout << "输入错误,请重新输入:" << endl;
cin >> kill2;
}
duyao = 0;
}
}
}
else
{
if (shou == kill1)
kill1 = 0;
Sleep(2000);
system("cls");
print(1, 1);
cout << "请问你要毒吗???" << endl << "A. 毒 B.不毒" << endl << "输入:";
cin >> a;
if (a == 'A')
{
cout << "请问你要毒谁???" << endl << "输入:";
cin >> kill2;
while (player[kill2].life != 1)
{
cout << "输入错误,请重新输入:" << endl;
cin >> kill2;
}
duyao = 0;
}
}
}
else
{
bool b = 0;
cout << "请问你是否要用解药???" << endl;
int FFF = 0, kkkk;
for (int i = 1; i <= n; i++)
{
if (player[i].life == 1 && player[i].name == "村民 ")
FFF++;
if (player[i].name == "女巫 ")
kkkk = i;
}
if (jieyao == 1 && player[kkkk].life == 1)
{
if (FFF == 1)
{
if (shou == kill1)
jieyao = 1;
else
jieyao = 0;
kill1 = 0;
b = 1;
}
else
for (int i = 1; i <= n; i++)
{
if (player[i].name == "女巫 " && kill1 == i)
{
kill1 = 0;
if (shou == kill1)
jieyao = 1;
else
jieyao = 0;
b = 1;
break;
}
else if (player[i].name == "预言家 " && kill1 == i)
{
kill1 = 0;
if (shou == kill1)
jieyao = 1;
else
jieyao = 0;
b = 1;
break;
}
}
}
Sleep(3000);
if (b == 0 && duyao == 1 && player[kkkk].life == 1)
{
system("cls");
print(1, 1);
cout << "请问你是否要用毒药???" << endl;
srand(time(0));
int x = rand() % 2;
Sleep(1500);
cout << "请问你要毒谁???" << endl;
if (x == 1)
{
duyao = 0;
int y = rand() % n + 1;
while ((player[y].name == "女巫 " || player[y].name == "预言家 " || y == kill1) || player[y].life == 0)
y = rand() % n + 1;
kill2 = y;
}
}
else
{
Sleep(3000);
system("cls");
print(1, 1);
cout << "请问你是否要用毒药???" << endl;
Sleep(3000);
cout << "请问你要毒谁???" << endl;
Sleep(3000);
}
}
Sleep(3000);
system("cls");
print(1, 1);
cout << "女~巫~请~闭~眼~~~" << endl;
if (n > 6)
{
Sleep(3000);
system("cls");
print(1, 1);
cout << "预~言~家~请~睁~眼~~~" << endl;
if (player[MY].name == "预言家 ")
{
Sleep(3000);
cout << "请问你想查验谁???" << endl << "输入:";
int x;
cin >> x;
player[x].know = 1;
Sleep(2000);
system("cls");
print(1, 1);
cout << "他的身份是:";
if (player[x].name == "狼人 ")
cout << "狼人" << endl;
else
cout << "好人" << endl;
Sleep(3000);
}
else
{
Sleep(3000);
cout << "请问你想查验谁???" << endl;
Sleep(3000);
system("cls");
print(1, 1);
cout << "他的身份是:......";
Sleep(3000);
}
Sleep(3000);
system("cls");
print(1, 1);
cout << "预~言~家~请~闭~眼~~~" << endl;
}
Sleep(3000);
if (kill1 != 0)
player[kill1].life = 0;
if (kill2 != 0)
player[kill2].life = 0;
player[kill1].how = 1;
player[kill2].how = 3;
system("cls");
system("color F0");
print(2, 0);
}
void night2(int hhh, int hhhh)
{
system("cls");
system("color 0f");
print(hhh, hhhh);
cout << "天~黑~请~闭~眼~~~" << endl;
if (n >= 12)
shoushui(hhh, hhhh);
Sleep(3000);
system("cls");
print(hhh, hhhh);
cout << "狼~人~请~睁~眼~~~" << endl;
if (player[MY].name == "狼人 " && player[MY].life == 1)
{
Sleep(3000);
cout << endl << "请问你们要杀谁:" << endl << "输入:";
cin >> kill1;
Sleep(1500);
system("cls");
print(hhh, hhhh);
cout << "今晚你们要杀的是" << kill1 << "号玩家" << endl;
}
else
{
Sleep(4000);
system("cls");
print(hhh, hhhh);
cout << "请问你们要杀谁?" << endl;
do
{
srand(time(0));
int x = rand() % n + 1;
if (player[x].name != "狼人 " && player[x].life == 1)
{
kill1 = x;
break;
}
} while (1);
Sleep(5000);
}
Sleep(3000);
system("cls");
print(hhh, hhhh);
cout << "狼~人~请~闭~眼~~~" << endl;
Sleep(2000);
system("cls");
print(hhh, hhhh);
cout << "女~巫~请~睁~眼~~~" << endl;
Sleep(2000);
system("cls");
print(hhh, hhhh);
if (player[MY].name == "女巫 " && player[MY].life == 1)
{
Sleep(1000);
if (jieyao == 1)
{
cout << "今晚" << kill1 << "号玩家被杀" << endl;
Sleep(500);
cout << "请问你要救吗???" << endl << "A. 救 B.不救" << endl << "输入:";
cin >> a;
if (a == 'A')
{
system("cls");
print(hhh, hhhh);
cout << "请问你要毒吗???" << endl;
Sleep(2000);
system("cls");
print(hhh, hhhh);
cout << "今晚" << kill1 << "号玩家被你解救" << endl;
jieyao = 0;
if (shou != kill1)
kill1 = 0;
}
else
{
if (shou == kill1)
kill1 = 0;
Sleep(2000);
system("cls");
print(hhh, hhhh);
cout << "请问你要毒吗???" << endl << "A. 毒 B.不毒" << endl << "输入:";
cin >> a;
if (a == 'A')
{
cout << "请问你要毒谁???" << endl << "输入:";
cin >> kill2;
while (player[kill2].life != 1)
{
cout << "输入错误,请重新输入:" << endl;
cin >> kill2;
}
duyao = 0;
}
}
}
else if (duyao == 1)
{
if (shou == kill1)
kill1 = 0;
Sleep(2000);
system("cls");
print(hhh, hhhh);
cout << "请问你要毒吗???" << endl << "A. 毒 B.不毒" << endl << "输入:";
cin >> a;
if (a == 'A')
{
cout << "请问你要毒谁???" << endl << "输入:";
cin >> kill2;
while (player[kill2].life != 1)
{
cout << "输入错误,请重新输入:" << endl;
cin >> kill2;
}
duyao = 0;
}
}
else
{
Sleep(2000);
system("cls");
print(hhh, hhhh);
cout << "请问你要毒吗???" << endl;
}
}
else
{
bool b = 0;
cout << "请问你是否要用解药???" << endl;
int FFF = 0, kkkk;
for (int i = 1; i <= n; i++)
{
if (player[i].life == 1 && player[i].name == "村民 ")
FFF++;
if (player[i].name == "女巫 ")
kkkk = i;
}
if (jieyao == 1 && player[kkkk].life == 1)
{
if (FFF == 1)
{
if (shou == kill1)
jieyao = 1;
else
jieyao = 0;
kill1 = 0;
b = 1;
}
else
for (int i = 1; i <= n; i++)
{
if (player[i].name == "女巫 " && kill1 == i)
{
kill1 = 0;
if (shou == kill1)
jieyao = 1;
else
jieyao = 0;
b = 1;
break;
}
else if (player[i].name == "预言家 " && kill1 == i)
{
kill1 = 0;
if (shou == kill1)
jieyao = 1;
else
jieyao = 0;
b = 1;
break;
}
}
}
Sleep(3000);
if (b == 0 && duyao == 1 && player[kkkk].life == 1)
{
system("cls");
print(hhh, hhhh);
cout << "请问你是否要用毒药???" << endl;
srand(time(0));
int x = rand() % 2;
Sleep(1500);
cout << "请问你要毒谁???" << endl;
if (x == 1)
{
duyao = 0;
int y = rand() % n + 1;
while ((player[y].name == "女巫 " || player[y].name == "预言家 " || y == kill1) || player[y].life == 0)
y = rand() % n + 1;
kill2 = y;
}
}
else
{
Sleep(3000);
system("cls");
print(hhh, hhhh);
cout << "请问你是否要用毒药???" << endl;
Sleep(3000);
cout << "请问你要毒谁???" << endl;
Sleep(3000);
}
}
Sleep(3000);
system("cls");
print(hhh, hhhh);
cout << "女~巫~请~闭~眼~~~" << endl;
if (n > 6)
{
Sleep(3000);
system("cls");
print(hhh, hhhh);
cout << "预~言~家~请~睁~眼~~~" << endl;
if (player[MY].name == "预言家 " && player[MY].life == 1)
{
Sleep(3000);
cout << "请问你想查验谁???" << endl << "输入:";
int x;
cin >> x;
player[x].know = 1;
Sleep(2000);
system("cls");
print(hhh, hhhh);
cout << "他的身份是:";
if (player[x].name == "狼人 ")
cout << "狼人" << endl;
else
cout << "好人" << endl;
Sleep(3000);
}
else
{
Sleep(3000);
cout << "请问你想查验谁???" << endl;
Sleep(3000);
system("cls");
print(hhh, hhhh);
cout << "他的身份是:......";
Sleep(3000);
}
Sleep(3000);
system("cls");
print(hhh, hhhh);
cout << "预~言~家~请~闭~眼~~~" << endl;
}
Sleep(3000);
if (kill1 != 0)
player[kill1].life = 0;
if (kill2 != 0)
player[kill2].life = 0;
player[kill1].how = 1;
player[kill2].how = 3;
system("cls");
system("color F0");
print(hhh + 1, 0);
}
bool lr = 0;
void panduanlieren()
{
if (lr == 1)
return;
if (MY == lieren)
{
cout << "请射杀一名玩家" << endl;
int x;
cin >> x;
while (player[x].life != 1)
{
cout << "输入错误,请重新输入" << endl;
cin >> x;
}
Sleep(1000);
cout << lieren << "号猎人发动技能,开枪带走了" << x << "号" << endl;
player[x].life = 0;
player[x].how = 4;
}
else if (n >= 9)
{
srand(time(0));
int x = rand() % n + 1;
while (player[x].life != 1)
{
x = rand() % n + 1;
}
Sleep(1000);
cout << lieren << "号猎人发动技能,开枪带走了" << x << "号" << endl;
player[x].life = 0;
player[x].how = 4;
}
lr = 1;
}
void print1()
{
cout << "天亮了,昨晚";
if (kill1 != 0 || kill2 != 0)
{
cout << kill1 << "号";
if (kill2 != 0)
{
cout << "," << kill2 << "号";
kill2 = 0;
}
cout << "被杀" << endl;
}
else
cout << "是平安夜" << endl;
}
int game()
{
system("cls");
cout << " " << "狼人杀online" << endl;
cout << "请输入人数个数:" << endl;
// scanf("%d", &n);
n = num;
cout << "加载时间长,请耐心等待";
init2(n);
int k = 1;
do
{
srand(time(0));
init3(k);
cout << ".";
// Sleep(17);
k++;
} while (k <= n);
system("cls");
system("color F0");
cout << "游戏即将开始";
// for (int i = 1; i <= 6; i++)
// {
// cout << ".";
// Sleep(500);
// }
// Sleep(1500);
cout << endl << endl << "请大家查看身份牌......" << endl;
// Sleep(45);
srand(time(0));
MY = rand() % n + 1;
cout << "您的身份是:" << player[MY].name << endl;
Sleep(500);
cout << "在" << player[MY].num << "号位上" << endl;
cout<<player[MY].name<<wan;
if(player[MY].name != wan){
// if(getch() != ' ')
return 0;
}
system("cls");
player[MY].know = 2;
print(1, 0);
cout << "即将进入夜晚";
for (int i = 1; i <= 6; i++)
{
cout << ".";
Sleep(500);
}
night();
print1();
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
if (player[lieren].life == 0 && lr == 0)
{
panduanlieren();
}
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
toupiao(2, 0);
system("cls");
print(2, 0);
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
else if (player[lieren].life == 0 && lr == 0)
{
panduanlieren();
}
cout << "即将进入夜晚";
for (int i = 1; i <= 6; i++)
{
cout << ".";
Sleep(500);
}
night2(2, 1);
print1();
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
if (player[lieren].life == 0 && lr == 0)
{
panduanlieren();
}
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
toupiao(3, 0);
system("cls");
print(3, 0);
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
else if (player[lieren].life == 0 && lr == 0)
{
panduanlieren();
}
cout << "即将进入夜晚";
for (int i = 1; i <= 6; i++)
{
cout << ".";
Sleep(500);
}
night2(3, 1);
print1();
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
if (player[lieren].life == 0)
{
panduanlieren();
}
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
toupiao(4, 0);
system("cls");
print(4, 0);
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
else if (player[lieren].life == 0 && lr == 0)
{
panduanlieren();
}
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
cout << "即将进入夜晚";
for (int i = 1; i <= 6; i++)
{
cout << ".";
Sleep(500);
}
night2(4, 1);
print1();
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
if (player[lieren].life == 0)
{
panduanlieren();
}
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
toupiao(5, 0);
system("cls");
print(5, 0);
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
else if (player[lieren].life == 0 && lr == 0)
{
panduanlieren();
}
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
cout << "即将进入夜晚";
for (int i = 1; i <= 6; i++)
{
cout << ".";
Sleep(500);
}
night2(5, 1);
print1();
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
if (player[lieren].life == 0)
{
panduanlieren();
}
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
toupiao(6, 0);
system("cls");
print(6, 0);
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
else if (player[lieren].life == 0 && lr == 0)
{
panduanlieren();
}
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
cout << "即将进入夜晚";
for (int i = 1; i <= 6; i++)
{
cout << ".";
Sleep(500);
}
night2(6, 1);
print1();
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
if (player[lieren].life == 0)
{
panduanlieren();
}
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
toupiao(7, 0);
system("cls");
print(7, 0);
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
else if (player[lieren].life == 0 && lr == 0)
{
panduanlieren();
}
if (game_over())
{
Sleep(1000);
system("cls");
cout << "游戏结束" << endl; printhhh();
return 0;
}
while (1)
system("pause");
return 0;
}
int main(){
init1();
cin>>wan>>num;
wan += " ";
while(true){
game();
}
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/saigonshu/algorithm.git
git@gitee.com:saigonshu/algorithm.git
saigonshu
algorithm
Algorithms
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385