-
个人简介
T1170??? (自己编的扫雷)
#include<bits/stdc++.h> using namespace std;//如果想知道答案,把代码中/* */删除 int bian,leishu,mailei=7,zong,siwang=1,hang,lie,zhouwei,hao,jishu,huan,dian,biaoji; int main() { printf("扫雷规则:\n先输入边长n(格子为n*n)与雷数,中间用空格隔开\n"); scanf("%d%d",&bian,&leishu); printf("等待'尝试次数'显示后再扫\n"); printf("扫雷时先输入一个大写字母A,B或C\n其中A=标记雷,B=解除标记,C=开这个点\n"); printf("然后输入空格,注意以左上角为原点,接着输入行空格最后列\n"); printf("结束条件:点出所有雷或 点出所有空格或 已点的雷+标记的雷=所有雷\n"); printf("注意,!为雷,~为标记,*为没有开的位置,数字代表九宫格内雷数\n"); char ju[bian][bian],lei[bian][bian]; for(int i=0;i<bian;i++) { for(int j=0;j<bian;j++) { ju[i][j]='*'; lei[i][j]='*'; } }//基本 for(int i=0;i<bian;i++) { for(int j=0;j<bian;j++) printf("%c ",ju[i][j]); printf("\n"); }//基本 printf("\n"); if(leishu>bian*bian/2) { leishu=bian*bian-leishu; huan=1; } zong=(bian+1)*(bian+1);//边界 for(int i=1;;i++) { mailei=mailei*(i+520)*7%zong+7; if(lei[mailei%bian][mailei-mailei%bian*bian]=='*') lei[mailei%bian][mailei-mailei%bian*bian]='!'; if(i>=leishu) { for(int j=0;j<bian;j++) { for(int k=0;k<bian;k++) { if(lei[j][k]=='!') jishu++; } } } if(jishu==leishu) break; jishu=0; }//埋雷 for(int i=0;i<bian;i++) { for(int j=0;j<bian;j++) ju[i][j]='*'; }//基本 if(huan==1) { leishu=bian*bian-leishu; for(int i=0;i<bian;i++) { for(int j=0;j<bian;j++) { if(lei[i][j]=='*') lei[i][j]='!'; else if(lei[i][j]=='!') lei[i][j]='*'; } } }//换雷 /* for(int i=0;i<bian;i++) { for(int j=0;j<bian;j++) printf("%c ",lei[i][j]); printf("\n"); }//答案*/ printf("尝试次数:1\n"); for(int z=1;;z++) { char caozuo; scanf("%c%d%d",&caozuo,&hang,&lie); hang--; lie--; if(caozuo=='A') { if(ju[hang][lie]=='*') ju[hang][lie]='~'; for(int i=0;i<bian;i++) { for(int j=0;j<bian;j++) printf("%c ",ju[i][j]); printf("\n"); } } if(caozuo=='B') { if(ju[hang][lie]=='~') ju[hang][lie]='*'; for(int i=0;i<bian;i++) { for(int j=0;j<bian;j++) printf("%c ",ju[i][j]); printf("\n"); } } if(caozuo=='C') { dian++; ju[hang][lie]=lei[hang][lie]; if(lei[hang][lie]=='!') { siwang++; printf("尝试次数:%d\n",siwang); for(int i=0;i<bian;i++) { for(int j=0;j<bian;j++) printf("%c ",ju[i][j]); printf("\n"); } printf("\n"); } if(lei[hang][lie]=='*') { hao++; bian--; if(lei[hang-1][lie]=='!'&&hang-1<=bian&&lie<=bian&&hang-1>=0&&lie>=0) zhouwei++; if(lei[hang+1][lie]=='!'&&hang+1<=bian&&lie<=bian&&hang+1>=0&&lie>=0) zhouwei++; if(lei[hang][lie-1]=='!'&&hang<=bian&&lie-1<=bian&&hang>=0&&lie-1>=0) zhouwei++; if(lei[hang][lie+1]=='!'&&hang<=bian&&lie+1<=bian&&hang>=0&&lie+1>=0) zhouwei++; if(lei[hang-1][lie-1]=='!'&&hang-1<=bian&&lie-1<=bian&&hang-1>=0&&lie-1>=0) zhouwei++; if(lei[hang+1][lie-1]=='!'&&hang+1<=bian&&lie-1<=bian&&hang+1>=0&&lie-1>=0) zhouwei++; if(lei[hang-1][lie+1]=='!'&&hang-1<=bian&&lie+1<=bian&&hang-1>=0&&lie+1>=0) zhouwei++; if(lei[hang+1][lie+1]=='!'&&hang+1<=bian&&lie+1<=bian&&hang+1>=0&&lie+1>=0) zhouwei++; if(zhouwei==0) ju[hang][lie]='0'; if(zhouwei==1) ju[hang][lie]='1'; if(zhouwei==2) ju[hang][lie]='2'; if(zhouwei==3) ju[hang][lie]='3'; if(zhouwei==4) ju[hang][lie]='4'; if(zhouwei==5) ju[hang][lie]='5'; if(zhouwei==6) ju[hang][lie]='6'; if(zhouwei==7) ju[hang][lie]='7'; if(zhouwei==8) ju[hang][lie]='8'; zhouwei=0; bian++; for(int i=0;i<bian;i++) { for(int j=0;j<bian;j++) printf("%c ",ju[i][j]); printf("\n"); } } } if(siwang==leishu+1) { printf("雷已点完,剩余无雷处:%d 尝试次数%d",bian*bian-dian,siwang); break; } else if(hao==bian*bian-leishu) { printf("无雷处已点完,尝试次数:%d",siwang); break; } else { for(int m=0;m<bian;m++) { for(int n=0;n<bian;n++) { if(lei[m][n]=='!'&&ju[m][n]=='~') biaoji++; } } if(biaoji+siwang-1==leishu) { printf("满足最后一个胜利条件,尝试次数:%d",siwang); break; } biaoji=0; } }//扫 return 0; }
逆天狼人杀,但是不完美
#include<bits/stdc++.h> #include<cstdio> #include<cstdlib> #include<ctime> #include<windows.h> using namespace std; struct Iname { int geshu; string NAME; }; Iname jue_se[100]; struct ID { int num; bool life; string name; int know; int how; }; ID player[65]; int n, MY, kill1, kill2; char a; bool jieyao = 1, duyao = 1; //女巫道具 int lieren, shouwei = 0 //,tianshi ,emo ,xingyuner , //特殊角色 ; 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 = "守卫 "; // jue_se[7].NAME = "天使 "; // jue_se[8].NAME = "恶魔"; // jue_se[9].NAME = "幸运儿"; // jue_se[10].NAME = ""; // jue_se[11].NAME = ""; // jue_se[12].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; // case : // jue_se[1] .geshu =; // jue_se[2] .geshu =; // jue_se[3] .geshu =; // jue_se[4] .geshu =; // jue_se[5] .geshu =; // jue_se[6] .geshu =; // jue_se[7] .geshu =; // jue_se[8] .geshu =; // jue_se[9] .geshu =; // jue_se[10] .geshu =; // jue_se[11] .geshu =; // jue_se[12] .geshu =; // jue_se[13] .geshu =; // jue_se[14] .geshu =; 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; // else if (nn <= 64) // x = x % 8 + 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; // if (player[nn].name =="天使") // ==nn; // if (player[nn].name =="恶魔") // ==nn; // if (player[nn].name =="") // ==nn; // if (player[nn].name =="") // ==nn; // if (player[nn].name =="") // ==nn; // if (player[nn].name =="") // ==nn; // if (player[nn].name =="") // ==nn; // if (player[nn].name =="") // ==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 if() // 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; // else if (player[i].how ==5) // cout<<"最终被" << endl; // else if (player[i].how ==6) // cout<<"最终被" << endl; // else if (player[i].how ==7) // 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<< endl; } else { Sleep(4000); system("cls"); print(1, 1); cout << "请问你们要杀谁?" << endl<< 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<< endl; Sleep(2000); system("cls"); print(1, 1); cout << "女巫~请~睁~眼~~~" << endl<< endl; Sleep(2000); system("cls"); print(1, 1); if (player[MY].name == "女巫 " && player[MY].life == 1) { Sleep(1000); if (jieyao == 1) { cout << "今晚" << kill1 << "号玩家被杀" << endl<< endl; Sleep(500); cout << "请问你要救吗???" << endl << "A. 救 B.不救" << endl << "输入:"; cin >> a; if (a == 'A') { system("cls"); print(1, 1); cout << "请问你要毒吗???" << endl<< 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 main() { system("cls"); cout << " " << "狼人杀online" << endl; cout << "请输入人数个数:" << endl; scanf("%d", &n); cout << "加载时间长,请耐心等待"; init1(); 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; system("pause"); 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; }
-
通过的题目
- P01
- P02
- P03
- P04
- P05
- P06
- P07
- P08
- P09
- P10
- P11
- P12
- P13
- P20
- P23
- P36
- P40
- P61
- P63
- P70
- P72
- P89
- P110
- P112
- P115
- P119
- P125
- P126
- P131
- P135
- P136
- P138
- P139
- P140
- P142
- P143
- P146
- P147
- P155
- P156
- P159
- P164
- P169
- P178
- P204
- P205
- P214
- P217
- P228
- P231
- P244
- P247
- P251
- P261
- P267
- P269
- P271
- P289
- P301
- P302
- P303
- P304
- P305
- P306
- P307
- P308
- P309
- P310
- P311
- P312
- P313
- P314
- P315
- P316
- P317
- P318
- P319
- P320
- P321
- P322
- P323
- P324
- P325
- P326
- P327
- P328
- P329
- P330
- P331
- P332
- P333
- P334
- P335
- P336
- P337
- P338
- P339
- P340
- P341
- P342
- P343
- P344
- P345
- P346
- P347
- P348
- P349
- P350
- P352
- P353
- P354
- P355
- P356
- P357
- P358
- P359
- P360
- P361
- P362
- P363
- P364
- P365
- P366
- P367
- P368
- P369
- P370
- P371
- P372
- P373
- P374
- P375
- P376
- P377
- P378
- P379
- P380
- P381
- P382
- P383
- P384
- P385
- P386
- P387
- P388
- P389
- P390
- P391
- P392
- P393
- P394
- P395
- P396
- P397
- P398
- P399
- P400
- P401
- P402
- P403
- P404
- P405
- P406
- P407
- P408
- P409
- P410
- P411
- P412
- P413
- P415
- P416
- P417
- P419
- P420
- P421
- P423
- P424
- P425
- P426
- P428
- P429
- P430
- P431
- P432
- P434
- P435
- P436
- P437
- P438
- P439
- P440
- P441
- P442
- P443
- P444
- P445
- P446
- P448
- P449
- P451
- P457
- P462
- P463
- P464
- P466
- P467
- P470
- P471
- P476
- P481
- P484
- P490
- P491
- P492
- P493
- P494
- P495
- P501
- P514
- P517
- P518
- P519
- 520
- P521
- P522
- P527
- P529
- P531
- P532
- P533
- P558
- P599
- P690
- P691
- P692
- P701
- P703
- P710
- P732
- P739
- P755
- P756
- P776
- P784
- P799
- P855
- P884
- P899
- P900
- P939
- P941
- P953
- P969
- P992
- P1001
- P1002
- P1003
- P1005
- P1011
- P1012
- P1016
- P1017
- P1078
- P1118
- P1121
- P1127
- P1166
- P1200
- P1243
- P1244
- P1261
- P1281
- P1305
- P1312
- P1323
- P1325
- P1326
- P1331
- P1349
- P1366
- P1451
- P1471
- P1478
- P1498
- P1539
- P1566
- P1567
- P351
- P1576
- P1600
- P1617
- P1636
- P1638
- P1639
- P1663
- P1664
- P1680
- P1681
- P1684
- P1706
- P1739
- P1742
- P1743
- P1747
- P1748
- P1753
- P1754
- P1755
- P1756
- P1757
- P1761
- P1764
- P1765
- P1766
- P1767
- P1769
- P1770
- P1772
- P1774
- P1775
- P1776
- P1778
- P1783
- P1784
- P1785
- P1786
- P1787
- P1793
- P1796
- P1799
- P1807
- P1831
- P1968
- P1974
- P1975
- P1999
- P2002
- P2012
- P2015
- P2018
- P2021
- P2024
- P2027
- P2055
- P2091
- P2092
- P2093
- P2095
- P2096
- P2098
- P2099
- P2101
- P2102
- P2104
- P2105
- P2106
- P2107
- P2108
- P2109
- P2110
- P2111
- P2112
- P2113
- P2114
- P2116
- P2117
- P2118
- P2119
- P2121
- P2122
- P2123
- P2124
- P2125
- P2126
- P2127
- P2128
- P2129
- P2131
- P2132
- P2133
- P2134
- P2136
- P2137
- P2138
- P2143
- P2144
- P2145
- P2149
- P2152
- P2153
- P2155
- P2156
- P2157
- P2161
- P2165
- P2174
- P2176
- P2184
- P2189
-
最近活动
-
最近编写的题解
题目标签
- 基础算法
- 62
- 课课通
- 49
- 动态规划
- 35
- 其他
- 35
- 贪心
- 30
- 模拟
- 24
- 数组
- 23
- USACO
- 20
- 省赛
- 18
- 江苏
- 18
- 字符串
- 17
- 普及组
- 16
- 提高组
- 16
- 分治
- 16
- 搜索
- 15
- 排序
- 15
- 递推
- 14
- 数据结构
- 13
- 高精度
- 8
- 背包
- 8