我的狼人杀程序

最近感觉CSDN上自编的狼人杀太烂了,于是自己写了一个,下载地址见下

链接:​https://pan.baidu.com/s/1-rnUS5COZdQbZCdFHubFOQ?pwd=ychi​
提取码:ychi 

(进网站的时候记得把前面的“xn--https-kt3b//”删掉,我也不知道那是什么东西)

 自认为还不错

 

本程序用C++编写,工具是VS,有bug请与作者练习,谢谢!

贴上源代码:

player.h

#ifndef PLAYER_H_
#define PLAYER_H_

#include <time.h>
#include <cstdlib>
#include <iostream>
#include <conio.h>
#include "output.h"
using namespace std;
template<typename T1, typename T2>
constexpr auto random(T1 x, T2 y) { return rand() % (y - x + 1) + x; }

//1为狼人,2为平民,3为预言家,4为女巫,5为猎人
struct Pl {
	bool dead, is_AI;//是否死亡及是否是AI
	int occ;//职业
	int last_out;//上一个对自己进行投票的人
	int pots;//毒药数量
	int know[40];//已知的别人身份
	bool fknow[40];//知道谁的身份
	int i_of_know;
	int num;
	void csh() {//初始化
		dead = false;
		is_AI = true;
		occ = 0;
		pots = 3;
		last_out = 0;
		num = 0;
		for (int i = 1; i <= 35; i++)
			know[i] = 0;
		for (int i = 1; i <= 35; i++)
			fknow[i] = false;
		i_of_know = 1;
	}
};
__declspec(selectany) Pl player[40];
extern string occs[10];//职业名称,比判断好使多了

bool check(Pl a,int i);

extern int out(Pl a, int peop);

extern int kill_for_wolf(Pl a, int peop, int which);

extern int things_of_witch(Pl a, int peop, int which,int day);

extern bool prop(Pl a, int peop, int which);

extern int pull_us(Pl a, int peop);

extern int over(Pl a, int peop, bool watchhh);

#endif

player.cpp

#include "player.h"
#include "output.cpp"

string occs[10] = { "","狼人","平民","预言家","女巫","猎人" };//职业名称,比判断好使多了

bool check(Pl a,int i) {//预言家的判断函数
	int i1 = 1;
	while (a.know[i1] != 0) {
		if (a.know[i1] != 1 && a.know[i1] == i) return false;
		i1++;
	}
	return true;
}

int out(Pl a, int peop) {//投票
	if (a.dead) return 0;//死了
	else if (a.is_AI && a.occ == 2 && a.last_out != 0 && !player[a.last_out].dead) {//如果是平民且有人投过他,这人还没死
		Sleep(300);
		outp_n(a.num);
		outp("->");
		outp_n(a.last_out);
		outp("\n");
		player[a.last_out].last_out = a.num;
		return a.last_out;
	}
	else if (a.is_AI && a.occ == 3 && a.know[1] != 0) {//如果是预言家,且可能知道是谁
		int i = 1;
		while (a.know[i] != 0) {
			if (player[i].occ == 1 && !player[i].dead) {
				Sleep(300);
				outp_n(a.num);
				outp("->");
				outp_n(a.last_out);
				outp("\n");
				return i;
			}
		}
		int tou = random(1, peop);
		while (tou == a.num || player[tou].dead || !check(a,tou)) tou = random(1, peop);//如果是自己或已死亡或已知不是狼人,就重来
		Sleep(300);
		outp_n(a.num);
		outp("->");
		outp_n(tou);
		outp("\n");
		player[tou].last_out = a.num;
		return tou;
	}
	else if (a.is_AI) {//其他AI或预言家未预言所有人
		int tou = random(1, peop);
		while (tou == a.num || player[tou].dead || (a.occ == 1 && player[tou].occ == 1)) tou = random(1, peop);//如果是自己或已死亡或双方都是狼人,就重来
		Sleep(300);
		outp_n(a.num);
		outp("->");
		outp_n(tou);
		outp("\n");
		player[tou].last_out = a.num;
		return tou;
	}
	else {//是玩家
		outp("你要投谁?(如果投死人,那么游戏可能会崩掉,你愿意吗)\n");
		for (int i = 1; i <= peop; i++)
			if (!player[i].dead) cout << i << " ";
		int tou;
		cin >> tou;
		player[a.last_out].last_out = a.num;
		return tou;
	}
}

int kill_for_wolf(Pl a, int peop, int which) {//狼人杀人
	if (a.occ != 1) return 0;//不是狼人
	else if (a.dead) return 0;//死了
	if (a.is_AI) {//是AI
		int tou = random(1, peop);
		while (tou == a.num || player[tou].dead || player[tou].occ == 1) tou = random(1, peop);
		outp("狼人");
		outp_n(which);
		outp("号请睁眼!\n");
		outp("今晚要杀谁?\n");
		Sleep(500 - op1 * 2);
		outp("好的。\n");
		return tou;
	}
	else {//是玩家
		outp("狼人");
		outp_n(which);
		outp("号请睁眼!\n");
		outp("今晚要杀谁?(如果杀死人,那么游戏可能会崩掉,你愿意吗)\n");
		for (int i = 1; i <= peop; i++)
			if (!player[i].dead) cout << i << " ";
		int tou;
		cin >> tou;
		return tou;
	}
}

int things_of_witch(Pl a, int peop, int which,int day) {//女巫杀人或救人
	if (a.occ != 4) return 0;//不是女巫
	else if (a.dead) return 0;//死了
	else if (a.is_AI) {//是AI
		int dead = 0;
		for (int i = 1; i <= peop; i++)
			if (player[i].dead) dead++;
		outp("女巫");
		outp_n(which);
		outp("号请睁眼!\n");
		outp("今晚要杀人还是救人?\n");
		Sleep(500 - op1 * 2);
		outp("好的。\n");
		int kill_save = random(1, 2);
		if ((a.pots > 0 && kill_save == 1) || (dead == 0 && a.pots > 0)) {//有毒药且没人死/随机抽到,杀人
			int tou = random(1, peop);
			while (tou == a.num || player[tou].dead) tou = random(1, peop);
			a.pots--;
			//cout << "杀\n";
			player[tou].dead = true;
			return tou;
		}
		else if (dead > 0) {//没毒药,救人
			int tou = random(1, peop);
			while (tou == a.num || !player[tou].dead) tou = random(1, peop);
			//cout << "救\n";
			player[tou].dead = false;
			return tou;
		}
		else return 2147483647;//无法杀,也无法救
	}
	else {//是玩家
		char k_s;
		outp("女巫");
		outp_n(which);
		outp("号请睁眼!\n");
		while (true) {
			outp("你要杀人还是要救人? 杀人:1    救人:2   啥也不做:3\n");
			k_s = _getch();
			if (k_s == '1') {//杀人
				if (a.pots < 1)//毒药不够
					cout << "毒药不足!\n";
				else {//毒药够
					outp("今晚要杀谁?(如果杀死人,那么游戏可能会崩掉,你愿意吗)\n");
					for (int i = 1; i <= peop; i++)
						if (!player[i].dead) cout << i << " ";
					int tou;
					cin >> tou;
					player[tou].dead = true;
					return tou;
				}
			}
			else if (k_s == '2') {//救人
				outp("今晚要救谁?(如果救活人,那么游戏可能会崩掉,你愿意吗)\n");
				for (int i = 1; i <= peop; i++)
					if (player[i].dead) cout << i << "号,职业:" << occs[player[i].occ] << endl;
				int tou;
				cin >> tou;
				player[tou].dead = false;
				return tou;
			}
			else return 2147483647;
		}
	}
}

bool prop(Pl a, int peop,int which) {//占卜某人身份
	if (a.occ != 3) return false;//如果不是预言家,就退出
	else if (a.dead) return false;//死了
	else if (a.is_AI) {//如果是AI
		outp("预言家");
		outp_n(which);
		outp("号请睁眼!\n");
		outp("你要占卜谁的身份?\n");
		Sleep(500 - op1 * 2);
		outp("好的。\n");
		int get_who = random(1, peop);
		while (a.fknow[get_who]) get_who = random(1, peop);
		a.know[a.i_of_know] = get_who;
		a.fknow[get_who] = true;
		a.i_of_know++;
		return true;
	}
	else {//如果不是AI
		outp("预言家");
		outp_n(which);
		outp("号请睁眼!\n");
		while (true) {
			outp("你要占卜谁的身份(输入编号)?(占卜百分百正确,如果占卜同一个人后果自负)\n");
			int get_who;
			cin >> get_who;
			if (get_who > peop || get_who < 1) continue;//当编号不正确
			else {
				//cout << get_who << "号的身份是:" << occs[player[get_who].occ] << "。\n";
				outp_n(get_who);
				outp("号的身份是:");
				outp(occs[player[get_who].occ]);
				outp("。\n");
				break;
			}
		}
		return true;
	}
}

int pull_us(Pl a, int peop) {//猎人的神级技能:拉一个人陪葬
	if (a.occ != 5) return 0;//不是猎人
	else if (a.dead) return 0;//死了
	else if (a.is_AI) {//是AI
		if (a.last_out != 0 && !player[a.last_out].dead) {
			Sleep(300);
			outp_n(a.num);
			outp("号决定拉出");
			outp_n(a.last_out);
			outp("号陪葬。\n");
			outp_n(a.last_out);
			outp("号的身份是:");
			outp(occs[player[a.last_out].occ]);
			outp("。\n");
			return a.last_out;
		}
		else {
			int tou = random(1, peop);
			while (tou == a.num || player[tou].dead) tou = random(1, peop);
			Sleep(300);
			outp_n(a.num);
			outp("号决定拉出");
			outp_n(tou);
			outp("号陪葬。\n");
			outp_n(tou);
			outp("号的身份是:");
			outp(occs[player[a.last_out].occ]);
			outp("。\n");
			return tou;
		}
	}
	else {//不是AI
		outp("很遗憾,你被投出了。正义虽迟但到,你可以陪葬一人,选择谁?(如果带走死人,那么游戏可能会崩掉,你愿意吗)\n");
		for (int i = 1; i <= peop; i++)
			if (!player[i].dead) cout << i << " ";
		int tou;
		cin >> tou;
		outp_n(tou);
		outp("号的身份是:");
		outp(occs[player[a.last_out].occ]);
		outp("。\n");
		return tou;
	}
}

int over(Pl a, int peop,bool watchhh) {//游戏是否结束
	int wolfs = 0, else_p = 0;;
	if (a.dead && watchhh == false) {
		outp("你已经>>死<<了。\n");
		system("pause");
		system("cls");
		return 3;
	}
	for (int i = 1; i <= peop; i++) {
		if (!player[i].dead && player[i].occ == 1) wolfs++;
	}
	if (wolfs == 0) {
		outp("狼人已全部死亡,好人胜利!\n");
		system("pause");
		system("cls");
		if (a.occ == 1) return 1;
		return 2;
	}
	for (int i = 1; i <= peop; i++) {
		if (!player[i].dead && player[i].occ != 1) else_p++;
	}
	if (else_p == 0) {
		outp("好人已全部死亡,狼人胜利!\n");
		system("pause");
		system("cls");
		if (a.occ == 1) return 2;
		else return 1;
	}
	return 0;
}//0为游戏未结束,1为游戏失败,2为游戏成功,3为人物死亡

chong.h

#ifndef CHONG_H_
#define CHONG_H_

#include "occ_card.h"
#include "player.h"
#include <cstring>

void play(int peoplesss);

#endif

chong.cpp

#include "chong.h"
#include "output.h"

//20人场:2狼人,8平民,3预言家,2女巫,5猎人
//30人场:3狼人,12平民,4预言家,4女巫,7猎人

void play(int peoplesss) {//开始游戏
	system("cls");
	//初始化
	for (int i = 1; i <= peoplesss; i++)
		player[i].csh();
	int twenty[10] = { 0,2,8,2,3,5 };
	int thirty[10] = { 0,3,12,4,4,7 };
	int hundred[10] = {0,16,40,24,7,13};
	//分配身份
	for (int i = 1; i <= peoplesss; i++) {
		int iden = random(1, 5);
		if (peoplesss == 20)
			while (twenty[iden] == 0) iden = random(1, 5);
		else if (peoplesss == 30)
			while (thirty[iden] == 0) iden = random(1, 5);
		else
			while (hundred[iden] == 0) iden = random(1, 5);
		player[i].occ = iden;
		if (peoplesss == 20)
			twenty[iden]--;
		else if (peoplesss == 30)
			thirty[iden]--;
		else
			hundred[iden]--;
		player[i].num = i;
	}
	//分配号码
	int p1 = random(1, peoplesss);
	player[p1].is_AI = false;
	//显示
	outp("你是");
	outp_n(p1);
	outp("号。\n");
	outp("正在分配身份……\n");
	Sleep(3000 - op1 * 2);
    outp_occ(player[p1].occ);
	/*
	system("cls");
	for (int i = 1; i <= peoplesss; i++)
		cout << player[i].occ << " ";
	cout << endl;
	system("pause");
	//system("cls");
	// 以上这段是测试*/

	//开始游戏
	outp("按任意键开始游戏……");
	char yijiansanlian_jiayou = _getch();
	int day = 1;//第几天
	bool watchh = false;
	while (true) {
		system("cls");
		//晚上
		outp("第");
		outp_n(day);
		outp("晚开始\n");
		outp("你是");
		outp_n(p1);
		outp("号\n");
		outp("天黑请闭眼!\n");
		int kill_by_wolf[10];//被狼人杀
		int things_by_witch[10];//被女巫杀/救
		memset(kill_by_wolf, 0, sizeof(kill_by_wolf));
		memset(things_by_witch, 0, sizeof(things_by_witch));
		//狼人杀人
		int i = 1;//第几个
		for (int i1 = 1; i1 <= peoplesss; i1++) {
			if (player[i1].dead) continue;
			int kill = kill_for_wolf(player[i1], peoplesss, i);
			if (kill != 0) {
				player[kill].dead = true;
				kill_by_wolf[i++] = kill;
			}
		}
		//女巫救人/杀人
		i = 1;
		int i2 = 1;
		for (int i1 = 1; i1 <= peoplesss; i1++) {
			if (player[i1].dead) continue;
			int kill = things_of_witch(player[i1], peoplesss, i2,day);
			if (kill != 0) {
				if (kill == 2147483647) {
					i2++;
					continue;
				}
				things_by_witch[i] = kill;
				i++,i2++;
			}
		}
		//预言家占卜
		i = 1;
		for (int i1 = 1; i1 <= peoplesss; i1++) {
			if (player[i1].dead) continue;
			bool is_or_not = prop(player[i1], peoplesss, i);
			if (is_or_not)
				i++;
		}
		//输出信息
		i = 1;
		bool save_p1 = false;//救玩家
		while (kill_by_wolf[i] > 0) {
			outp("狼人杀掉了");
			outp_n(kill_by_wolf[i]);
			outp("号,身份:");
			outp(occs[player[kill_by_wolf[i]].occ]);
			outp("。\n");
			i++;
		}
		/*int i1 = 1;
		while (kill_by_witch[i1] > 0) {
			outp("女巫杀掉了");
			outp_n(kill_by_witch[i1]);
			outp("号,身份:");
			outp(occs[player[kill_by_witch[i1]].occ]);
			outp("。\n");
			i1++;
		}
		int i2 = 1;
		while (save_by_witch[i2] > 0) {
			outp("女巫救活了");
			outp_n(save_by_witch[i2]);
			outp("号,身份:");
			outp(occs[player[save_by_witch[i2]].occ]);
			outp("。\n");
			if (save_by_witch[i2] == p1) save_p1 = true;
			i2++;
			if (save_by_witch[i2] == p1) save_p1 = true;
		}*///之前的代码
		i = 1;
		while (things_by_witch[i] > 0) {
			if (player[things_by_witch[i]].dead) {
				outp("女巫杀掉了");
				outp_n(things_by_witch[i]);
				outp("号,身份:");
				outp(occs[player[things_by_witch[i]].occ]);
				outp("。\n");
				i++;
			}
			else if (!player[things_by_witch[i]].dead) {
				outp("女巫救活了");
				outp_n(things_by_witch[i]);
				outp("号,身份:");
				outp(occs[player[things_by_witch[i]].occ]);
				outp("。\n");
				if (things_by_witch[i] == p1) save_p1 = true;
				i++;
				if (things_by_witch[i] == p1) save_p1 = true;
			}
		}
		//判断游戏是否结束(0为未结束,1为失败,2为成功)
		int over2 = over(player[p1], peoplesss, watchh);
		if (over2 == 1) {
			outp("对不起,你失败了。\n");
			system("pause");
			return;
		}
		else if (over2 == 2) {
			outp("恭喜你,你成功取得了胜利!!!\n");
			system("pause");
			return;
		}
		else if (over2 == 3){
			outp("对不起,你死了。\n");
			outp("是否观战?1:是   其他:否\n");
			char watchhh = _getch();
			if (watchhh == '1') {
				outp("好的。\n两秒后继续游戏……\n");
				Sleep(2000 - op1);
				watchh = true;
			}
			else return;
		}
		if (save_p1) {
			outp("你被救活了。\n");
			watchh = false;
		}
		//投票
		outp("投票开始\n");
		int how_much[40];
		memset(how_much, 0, sizeof(how_much));
		for (int i = 1; i <= peoplesss; i++) {
			int outi = out(player[i], peoplesss);
			if (player[i].occ == 2 && day % 3 == 0) how_much[outi] += 2;
			else how_much[outi]++;
		}
		int maxn = -1, maxnn = 0;;
		for (int i = 1; i <= peoplesss; i++)
			if (how_much[i] > maxn) maxn = how_much[i], maxnn = i;
		outp_n(maxnn);
		outp("号被大家以");
		outp_n(maxn);
		outp("票的高票数投出了。\n");
		outp_n(maxnn);
		outp("号的身份是:");
		outp(occs[player[maxnn].occ]);
		outp("。\n");
		int who_out_with_hau = pull_us(player[maxnn], peoplesss);
		player[maxnn].dead = true;
		if (who_out_with_hau > 0) player[who_out_with_hau].dead = true;
		//判断游戏是否结束
		over2 = over(player[p1], peoplesss,watchh);
		if (over2 == 1) {
			outp("对不起,你失败了。\n");
			system("pause");
			return;
		}
		else if (over2 == 2) {
			outp("恭喜你,你成功取得了胜利!!!\n");
			system("pause");
			return;
		}
		else if (over2 == 3){
			outp("对不起,你死了。\n");
			outp("是否观战?1:是   其他:否\n");
			char watchhh = _getch();
			if (watchhh == '1') {
				outp("好的。\n两秒后继续游戏……\n");
				Sleep(2000 - op1);
				watchh = true;
			}
			else return;
		}
		//天数++
		day++;
		system("pause");
		
		/*for (int i = 1; i <= peoplesss; i++)
			cout << player[i].dead << " ";
		cout << endl;
		system("pause");
		//以上是测试*/

	}
}

output.h

#ifndef OUTPUT_H_
#define OUTPUT_H_

#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
inline extern void outp(string s);
inline extern void outp_n_l(int a);
inline extern void outp_n(int a);
inline extern void outp_fast(string s);
inline extern void outp_line(string s);
__declspec(selectany) extern const int op1 = 66;
__declspec(selectany) extern const int op2 = 40;
__declspec(selectany) extern const int op3 = 500;

#endif

output.cpp

#include "output.h"
using namespace std;

inline void outp(string s) {
	for (int i = 0; i < s.size(); i++) {
		cout << s[i];
		Sleep(op1);
	}
}
inline void outp_n_l(int a) {
	string s = to_string(a);
	for (int i = 0; i < s.size(); i++) {
		cout << s[i];
		Sleep(op1 * 2);
	}
	cout << endl;
	Sleep(op1 * 2);
}
inline void outp_n(int a) {
	string s = to_string(a);
	for (int i = 0; i < s.size(); i++) {
		cout << s[i];
		Sleep(op1 * 2);
	}
}
inline void outp_fast(string s) {
	for (int i = 0; i < s.size(); i++) {
		cout << s[i];
		Sleep(op2);
	}
}
inline void outp_line(string s) {
	cout << s;
	Sleep(op3);
}

game.h

#ifndef GAME_H_
#define GAME_H_

#include "chong.h"
#include <fstream>

extern void begin();//开始游戏

#endif

game.cpp

#include "game.h"
using namespace std;

void begin() {//开始游戏
	system("cls");
	while (true) {
		cout << "你要玩多少人场的游戏?20人:1   30人:2\n";
		char how_many_p = _getch();
		if (how_many_p == '1') {
			play(20);
			break;
		}
		else if (how_many_p == '2') {
			play(30);
			break;
		}
		/*else if (how_many_p == 'h') {
			play(100);
			break;
		}*/
		else
			system("cls");
	}
	system("cls");
	cout << "是否再来一局?是:1    否:其它\n";
	char again = _getch();
	if (again == '1') {
		cout << "好的。\n";
		cout << "按任意键开始新一局游戏...";
		char yijiansanlian = _getch();
		system("cls");
		begin();
		return;
	}
	else {
		cout << "好的。\n";
		return;
	}
	return;
}

occ_card.h

#ifndef OCC_CARD_H_
#define OCC_CARD_H_
#include <string>
#include <windows.h>
#include <iostream>
#include <conio.h>
using namespace std;

extern string occ[10][40];//职业

extern void outp_occ(int x);//显示职业,1为狼人,2为平民,3为女巫,4为预言家,5为猎人

#endif

occ_card.cpp

#include "occ_card.h"

string occ[10][40] = {
{
					   "╔════════════════════════════════════════════════════════╗\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║          狼               人               杀          ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "╚════════════════════════════════════════════════════════╝\n"
},//空
{                      "╔════════════════════════════════════════════════════════╗\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                     你           是                    ║\n",
					   "║                                                        ║\n",
					   "║                  狼                 人                 ║\n",
					   "║                                                        ║\n",
					   "║                          !!!                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                  技能:每晚可以杀一个人                ║\n",
					   "║                                                        ║\n",
					   "║                       去追随野性吧!                   ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "╚════════════════════════════════════════════════════════╝\n"
						},//狼人
				 {     "╔════════════════════════════════════════════════════════╗\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                     你           是                    ║\n",
					   "║                                                        ║\n",
					   "║                  平                 民                 ║\n",
					   "║                                                        ║\n",
					   "║                          !!!                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║               技能:第3的倍数天投一票等于2票           ║\n",
					   "║                                                        ║\n",
					   "║                简单的单位组成了世间的一切。            ║\n",
					   "║                                                        ║\n",
					   "║                                    ——艾萨克·牛顿       ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "╚════════════════════════════════════════════════════════╝\n"
},//平民
				   {   "╔════════════════════════════════════════════════════════╗\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                     你           是                    ║\n",
					   "║                                                        ║\n",
					   "║                 预         言         家               ║\n",
					   "║                                                        ║\n",
					   "║                          !!!                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║               技能:每晚可以占卜一个人的身份           ║\n",
					   "║                                                        ║\n",
					   "║          当世界暴露在彻底的光明之下,人类就毁灭了。    ║\n",
					   "║                                                        ║\n",
					   "║                                            ——白冰      ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "╚════════════════════════════════════════════════════════╝\n"
},//女巫
				  {    "╔════════════════════════════════════════════════════════╗\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                     你           是                    ║\n",
					   "║                                                        ║\n",
					   "║                  女                 巫                 ║\n",
					   "║                                                        ║\n",
					   "║                          !!!                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                 技能:每晚可以杀人或救人               ║\n",
					   "║                                                        ║\n",
					   "║                 生存还是死亡,这是个问题。             ║\n",
					   "║                                                        ║\n",
					   "║                                      ——哈姆雷特        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "╚════════════════════════════════════════════════════════╝\n"
},//预言家
				   {   "╔════════════════════════════════════════════════════════╗\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                     你           是                    ║\n",
					   "║                                                        ║\n",
					   "║                  猎                 人                 ║\n",
					   "║                                                        ║\n",
					   "║                          !!!                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║            技能:被投出后,可以拉一人作为陪葬          ║\n",
					   "║                                                        ║\n",
					   "║                   任何邪恶终将绳之以法!               ║\n",
					   "║                                                        ║\n",
					   "║                                      ——吴京            ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "║                                                        ║\n",
					   "╚════════════════════════════════════════════════════════╝\n"
} };//猎人
//以上是为了对齐所做的努力(可能在Windows10又坏了)

extern void outp_occ(int x) {//显示职业,1为狼人,2为平民,3为女巫,4为预言家,5为猎人
	system("cls");
	for (int i = 0; i < 29; i++) cout << occ[0][i];
	cout << "按任意键查看你的身份:";
	char dianzano = _getch();
	system("cls");
	for (int i = 0; i < 29; i++) {
		cout << occ[x][i];
		Sleep(300);
	}
}

狼人杀.cpp

// 狼人杀.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include "game.h"
using namespace std;

int main()
{
    srand(time(0));
    outp_line("欢迎来到狼人杀游戏!\n");
    outp_line("你要干什么?\n1:开始游戏\n2:查看游戏规则\n3:退出\n4:游戏信息\n");
    while (true) {
        char choose = _getch();
        if (choose == '2') {
            cout << "---------------------------------------------------------\n";
            outp_line("狼人杀游戏规则如下:\n");
            outp_line("首先介绍职业:\n");
            outp_line("1.狼人:在每个晚上可以杀一个人,20人场中有2个狼人,30人场中有3个狼人;\n");
            outp_line("2.平民:每晚投票时可以获得一次机会,三的倍数晚时投一票等于2票,20人场中有8个平民,30人场中有12个平民;\n");
            outp_line("3.预言家:每晚可以看见一个人的身份,如果发现了狼人,就是走大运了,20人场中有2个预言家,30人场中有4个预言家;\n");
            outp_line("4.女巫:每晚可以毒死一个人或者救一个人,但是毒药只有3瓶,救药无限,20人场中有3个女巫,30人场中有4个女巫;\n");
            outp_line("5.猎人:当投票被投出时,可以拉一个人陪葬,20人场中有5个猎人,30人场中有7个猎人\n\n");
            outp_line("接下来说一下其他规则:\n");
            outp_line("本游戏中的其他人都是作者手写很久的人工愚蠢,有这几条规则,利用好规则赢得游戏:\n");
            outp_line("1.平民每次都会投上次投他的最后一个人;\n");
            outp_line("2.猎人带走的是最后一个投他的人;\n");
            outp_line("3.预言家如果预言到狼人,就会一直投他;如果不是,则不会投他;\n");
            outp_line("4.女巫是好人,但是有时会脑抽,复活狼人(亲测这种情况很多);\n");
            outp_line("5.狼人不会互杀,投票时也不会;\n");
            outp_line("6.如果有人票数相同,则选编号靠前的人\n");
            outp_line("7.会显示死的人,但不会显示被救的人;\n");
            outp_line("8.为什么人机叫人工愚蠢?非常简单,因为他们(除了预言家)记不住自己知道的身份\n\n\n");
            outp_line("好了,游戏的规则就是这样了,开始你的狼人杀旅程吧!\n");
            system("pause");
        }
        else if (choose == '1') {
            begin();
            break;
        }
        else if (choose == '3') {
            cout << "好的。\n";
            break;
        }
        else if (choose == '4') {
            cout << "\n游戏版本:1.0版\n";
            cout << "作者:一尺\n";
            cout << "copyright (c) yichi studios. 保留所有权利\n";
            system("pause");
        }
        system("cls");
        cout << "你要干什么!\n1:开始游戏\n2:查看游戏规则\n3:退出\n4:游戏信息";
    }
    system("pause");
    return 0;
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值