谁是卧底(更新版)
tanruiqing · · 个人记录
dev-c++可以编译,请放心使用。。。
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#define int long long
using namespace std;
const int N = 35;
int n;
bool vis[N];
string a, b, s[N];
void print(string s){
int len = s.size();
for(int i = 0; i < len; ++i){
cout << s[i];
Sleep(10);
}
return ;
}
signed main(){
srand(time(0));
//ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
print("欢迎来到“谁是卧底”\n这个游戏不太一样,平民只有一次猜的机会\n若猜中的是卧底,则平民胜利,反之卧底胜利。");
cout << "\n请输入任何键继续......\n";
char _0;
_0 = _getch();
system("cls");
int pm = 0,lr = 0; //pm是平民,lr是狼人。
print("请输入玩的人数:");
while(cin >> n){
if(n >= 3 && n <= 30){
break;
}
else{
system("cls");
print("请输入玩的人数:");
}
}
system("cls");
print("请输入2个长度小于等于18的单词(不许带空格):");
cin >> a >> b;
system("cls");
int _ = rand() % 32000;
if(_ % 2 == 0) swap(a, b);
int ci = 0;
if(n >= 3 && n <= 6){
ci = 1;
pm = n - 1;
}
else if(n > 6 && n <= 12){
ci = 2;
pm = n - 2;
}
else{
ci = 3;
pm = n - 3;
}
//指定狼人和平民的人数。
for(int i = 1; i <= n; ++i){
s[i] = a;//假设全部是平民。
}
for(int i = 1; i <= ci; ++i){
int __ = rand() % n + 1;//指定哪个人是狼人。
s[__] = b;
}
for(int i = 1; i <= n; ++i){
cout << "--------------------\n";
cout << "| |\n";
cout << "| |\n";
cout << "| |\n";
cout << "|不要被别人看见了哦|\n";
cout << "| |\n";
cout << "| |\n";
cout << "| |\n";
cout << "--------------------\n\n";
cout << "请输入任何键继续......\n";
char _0;
_0 = _getch();
system("cls");
cout << "--------------------\n";
cout << "| |\n";
cout << "| |\n";
cout << "| |\n|";
int len = s[i].length();
int kglen = 18 - len;
for(int j = 1; j <= (kglen + 1) / 2; ++j) cout << ' ';
cout << s[i];
for(int j = 1; j <= kglen / 2; ++j) cout << ' ';
cout << "|\n| |\n";
cout << "| |\n";
cout << "| |\n";
cout << "--------------------\n";
cout << "请输入任何键继续......\n";
_0 = _getch();
system("cls");
}
lr = ci;
while(true){
print("\n!!!发言环节!!!\n你们投几号:");
int _1;
cin >> _1;
if(_1 <= 0 || _1 > n){
system("cls");
MessageBox(NULL, "This number has exceeded the range, please re-enter...", "wrong", MB_OK|MB_ICONHAND);
}
else if(vis[_1] == 1){
system("cls");
MessageBox(NULL, "This person has already been eliminated...", "wrong", MB_OK|MB_ICONHAND);
}
else{
vis[_1] = 1;
if(s[_1] == b){
lr--;
}
else{
pm--;
}
cout << _1;
print("的身份是:");
if(s[_1] == b)print("狼人\n");
else print("平民\n");
print("TA以出局,请不要再进行游戏...\n");
cout << "请输入任何键继续......\n";
char _0;
_0 = _getch();
if(lr == 0){
print("狼人全部淘汰,平民胜利!");
return 0;
}else if(pm <= 2){
print("平民只剩不到2人,狼人胜利!");
return 0;
}
}
}
return 0;
}