ARTICLE DETAIL

建站实战干货

来自一线的建站与推广经验沉淀,每一条都经过真实交付验证。

谁是卧底 C++三人版

2026/8/20 21:44:01 拓冰建站 浏览量
谁是卧底 C++三人版 好像很久没有发博文了这次来搞一把。谁是卧底三人版闪亮登场一、简介谁是卧底这个游戏很多人应该都是玩过的。游戏的规则就是选一个卧底词和N-1N玩家数量个平民词两个平民词需要一样卧底词和平民词则必须不一样悄声报给玩家。进入描述环节后玩家描述该词。最后玩家们各自投出自己认为谁是卧底票数最多者如果为卧底则判定为平民胜利若为平民则依玩家人数而定玩家人数为3人时则判定为卧底胜利。玩家人数大于3时则该平民出局游戏继续最后进行到第二或第三局时仍出现该情况则卧底胜利。这个程序是供三人使用。废话多说上代码二、代码#includestring #includectime #includecstdlib #includeiostream #includestdlib.h #includeconio.h using namespace std; class whoistheundercoveragent{ private: int undercovernumber,setnumber; string civilianword,undercoverword; long long thepersonwhoreceivedthemostvotes; public: void randomlydeterminethecorrespondingwordsforvariousidentities(){ srand(time(0)); setnumberrand()%201; switch(setnumber){ case 1: civilianword医生; undercoverword护士; break; case 2: civilianword苹果; undercoverword红蛇果; break; case 3: civilianword篮球; undercoverword排球; break; case 4: civilianword芹菜; undercoverword西芹; break; case 5: civilianword日记; undercoverword作文; break; case 6: civilianword人财两空; undercoverword穷困潦倒; break; case 7: civilianword导弹; undercoverword氢弹; break; case 8: civilianword美丽; undercoverword漂亮; break; case 9: civilianword浴缸; undercoverword澡盆; break; case 10: civilianword美利坚合众国; undercoverword中华人民共和国; break; case 11: civilianword敖丙; undercoverword哪吒; break; case 12: civilianword魔术; undercoverword魔法; break; case 13: civilianword鲨鱼; undercoverword鲸; break; case 14: civilianword降服; undercoverword降伏; break; case 15: civilianword智商; undercoverword情商; break; case 16: civilianword吉安; undercoverword安吉; break; case 17: civilianword计算机; undercoverword计算器; break; case 18: civilianword台风; undercoverword飓风; break; case 19: civilianword字典; undercoverword词典; break; case 20: civilianword宫; undercoverword殿; break; } } void reportwords(){ srand(time(0)); undercovernumberrand()%31; randomlydeterminethecorrespondingwordsforvariousidentities(); for(int playernumber1;playernumber3;playernumber){ cout不要让别人偷看哦endl你是playernumber号玩家请按回车键看词...; cin.ignore(); coutendl你的词语是; if(undercovernumber!playernumber){ coutcivilianwordendl; }else{ coutundercoverwordendl; } cout看完请按回车键...; cin.ignore(); system(cls); } } void speechsecion(){ cout发言环节描述你所看到的词语吧endl需开始投票请按回车键...; cin.ignore(); } void votingsession(){ do{ system(cls); cout投票环节投出获票最多的人endl获票最多的人; cinthepersonwhoreceivedthemostvotes; }while(thepersonwhoreceivedthemostvotes1||thepersonwhoreceivedthemostvotes3); } void determinethewinnerorloser(){ votingsession(); system(cls); system(color E0); if(thepersonwhoreceivedthemostvotesundercovernumber){ cout平民胜利endl; }else{ cout卧底胜利endlundercovernumber号玩家是卧底。endl; } } void run(){ reportwords(); speechsecion(); determinethewinnerorloser(); } }; int main(){ whoistheundercoveragent game; game.run(); cout还想再来玩一局重新运行程序吧endl; system(pause); return 0; }代码共计151行3596个字符。有一些变量名或函数名长度较高可自行简化。三、运行结果按以前我肯定是要写运行结果的但是由于此次有大量的输入故请自行运行。