跳到正文

休闲·娱乐

迷宫闯关 V1.4.2

HappyJaPhy约 73 分钟
原文
文章信息与版本

文章信息

发布
2021年8月24日
收录
2025年12月12日
更新
2026年11月13日
篇幅
约 73 分钟
获赞
5

版本

  1. v1当前

迷宫闯关 V1.4.2 !

  • 第一次打小游戏,做的不好请见谅!~

V1.3.x

  • 加入了商店,并对游玩体验进行了优化

V1.3.0 (2023/8/6)

  1. 加入了“技能”和“商店”功能
  2. 将炸弹和地雷爆炸设定为连锁反应
  3. 进一步优化代码长度

V1.3.1

  1. 修复了炸弹被多次引爆的问题
  2. 修复了地图左下角总是出现空位,导致爆炸输出越界的问题
  3. 修复了不经常自动存档的问题
  4. 修复了在收集血包时可以无限加血的问题
  5. 修复了炸弹爆炸时加血和加分会再次调用的问题
  6. 修复了已开启但未通过第五关时商店就解锁的问题

V1.3.2

  1. 加入了存档问题检测,使随意更改存档成为过去
  2. 加入了技能面板
  3. 进一步优化代码长度

V1.3.3.1 (2023/8/8)

  1. 加入了消耗品商店,可购买血包和技能体验卡
  2. 加入了当铺,可以用来倒卖消耗品
  3. 优化了技能面板
  4. 进一步优化了代码长度,并修改了大量已知 BUGBUG,优化了游玩体验

小修改

  1. 提高了技能的价格
  2. HardHard 模式下通过第 33 关就可以解锁商店

V1.3.4

  1. 在中等和困难模式中加入 5×55 \times 5 的大炸弹
  2. 大炸弹的爆炸范围内的碎砖墙可能发生破碎
  3. 将炸弹伤害与距离爆炸中心的距离挂钩

小修改

  1. 降低了爆炸产生碎砖墙的概率

V1.4

  • 加入了探索模式。

V1.4.0 (2023/8/26)

  1. 加入了探索模式,将原先的正常迷宫归入扫荡模式(通关后才能进入扫荡模式)。
  2. 修复了已知 BUGBUG。

V1.4.1.3

  1. 加入了“地毯”。
  2. 将未失明时的地图探索做出了一点小更改。
  3. 优化了代码长度并修复了已知 BUGBUG。

V1.4.2 (2023/9/22)

  1. 加入键位修改功能。
  2. 更改每一关的胜利界面的小细节(没法直接进入商店了)。
  3. 将部分按键改为平滑检测。
  4. 修复了已知 BUGBUG。

V1.4.3(预告)(可能又会断更了)

  1. 有可能将所有按键检测变为平滑检测(详见 我的根本没打出来的新游戏 以及 此头文件)
  2. 加入技能升级系统,背包系统

上代码!

C++
#include <bits/stdc++.h>
#include <io.h>
#include <windows.h>
#define maxn 20
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1 : 0)
using namespace std;

int mp[200][200] = {0}, rx, ry, score = 0, blood = 10, bao = 0, sgless;
int nandu, op[10] = {0}, boomm[100] = {0}, len = 1, rlen = 1, facing;
int costsco[maxn] = {0, 40, 30, 50, 40, 25, 20, 15, 10, 20, 15};
int needblo[maxn] = {0, 1, 4, 0, -1, -2, 1, 4, 0, -1};
int dir[5][2] = {{0, 0}, {0, -1}, {-1, 0}, {0, 1}, {1, 0}}, have[maxn];
char whichkey[] = {'Q', 'Z', 'X', 37, 38, 39, 40, 'A', 'W', 'D', 'S'};
bool issg, isopen, isup[260];
float xt = 0;
string thisgamename;
char keyname[260][60] = {"", "鼠标左键", "鼠标右键", "[Ctrl]+[Break]",
                         "鼠标中键", "X1 鼠标按钮", "X2 鼠标按钮", "", "[Backspace]", "[Tab]", "", "",
                         "[Clear]", "[Enter]", "", "", "[Shift]", "[Ctrl]", "[Alt]", "[Pause]",
                         "[CapsLock]", "", "", "", "", "", "", "[Esc]", "", "", "", "", "[Space]",
                         "[PageUp]", "[PageDown]", "[End]", "[Home]", "[Left]", "[Up]", "[Right]",
                         "[Down]", "[Select]", "[Print]", "[Execute]", "[PrintScreen]", "[Insert]",
                         "[Delete]", "[Help]", "[0]", "[1]", "[2]", "[3]", "[4]", "[5]", "[6]", "[7]",
                         "[8]", "[9]", "", "", "", "", "", "", "", "[A]", "[B]", "[C]", "[D]", "[E]",
                         "[F]", "[G]", "[H]", "[I]", "[J]", "[K]", "[L]", "[M]", "[N]", "[O]", "[p]",
                         "[Q]", "[R]", "[S]", "[T]", "[U]", "[V]", "[W]", "[X]", "[Y]", "[Z]", "左[Win]",
                         "右[Win]", "[App]", "", "[Sleep]", "小键盘[0]", "小键盘[1]", "小键盘[2]",
                         "小键盘[3]", "小键盘[4]", "小键盘[5]", "小键盘[6]", "小键盘[7]", "小键盘[8]",
                         "小键盘[9]", "[×]", "[+]", "[分隔符]", "[-]", "[Dec]", "[/]", "[F1]", "[F2]",
                         "[F3]", "[F4]", "[F5]", "[F6]", "[F7]", "[F8]", "[F9]", "[F10]", "[F11]",
                         "[F12]", "[F13]", "[F14]", "[F15]", "[F16]", "[F17]", "[F18]", "[F19]", "[F20]",
                         "[F21]", "[F22]", "[F23]", "[F24]", "", "", "", "", "", "", "", "", "[NumLock]",
                         "[ScrollLock]", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
                         "左[Shift]", "右[Shift]", "左[Ctrl]", "右[Ctrl]", "左[Alt]", "右[Alt]", "", "", "", "",
                         "", "", "", "静音", "音量减小", "音量增加", "下一首", "上一首", "停止", "播放/暂停",
                         "启动邮件", "选择媒体", "启动应用程序_1", "启动应用程序_2", "", "", "[;]",
                         "[+]", "[,]", "[-]", "[.]", "[/]", "[~]", "", "", "", "", "", "", "", "", "",
                         "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "[{]", "[\\]",
                         "[}]", "[']", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
                         "", "", "", "", "", "", "[Attn]", "[CrSel]", "[ExSel]", "[ErEOF]", "播放键",
                         "缩放键", "", "[PA1]", "清除键"
                        };

struct blk {
	char ch[3];
	int clr;
	blk (const char *s = "  ", int a = 7) {
		ch[0] = s[0], ch[1] = s[1], ch[2] = '\0', clr = a;
	}
} blocks[11];

struct node {
	int x, y;
};
queue<node> boom;

inline void color(int a) {
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), a);
}

inline void gto(int x, int y) {
	COORD pos;
	pos.X = y;
	pos.Y = x;
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

bool new_game(), cundang(), read(string name), game(), to_start();
bool checkup(int x, int y, int n), whichmod(int n), notwall(int x, int y);
bool isair(int x, int y);
int gq(int n, bool mod), rnk(int x, bool y = 1);
void start(), jiaocheng(), shop(), jinengshop(), scoshop(), huishou();
void whichxitong(), dlt(string name), all_clear(), sout(string a, int t);
void update(int x), manout(int n), mpout(int n, bool mod), goofput(int rx, int ry);
void lose(int num), win(), addvis(int n), boardout(int n), prt(int x, int y);
void booom(int n, bool mod), boomclear(), mpout(int x, int y, bool isbig, bool mod);
void save(string name), look(int n, bool mod), go_though(int x, int y, int n);
void addop(int x, int y, int n, int face), setkey(), change(int x);

void whichxitong() {
	typedef void(__stdcall * NTPROC)(DWORD *, DWORD *, DWORD *);
	HINSTANCE hinst = LoadLibrary("ntdll.dll");
	DWORD dwMajor, dwMinor, dwBuildNumber;
	NTPROC proc = (NTPROC)GetProcAddress(hinst, "RtlGetNtVersionNumbers");
	proc(&dwMajor, &dwMinor, &dwBuildNumber);
	if (dwMajor == 10 && dwMinor == 0) {
		xt = 10;
		return ;
	}
	SYSTEM_INFO info;
	GetSystemInfo(&info);
	OSVERSIONINFOEX os;
	os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
	if (GetVersionEx((OSVERSIONINFO *)&os)) {
		if (os.dwMajorVersion == 6 && os.wProductType == VER_NT_WORKSTATION) {
			xt = 7;
		}
	}
}

int main() {
	srand((unsigned)time(NULL));
	blocks[6] = blocks[0] = {"  ", 238};
	blocks[4] = blocks[3] = blocks[1] = {"  ", 119};
	blocks[2] = {"!!", 27};
	blocks[10] = blocks[5] = {"[]", 236};
	blocks[7] = {"☆", 231};
	blocks[8] = {"☆", 236};
	blocks[9] = {"国", 120};
	for (int i = 1; i <= 256; i++) {
		if (!KEY_DOWN(i)) {
			isup[i] = 1;
		}
	}
	start();
	return 0;
}

bool read(string name) {
	string str = name + ".save";
	char ch[30];
	memset(ch, 0, sizeof ch);
	for (unsigned int i = 0; i < str.size(); i++) {
		ch[i] = str[i];
	}
	char *s = ch;
	FILE *fp = fopen(s, "r");
	fscanf(fp, "%d%d%d%d", &nandu, &blood, &bao, &score);
	bool isold = 0;
	unsigned long long hsh = rnk(nandu, 0) + rnk(blood, 0) + rnk(bao, 0) + rnk(score, 0), thehsh;
	for (int i = 0; i < 10; i++) {
		fscanf(fp, "%d", op + i);
		hsh += rnk(op[i], 0);
	}
	for (int i = 1; i < maxn; i++) {
		if (fscanf(fp, "%d", have + i) == EOF) isold = 1, have[i] = 0;
		hsh += rnk(have[i], 0);
	}
	have[5] = bao;
	int a = 0;
	if (fscanf(fp, "%d", &a) == EOF) {
		isold = 1, isopen = 0;
	} else {
		isopen = ((a || (nandu == 3 ? op[4] : op[6])) ? 1 : 0);
	}
	hsh += rnk(isopen, 0);
	for (int i = 0; i <= 10; i++) {
		if (fscanf(fp, "%d", &a) == EOF) isold = 1;
		else whichkey[i] = a;
		hsh += rnk(whichkey[i], 0);
	}
	if (fscanf(fp, "%llu", &thehsh) == EOF) isold = 1;
	fclose(fp);
	if (thehsh != hsh && !isold) return 0;
	if (isopen == 0) memset(have, 0, sizeof have);
	save(name);
	return 1;
}

void save(string name) {
	name += ".save";
	char ch[30];
	memset(ch, 0, sizeof ch);
	for (unsigned int i = 0; i < name.size(); i++) ch[i] = name[i];
	char *s = ch;
	FILE *fp = fopen(s, "w");
	fprintf(fp, "%d %d %d %d ", nandu, blood, bao, score);
	unsigned long long hsh = rnk(nandu, 0) + rnk(blood, 0) + rnk(bao, 0) + rnk(score, 0);
	for (int i = 0; i < 10; i++) {
		fprintf(fp, "%d ", op[i]);
		hsh += rnk(op[i], 0);
	}
	for (int i = 1; i < maxn; i++) {
		have[5] = bao;
		fprintf(fp, "%d ", have[i]);
		hsh += rnk(have[i], 0);
	}
	isopen |= (nandu == 3 ? op[4] : op[6]);
	fprintf(fp, "%d ", isopen), hsh += rnk(isopen, 0);
	for (int i = 0; i <= 10; i++) {
		fprintf(fp, "%d ", whichkey[i]);
		hsh += rnk(whichkey[i], 0);
	}
	fprintf(fp, "%llu", hsh);
	fclose(fp);
	return ;
}

string keys[] = {"", "使用血包", "感知", "跃迁", "向左", "向上", "向右", "向下"};
void change(int x) {
	bool flag = 0;
	color(7), gto(x * 2 + 6, 4), cout << keys[x], color(13);
	gto(x * 2 + 6, 15), printf("[  %s  ]    ", keyname[(int)whichkey[x - 1]]);
	Sleep(50);
	while (1) {
		for (int i = 2; i <= 256; i++)
			if (KEY_DOWN(i)) {
				if (!isup[i]) continue;
				isup[i] = 0;
				bool ffff = 1;
				for (int l = 0; l <= 10; l++) {
					if (l == x - 1) continue;
					if (i == whichkey[l]) {
						ffff = 0, MessageBox(
							NULL,
							"键位冲突!请选择其他键位!",
							"Wrong",
							MB_ICONEXCLAMATION | MB_OK
						);
					}
				}
				if (ffff) flag = 1, whichkey[x - 1] = i;
				break;
			} else {
				isup[i] = 1;
			}
		if (flag) break;
	}
	color(7), gto(x * 2 + 6, 15), printf("[  %s  ]    ", keyname[(int)whichkey[x - 1]]);
	Sleep(100), flag = 0;
	if (x >= 4) {
		color(13);
		gto(x * 2 + 6, 25), printf("[  %s  ]    ", keyname[(int)whichkey[x + 3]]);
		while (1) {
			for (int i = 2; i <= 256; i++)
				if (KEY_DOWN(i)) {
					if (!isup[i]) continue;
					isup[i] = 0;
					bool ffff = 1;
					for (int l = 0; l <= 10; l++) {
						if (l == x - 1) continue;
						if (i == whichkey[l]) {
							ffff = 0, MessageBox(
								NULL,
								"键位冲突!请选择其他键位!",
								"Wrong",
								MB_ICONEXCLAMATION | MB_OK
							);
						}
					}
					if (ffff) flag = 1, whichkey[x - 1] = i;
					break;
				} else
					isup[i] = 1;
			if (flag) break;
		}
		color(7);
		gto(x * 2 + 6, 25), printf("[  %s  ]    ", keyname[(int)whichkey[x + 3]]);
	}
}

void setkey() {
	system("cls"), system("mode con cols=50 lines=30");
	int now = 1, lst = 1;
	color(7), gto(2, 11), printf("键位设置");
	for (int i = 1; i <= 7; i++) {
		gto(i * 2 + 6, 15), printf("[  %s  ]    ", keyname[(int)whichkey[i - 1]]);
		if (i >= 4) {
			gto(i * 2 + 6, 25), printf("[  %s  ]    ", keyname[(int)whichkey[i + 3]]);
		}
	}
A:
	for (int i = 1; i <= 7; i++) {
		if (now == i) color(13);
		gto(i * 2 + 6, 4), cout << keys[i];
		if (now == i) color(7);
	}
	while (1) {
		Sleep(50);
		if (!KEY_DOWN(40)) isup[40] = 1;
		if (!KEY_DOWN(38)) isup[38] = 1;
		if (!KEY_DOWN(13)) isup[13] = 1;
		if (!KEY_DOWN(27)) isup[27] = 1;
		if (isup[40] && KEY_DOWN(40)) {
			isup[40] = 0;
			now = min(7, now + 1), Sleep(30);
		}
		if (isup[38] && KEY_DOWN(38)) {
			isup[38] = 0;
			now = max(1, now - 1), Sleep(30);
		}
		if (now != lst) {
			lst = now;
			goto A;
		}
		if (isup[13] && KEY_DOWN(13)) {
			isup[13] = 0;
			change(now), save(thisgamename), Sleep(30);
			goto A;
		}
		if (isup[27] && KEY_DOWN(27)) {
			isup[27] = 0;
			break;
		}
	}
}

void all_clear() {
	blood = 10, bao = score = 0, nandu = 1;
	isopen = 0;
	memset(op, 0, sizeof op);
	memset(have, 0, sizeof have);
}

void start() {
A:
	system("cls");
	system("mode con cols=40 lines=30");
	int isk = 1, lst = 0;
	gto(7, 10), printf("迷宫の勇者!  v1.4.2");
B:
	all_clear();
	gto(13, 25), printf("开始教程!");
	gto(15, 25), printf("新游戏!");
	gto(17, 25), printf("读取存档!");
	color(13);
	if (isk == 1) {
		gto(13, 25), printf("开始教程!");
	} else if (isk == 2) {
		gto(15, 25), printf("新游戏!");
	} else {
		gto(17, 25), printf("读取存档!");
	}
	color(7);
	gto(29, 39);
	while (1) {
		Sleep(30);
		if (!KEY_DOWN(40)) isup[40] = 1;
		if (!KEY_DOWN(38)) isup[38] = 1;
		if (!KEY_DOWN(27)) isup[27] = 1;
		if (isup[40] && KEY_DOWN(40)) isup[40] = 0, isk = min(3, isk + 1), Sleep(30);
		if (isup[38] && KEY_DOWN(38)) isup[38] = 0, isk = max(1, isk - 1), Sleep(30);
		if (isk != lst) {
			lst = isk;
			goto B;
		}
		if (KEY_DOWN(13)) {
			if (isk == 1) {
				jiaocheng();
				goto A;
			} else if (isk == 2) {
				if (new_game()) if (!game()) return ;
				goto A;
			} else {
				if (cundang()) if (!game()) return ;
				goto A;
			}
		}
		if (isup[27] && KEY_DOWN(27)) {
			isup[27] = 0;
			break;
		}
	}
	return ;
}

bool new_game() {
	system("cls"), system("mode con cols=50 lines=30");
	gto(10, 14), printf("为坠落的存档命名:");
	fflush(stdin);
	cin >> thisgamename;
	gto(15, 18), printf("选择你的难度!\n");
	int now = 1, lst = 0;
	string str[4] = {"", "Easy  ", "Medium", "Hard  "};
	gto(21, 15), printf("按下 [Esc] 退出选择");
	gto(20, 14), printf("使用左右箭头更改难度");
	gto(16, 18), printf("▁▁▁▁");
	if (xt == 10) {
		printf("▁▁▁▁");
	}
	gto(18, 18), printf("▔▔▔▔");
	if (xt == 10) {
		printf("▔▔▔▔");
	}
	gto(17, 18), printf("▏");
	gto(17, 26), printf("▏");
	Sleep(100);
	while (1) {
		Sleep(50);
		if (KEY_DOWN(37)) {
			now = max(1, now - 1);
			Sleep(30);
		}
		if (KEY_DOWN(39)) {
			now = min(3, now + 1);
			Sleep(30);
		}
		if (lst != now) {
			for (int i = 1; i <= 3; i++) {
				gto(17, (2 - now + i) * 10);
				cout << str[i];
			}
			if (lst < now) {
				gto(17, (6 - now) * 10), printf("       ");
			} else {
				gto(17, (2 - now) * 10), printf("       ");
			}
			gto(29, 39), lst = now;
		}
		if (KEY_DOWN(13)) {
			nandu = now;
			break;
		}
		if (KEY_DOWN(27)) return 0;
	}
	save(thisgamename);
	return 1;
}

vector<string> vec;
vector<int> dif, bol, baonum, sco, gotowhere, wrongs;
bool cundang() {
	vec.clear(), dif.clear(), bol.clear(), baonum.clear(), sco.clear();
	gotowhere.clear(), wrongs.clear();
	system("cls"), Sleep(100);
	struct _finddata_t filefind;
	string curr = "./*.save", now;
	int handle = _findfirst(curr.c_str(), &filefind);
	if (handle == -1) {
		gto(12, 6), color(12), printf("您还没有存档!按[Enter]返回!"), color(7);
		while (1) {
			Sleep(50);
			if (KEY_DOWN(13)) break;
		}
		return 0;
	}
	do {
		if (!strcmp(filefind.name, "..")) continue;
		now = filefind.name;
		now.erase(now.end() - 5, now.end());
		vec.push_back(now);
	} while (!(_findnext(handle, &filefind)));
	_findclose(handle);
	int num = vec.size(), which = 0, lst = 0, l;
	string str[4] = {"", "Easy", "Medium", "Hard"};
	for (int i = 0; i < num; i++) {
		if (!read(vec[i])) wrongs.push_back(1);
		else wrongs.push_back(0);
		dif.push_back(nandu);
		baonum.push_back(bao);
		bol.push_back(blood);
		sco.push_back(score);
		l = 1;
		while (op[l + 1]) l++;
		gotowhere.push_back(l);
	}
	all_clear();
A:
	system("cls");
	gto(0, 5), printf("press [Enter] to chose;");
	gto(1, 5), printf("press [Delete] to remove;");
	gto(2, 5), printf("press [Esc] to exit.");
	for (int i = 0; i < num; i++) {
		if (wrongs[i]) {
			gto((i + 1) * 3 + 1, 1), color(12);
			printf("[ 此 存 档 出 现 问 题, 无 法 读 取 ]"), color(7);
			continue;
		}
		gto((i + 1) * 3 + 1, 4), printf("血量: %d", bol[i]);
		gto((i + 1) * 3 + 1, 14), printf("血包数: %d", baonum[i]);
		gto((i + 1) * 3 + 1, 27), printf("积分: %d", sco[i]);
		gto((i + 1) * 3 + 2, 10);
		(gotowhere[i] >= 6 ? printf("已通关") : printf("第 %d 关", gotowhere[i]));
	}
B:
	for (int i = 0; i < num; i++) {
		gto((i + 1) * 3, 6);
		if (i == which) color(12);
		cout << vec[i];
		gto((i + 1) * 3, 30);
		cout << str[dif[i]];
		if (i == which) color(7);
	}
	gto(29, 39);
	while (1) {
		Sleep(50);
		if (KEY_DOWN(40)) {
			which = min(num - 1, which + 1);
			Sleep(30);
		}
		if (KEY_DOWN(38)) {
			which = max(0, which - 1);
			Sleep(30);
		}
		if (which != lst) {
			lst = which;
			goto B;
		}
		if (KEY_DOWN(13) && wrongs[which] == 0) {
			thisgamename = vec[which];
			read(thisgamename);
			break;
		}
		if (KEY_DOWN(46)) {
			thisgamename = vec[which];
			dlt(thisgamename);
			vec.erase(vec.begin() + which);
			dif.erase(dif.begin() + which);
			bol.erase(bol.begin() + which);
			baonum.erase(baonum.begin() + which);
			sco.erase(sco.begin() + which);
			gotowhere.erase(gotowhere.begin() + which);
			wrongs.erase(wrongs.begin() + which);
			num--, which = 0;
			goto A;
		}
		if (KEY_DOWN(27) || num == 0) return 0;
	}
	return 1;
}

void dlt(string name) {
	name += ".save";
	char ch[30];
	memset(ch, 0, sizeof ch);
	for (unsigned int i = 0; i < name.size(); i++) {
		ch[i] = name[i];
	}
	char *s = ch;
	remove(s);
}

void jiaocheng() {
	system("mode con cols=50 lines=25");
	gto(3, 0), sout("你是村里的年轻人\n最近村里正在招募“勇士”\n只有通过村北边的迷宫,才能受到大家的认可!\n", 1);
	system("pause");
	system("cls"), gto(3, 0);
	sout("迷宫总共有5关,规模会随着进行的关数增大\n迷宫里还有各种陷阱\n很可能会命丧黄泉!!\n", 1);
	system("pause");
	system("cls"), gto(3, 0), sout("接下来是迷宫的介绍:\n“", 1);
	color(119), cout << "  ", color(7);
	sout("”是墙\n“  ”是空气\n这些是破砖墙(肯定不是门)“国”\n有些墙上有暗门,是可以打开的!\n还有一些是迷雾弹,隐藏在墙中,会让你失明一阵子\n还有红色的炸弹,长这样:“", 1);
	color(12), printf("[]"), color(7);
	sout("”,爆炸的范围是3米,但是不会破坏墙壁\n和炸弹一样的是地雷,地雷会在你踩中它之后发出红光,然后爆炸\n", 1);
	system("pause"), system("cls"), gto(3, 0);
	sout("☆是可收集品!收集它可以得一积分,积分可以兑换技能!\n", 1);
	color(12), printf("☆"), color(7);
	sout("是血包!当你受伤的时候就可以按[Q]来回血!\n“", 1);
	color(10), printf("!!"), color(7);
	sout("”是终点,是可以把你传送到下一关的传送门!\n", 1);
	system("pause");
	system("cls"), gto(5, 10), sout("教程结束,去尽情闯关吧!!!\n", 1);
	system("pause"), system("cls");
	return ;
}

void sout(string a, int t) {
	t *= 25;
	int len = a.size();
	for (int i = 0; i < len; i++) {
		printf("%c", a[i]);
		Sleep(t);
	}
	return ;
}

bool to_start() {
	system("cls"), system("mode con cols=26 lines=5");
	gto(2, 3), printf("返回起始菜单吗?(Y/N)");
	while (1) {
		Sleep(50);
		if (KEY_DOWN('Y')) {
			return 1;
		} else if (KEY_DOWN('N')) {
			return 0;
		}
	}
}

int big[] = {0, 16, 20, 30, 40, 50};
bool game() {
	int keydown[] = {0, 49, 50, 51, 52, 53}, now;
	string bigturn[] = {"", "cols=54 lines=27", "cols=54 lines=30",
	                    "cols=74 lines=40", "cols=94 lines=50",
	                    "cols=114 lines=60"
	                   };
	op[1] = 1;
A:
	system("cls"), system("mode con cols=50 lines=25");
	if (isopen) {
		gto(8, 20), printf("按 [X] 进入商店");
	} else {
		gto(8, 20), color(8), printf("通过第 %d 关后解锁商店", (nandu == 3 ? 3 : 5)), color(7);
	}
	gto(11, 20), printf("按 [S] 更改键位");
	gto(14, 20), printf("按 [Esc] 退出");
	gto(3, 1), sout("请选择关卡\n\n\n\n", 1);
	for (int i = 1; i <= 5; i++) {
		if (op[i]) {
			printf("%d.%d x %d 迷宫\n\n", i, big[i], big[i]);
		} else {
			printf("%d.xxxxxxxxxxxx\n\n", i);
		}
	}
	bool k[10], whmod;
	memset(k, 0, sizeof k);
	while (1) {
		if (!KEY_DOWN(27)) isup[27] = 1;
		Sleep(30);
		for (int i = 1; i <= 5; i++) {
			if ((KEY_DOWN(keydown[i]) && op[i]) || k[i]) {
				string str = "mode con " + bigturn[i];
				char ch[30] = {0};
				for (unsigned int i = 0; i < str.size(); i++) {
					ch[i] = str[i];
				}
				whmod = whichmod(i);
				system(ch);
				now = gq(big[i], whmod);
				if (now == 0) {
					lose(i);
					return 1;
				} else if (now == 1) {
					op[i + 1] = 1;
					save(thisgamename);
					goto A;
				} else if (now == 2) {
					if (i == 5) {
						win();
						goto A;
					} else {
						op[i + 1] = k[i + 1] = 1;
						save(thisgamename);
					}
				}
				Sleep(30);
			}
		}
		if (isopen && KEY_DOWN('X')) {
			shop(), save(thisgamename), Sleep(30);
			goto A;
		}
		if (KEY_DOWN('S')) {
			setkey();
			goto A;
		}
		if (isup[27] && KEY_DOWN(27)) {
			isup[27] = 0;
			return to_start();
		}
	}
}

bool whichmod(int n) {
	if (!op[n + 1]) {
		return 1;
	}
	system("cls"), system("mode con cols=26 lines=5");
	gto(2, 3), printf("进入扫荡模式?(Y/N)");
A:
	if (KEY_DOWN('Y')) {
		return 0;
	} else if (KEY_DOWN('N')) {
		return 1;
	} else {
		goto A;
	}
}

void shop() {
A:
	vector<void(*)()>Funcs = {shop, scoshop, huishou, jinengshop};
	system("cls"), system("mode con cols=50 lines=10");
	int now = 1, lst = 1;
	color(7), gto(2, 23), printf("商店");
	string shopname[] = {"", "7-11 Shop", "Garbage Dumps", "Skill Shop"};
	for (int i = 1; i <= 3; i++) {
		gto(5, i * 15 - 12);
		cout << shopname[i];
	}
B:
	for (int i = 1; i <= 3; i++) {
		if (now == i) color(12);
		gto(7, i * 15 - 9), printf("进入");
		if (now == i) color(7);
	}
	while (1) {
		Sleep(50);
		if (KEY_DOWN(37)) now = max(1, now - 1), Sleep(30);
		if (KEY_DOWN(39)) now = min(3, now + 1), Sleep(30);
		if (lst != now) {
			lst = now;
			goto B;
		}
		if (KEY_DOWN(13)) {
			Funcs[now]();
			save(thisgamename), Sleep(30);
			goto A;
		}
		if (KEY_DOWN(27)) break;
	}
}

void huishou() {
	system("cls"), system("mode con cols=50 lines=30");
	int now = 1, lst = 1;
	color(7), gto(2, 23), printf("当铺");
	string goods[] = {"", "血包", "[感知] 体验卡", "[跃迁] 体验卡", "[拆弹专家] 体验卡", "[拿钱卖命] 体验卡"};
	for (int i = 1; i <= 5; i++) {
		gto(i * 4 + 4, 4), cout << goods[i];
		gto(i * 4 + 4, 32), printf("收购价:%d 积分", costsco[i + 4] - 5);
	}
A:
	gto(1, 35), printf("积分:%d     ", score);
	for (int i = 1; i <= 5; i++) {
		if (now == i) color(13);
		gto(i * 4 + 4, 26), printf("卖出");
		if (now == i) color(7);
		if (have[i + 4]) gto(i * 4 + 5, 23), printf("还剩余 %d 个  ", have[i + 4]);
	}
	while (1) {
		Sleep(50);
		if (KEY_DOWN(40)) {
			now = min(5, now + 1);
			Sleep(30);
		}
		if (KEY_DOWN(38)) {
			now = max(1, now - 1);
			Sleep(30);
		}
		if (now != lst) {
			lst = now;
			goto A;
		}
		if (KEY_DOWN(13) && have[now + 4]) {
			score += costsco[now + 4] - 5;
			have[now + 4]--;
			if (now == 1) bao--;
			save(thisgamename);
			goto A;
		}
		if (KEY_DOWN(27)) break;
	}
}

void scoshop() {
	system("cls"), system("mode con cols=50 lines=30");
	int now = 1, lst = 1;
	color(7), gto(2, 11), printf("7-11 商店");
	string goods[] = {"", "血包", "[感知] 体验卡", "[跃迁] 体验卡", "[拆弹专家] 体验卡", "[拿钱卖命] 体验卡"};
	string statement[] = {"", "购买血包", "一次性使用", "一次性使用", "一次性使用", "一次性使用"};
	for (int i = 1; i <= 5; i++) {
		gto(i * 4 + 4, 4), cout << goods[i];
		gto(i * 4 + 4, 32), printf("这将花费 %d 积分", costsco[i + 4]);
		gto(i * 4 + 5, 5), printf("使用此消耗品会");
		cout << (needblo[i + 4] >= 0 ? "损失" : "获得");
		color(12), printf(" %d ", abs(needblo[i + 4])), color(7), printf("滴血");
		gto(i * 4 + 6, 5), cout << statement[i];
	}
A:
	gto(1, 35), printf("积分:%d     ", score);
	for (int i = 1; i <= 5; i++) {
		if (now == i) color(13);
		gto(i * 4 + 4, 26), printf("购买");
		if (now == i) color(7);
		if (have[i + 4]) gto(i * 4 + 3, 24), printf("已拥有 %d 个", have[i + 4]);
	}
	while (1) {
		Sleep(50);
		if (KEY_DOWN(40)) {
			now = min(5, now + 1);
			Sleep(30);
		}
		if (KEY_DOWN(38)) {
			now = max(1, now - 1);
			Sleep(30);
		}
		if (now != lst) {
			lst = now;
			goto A;
		}
		if (KEY_DOWN(13) && score >= costsco[now + 4]) {
			score -= costsco[now + 4];
			have[now + 4]++;
			if (now == 1) bao++;
			save(thisgamename);
			goto A;
		}
		if (KEY_DOWN(27)) break;
	}
}

void jinengshop() {
	system("cls"), system("mode con cols=50 lines=26");
	int now = 1, lst = 1;
	color(7), gto(2, 11), printf("寄能商店");
	string jineng[] = {"", "感知", "跃迁", "拆弹专家", "拿钱卖命"};
	string statement[] = {"", "长按 [Z] 可以感知所有暗门和“傻瓜蛋”",
	                      "面对墙按下 [A] 可以穿墙而过",
	                      "踩到炸药时有 40% 的几率不将其引爆",
	                      "无血包时按下 [Q] 会花费 10 积分回 1 点血"
	                     };
	for (int i = 1; i <= 4; i++) {
		gto(i * 4 + 4, 10), cout << jineng[i];
		if (!have[i]) {
			gto(i * 4 + 4, 32), printf("这将花费 %d 积分", costsco[i]);
		}
		gto(i * 4 + 5, 5), printf("使用此寄能会");
		cout << (needblo[i] >= 0 ? "损失" : "获得");
		color(12), printf(" %d ", abs(needblo[i])), color(7), printf("滴血");
		gto(i * 4 + 6, 5), cout << statement[i];
	}
A:
	gto(1, 35), printf("积分:%d     ", score);
	for (int i = 1; i <= 4; i++) {
		if (now == i) color(13);
		gto(i * 4 + 4, 20), printf((have[i] ? "已拥有" : "购买"));
		if (now == i) color(7);
	}
	while (1) {
		Sleep(50);
		if (KEY_DOWN(40)) {
			now = min(4, now + 1);
			Sleep(30);
		}
		if (KEY_DOWN(38)) {
			now = max(1, now - 1);
			Sleep(30);
		}
		if (now != lst) {
			lst = now;
			goto A;
		}
		if (KEY_DOWN(13) && !have[now] && score >= costsco[now]) {
			score -= costsco[now];
			have[now] = 1;
			gto(now * 4 + 4, 32);
			printf("                ");
			save(thisgamename);
			goto A;
		}
		if (KEY_DOWN(27)) break;
	}
}

void lose(int num) {
	system("cls");
	system("mode con cols=50 lines=30");
	gto(10, 0), sout("很可惜,你离勇者只差", 1), printf("  %d  ", 5 - num);
	sout("个关卡了!!!\n", 1);
	system("pause"), system("cls");
	sout("你成功被村民们抢救了回来!\n你以后在村庄里将怎样生存呢?\n   ", 1);
	gto(10, 10), sout("未完待续......", 3), system("pause");
	return ;
}

void win() {
	op[6] = isopen = 1;
	save(thisgamename);
	system("cls"), system("mode con cols=50 lines=30"), gto(10, 10);
	sout("恭喜你!你成功闯过了这些复杂的迷宫!\n你是村里唯一成为的 “勇者” 的人!!\n\n", 1);
	system("pause");
	system("cls"), gto(10, 10), sout("成为勇者后的你将会怎么样呢?   ", 1);
	gto(13, 10), sout("未完待续......", 3);
	system("pause");
	return ;
}

bool vis[200][200];
int gq(int n, bool mod) {
	int nowb = blood, nows = score, nowba = bao;
	int nowhave[maxn];
	for (int i = 1; i < maxn; i++) {
		nowhave[i] = have[i];
	}
Q:
	system("cls");
	memset(vis, 0, sizeof vis);
	for (int i = 1; i < maxn; i++) {
		have[i] = nowhave[i];
	}
	facing = 3;
	boomclear();
	blood = nowb, score = nows, bao = nowba;
	sgless = issg = 0;
	rx = 2, ry = 1;
	update(n), addvis(n), mpout(n, mod), manout(n), boardout(n);
	while (1) {
		Sleep(50);
		for (int i = 1; i <= 4; i++) {
			if (KEY_DOWN(whichkey[2 + i]) || KEY_DOWN(whichkey[6 + i])) {
				int x0 = rx + dir[i][0], y0 = ry + dir[i][1];
				facing = i;
				if (mp[x0][y0] == 1 || mp[x0][y0] == 9) {
					continue;
				}
				goofput(rx, ry);
				rx = min(n, max(1, x0));
				ry = min(n, max(1, y0));
				addvis(n), manout(n);
				if (mp[rx][ry] == 7) {
					score++;
					boardout(n);
				} else if (mp[rx][ry] == 8) {
					bao++;
					boardout(n);
				}
			}
		}
		if (KEY_DOWN(whichkey[0]) && blood < 10) {
			if (bao >= 1) {
				blood = min(10, blood + 2);
				bao--;
			} else if ((have[4] || have[9]) && score >= 10) {
				if (!have[4]) {
					have[9]--;
				}
				score -= 10;
				blood++;
			}
			boardout(n);
		} else if (KEY_DOWN(whichkey[1])) {
			look(n, mod);
		} else if (KEY_DOWN(whichkey[2])) {
			go_though(rx, ry, n);
		}
		if (issg) {
			sgless--;
			if (sgless == 0) {
				issg = 0;
				addvis(n), mpout(n, mod), manout(n);
			}
		}
		booom(n, mod);
		if (blood <= 0) {
			system("cls"), gto(4, 10), sout("你死了……", 3);
			Sleep(3000);
			gto(10, 10), sout("1.重生     2.退出游戏", 1);
			while (1) {
				if (KEY_DOWN(49)) {
					goto Q;
				} else if (KEY_DOWN(50)) {
					for (int i = 1; i < maxn; i++) {
						have[i] = nowhave[i];
					}
					blood = nowb, score = nows, bao = nowba;
					return 0;
				}
			}
		}
		if (mp[rx][ry] == 2) {
			system("cls"), gto(10, 10), sout("恭喜你!闯过了这一关!!", 1);
			gto(13, 10), sout("1.回家   2.下一关", 1);
			save(thisgamename);
			while (1) {
				if (KEY_DOWN(49) && n != 50) {
					return 1;
				} else if (KEY_DOWN(50) || (KEY_DOWN(49) && n == 50)) {
					return 2;
				}
			}
		}
	}
}

bool checkup(int x, int y, int n) {
	return x > 0 && y > 0 && x <= n + 1 && y <= n;
}

bool notwall(int x, int y) {
	return mp[x][y] != 1 && mp[x][y] != 9;
}

bool isair(int x, int y) {
	return notwall(x, y) && mp[x][y] != 3 && mp[x][y] != 4;
}

void prt(int x, int y) {
	gto(x + 4, (y - 1) * 2);
	if (issg) {
		printf("  ");
	} else {
		color(blocks[mp[x][y]].clr);
		printf(blocks[mp[x][y]].ch);
		color(7);
	}
}

void addop(int x, int y, int n, int face = facing) {
	int bak = (face + 1) % 4 + 1;
	int lx = x + dir[face][0], ly = y + dir[face][1];
	int gx = x + dir[bak][0], gy = y + dir[bak][1];
	if (checkup(x, y, n) && !vis[x][y]) prt(x, y), vis[x][y] = 1;
	if (checkup(lx, ly, n) && !isair(lx, ly) && !vis[lx][ly]) prt(lx, ly), vis[lx][ly] = 1;
	if (checkup(gx, gy, n) && !isair(gx, gy) && !vis[gx][gy]) prt(gx, gy), vis[gx][gy] = 1;
}

void addvis(int n) {
	int lft = (facing + 2) % 4 + 1, rgt = (facing) % 4 + 1;
	int lfx = rx + dir[lft][0], lfy = ry + dir[lft][1];
	int rgx = rx + dir[rgt][0], rgy = ry + dir[rgt][1];
	if (!issg && isair(lfx, lfy)) {
		lfx += dir[lft][0], lfy += dir[lft][1];
		if (checkup(lfx, lfy, n)) addop(lfx, lfy, n);
	}
	if (!issg && isair(rgx, rgy)) {
		rgx += dir[rgt][0], rgy += dir[rgt][1];
		if (checkup(rgx, rgy, n)) addop(rgx, rgy, n);
	}
	int x = rx, y = ry, lx, ly, gx, gy;
	while ((isair(x, y) || (mp[rx][ry] == 3 && x == rx && y == ry))
	        && checkup(x, y, n)) {
		lx = x + dir[lft][0], ly = y + dir[lft][1];
		gx = x + dir[rgt][0], gy = y + dir[rgt][1];
		if (checkup(x, y, n) && !vis[x][y]) prt(x, y), vis[x][y] = 1;
		if (checkup(lx, ly, n) && !vis[lx][ly]) prt(lx, ly), vis[lx][ly] = 1;
		if (checkup(gx, gy, n) && !vis[gx][gy]) prt(gx, gy), vis[gx][gy] = 1;
		x += dir[facing][0], y += dir[facing][1];
	}
	addop(x, y, n, lft);
}

void go_though(int x, int y, int n) {
	goofput(rx, ry);
	x = x + dir[facing][0], y = y + dir[facing][1];
	if (!(have[2] || have[7]) || blood <= needblo[2] || (mp[x][y] != 1
	        && mp[x][y] != 9)) {
		return ;
	}
	while (!notwall(x, y)) {
		x = x + dir[facing][0], y = y + dir[facing][1];
	}
	if (checkup(x, y, n)) {
		rx = x, ry = y;
		blood -= needblo[2];
		if (!have[2]) have[7]--;
		addvis(n), manout(n), boardout(n);
	}
}

void mpout(int n, bool mod) {
	gto(5, 0), color(7);
	for (int i = 1; i <= n + 1; i++) {
		for (int l = 1; l <= n; l++) {
			if (mod && !vis[i][l]) {
				printf("  ");
			} else {
				color(blocks[mp[i][l]].clr);
				printf(blocks[mp[i][l]].ch);
				color(7);
			}
		}
		printf("\n");
	}
}

void boardout(int n) {
	color(7);
	gto(4, 5), printf("score:%d  ", score);
	gto(2, 5), printf("blood: ");
	if (blood <= 3) {
		color(77);
	} else if (blood <= 6) {
		color(221);
	} else {
		color(170);
	}
	for (int i = 1; i <= blood; i++) {
		printf("  ");
	}
	color(7);
	for (int i = blood; i < 10; i++) {
		printf("  ");
	}
	printf("▏");
	if (xt == 10) {
		gto(1, 12), printf("▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁");
		gto(3, 12), printf("▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔");
	} else {
		gto(1, 12), printf("▁▁▁▁▁▁▁▁▁▁");
		gto(3, 12), printf("▔▔▔▔▔▔▔▔▔▔");
	}
	gto(4, 20), color(12), printf("★:%d  ", bao), color(7);
	char str[][50] = {"", "感知", "跃迁", "[被动] 拆弹专家", "拿钱卖命"};
	int ftog[] = {0, 1, 2, 0, 0};
	gto(n + 7, 2), printf("                         ");
	gto(n + 7, 29), printf("                         ");
	gto(n + 8, 2), printf("                         ");
	gto(n + 8, 29), printf("                         ");
	int cnt = 1;
	for (int i = 1; i <= 4; i++) {
		gto((cnt + 1) / 2 + n + 6, (((cnt + 1) & 1) + 1) * 27 - 25);
		if (have[i] || have[i + 5]) {
			if (i == 3) printf("%s  ", str[i]);
			else printf("[%c] %s  ", whichkey[ftog[i]], str[i]);
			printf((!have[i] ? "剩余%d张" : "%c"), (!have[i] ? have[i + 5] : ' '));
			cnt++;
		}
	}
}

void goofput(int x, int y) {
	color(7), gto(x + 4, (y - 1) * 2);
	if (mp[x][y] == 7 || mp[x][y] == 8) {
		mp[x][y] = 0;
	}
	if (issg) {
		printf("  ");
	} else {
		color(blocks[mp[x][y]].clr);
		printf(blocks[mp[x][y]].ch);
		color(7);
	}
	return ;
}

void look(int n, bool mod) {
	if (!(have[1] || have[6]) || blood <= needblo[1] || issg) {
		return ;
	}
	if (!have[1]) {
		have[6]--;
	}
	blood -= needblo[1];
	boardout(n);
	for (int i = 1; i <= n; i++) {
		for (int l = 1; l <= n; l++) {
			if (mp[i][l] == 3 || mp[i][l] == 4) {
				gto(i + 4, (l - 1) * 2), color(13), printf("▎");
				if (xt == 10) {
					printf(" ");
				}
				color(7);
			}
		}
	}
	while (KEY_DOWN(90));
	for (int i = 1; i <= n; i++) {
		for (int l = 1; l <= n; l++) {
			if ((!mod || (mod && vis[i][l])) && (mp[i][l] == 3 || mp[i][l] == 4)) {
				gto(i + 4, (l - 1) * 2), color(119), printf("  "), color(7);
			} else if (mp[i][l] == 3 || mp[i][l] == 4) {
				gto(i + 4, (l - 1) * 2), printf("  ");
			}
		}
	}
}

void mpout(int x, int y, bool isbig, bool mod) {
	color(7);
	for (int i = x; i <= x + (isbig ? 4 : 2); i++) {
		for (int l = max(y, 1); l <= y + (isbig ? 4 : 2); l++) {
			gto(i + 4, (l - 1) * 2);
			if (issg || (mod && !vis[i][l])) {
				printf("  ");
			} else {
				color(blocks[mp[i][l]].clr);
				printf(blocks[mp[i][l]].ch);
				color(7);
			}
		}
	}
}

void booom(int n, bool mod) {
	srand((unsigned)time(0));
	for (int i = rlen; i < len; i++) {
		boomm[i]--;
	}
	bool isbig;
	for (int i = rlen; i < len; i++) {
		if (boomm[i] > 0) continue;
		node now = boom.front();
		rlen++, boom.pop(), mp[now.x][now.y] = 0, isbig = 0;
		if (nandu != 1 && rnk(rand()) % 20 < 4)
			isbig = 1;
		if (rx == now.x && ry == now.y) {
			blood -= (isbig ? 4 : 3), boardout(n);
		} else if (rx >= now.x - 1 && rx <= now.x + 1 && ry >= now.y - 1
		           && ry <= now.y + 1) {
			blood -= (isbig ? 3 : 2), boardout(n);
		} else if (isbig && (rx >= now.x - 2 && rx <= now.x + 2 && ry >= now.y - 2
		                     && ry <= now.y + 2)) {
			blood--, boardout(n);
		}
		color(192);
		for (int i = now.x - (isbig ? 2 : 1); i <= now.x + (isbig ? 2 : 1); i++) {
			for (int l = max(now.y - (isbig ? 2 : 1), 1); l <= now.y + (isbig ? 2 : 1); l++) {
				gto(i + 4, (l - 1) * 2);
				printf("  ");
			}
		}
		Sleep(200);
		for (int i = max(1, now.x - (isbig ? 2 : 1)); i <= now.x + (isbig ? 2 : 1); i++) {
			for (int l = max(1, now.y - (isbig ? 2 : 1)); l <= now.y + (isbig ? 2 : 1); l++) {
				if (mp[i][l] == 5 || mp[i][l] == 6) {
					boom.push({i, l});
					if (mp[i][l] == 6) {
						boomm[len] = 5;
					} else {
						boomm[len] = 15;
					}
					mp[i][l] = 10;
					len++;
				} else if (mp[i][l] != 9 && mp[i][l] != 1 && mp[i][l] != 2 && mp[i][l] != 10) {
					mp[i][l] = 0;
				} else if (isbig && mp[i][l] == 9 && rnk(rand()) % 20 < 4) {
					mp[i][l] = 0;
				}
				if (mp[i][l] == 1 && rand() % 5 == 0) {
					mp[i][l] = 9;
				}
			}
		}
		mpout(now.x - (isbig ? 2 : 1), now.y - (isbig ? 2 : 1), isbig, mod);
		manout(n);
	}
}

int rnk(int x, bool y) {
	int a;
	if (y) a = rand() % 1145 + 1, x *= a;
	x ^= x << 17;
	x ^= x >> 7;
	x ^= x << 13;
	if (y) x /= a;
	return abs(x);
}

void manout(int n) {
	gto(rx + 4, (ry - 1) * 2);
	if (mp[rx][ry] == 3) {
		if (issg) color(8);
		else color(224);
		printf("▎"), color(7);
		if (xt == 10)
			printf(" ");
	} else if (mp[rx][ry] == 4) {
		sgless = 150, issg = 1, mp[rx][ry] = 0;
		system("cls"), boardout(n), gto(rx + 4, (ry - 1) * 2), printf("♀");
	} else if (mp[rx][ry] == 6 || mp[rx][ry] == 5) {
		node now = {rx, ry};
		if (issg) color(7);
		else color(224);
		printf("♀");
		if (!(have[3] || have[8]) || (rnk(rand()) % 20 >= 8)) {
			boom.push(now);
			if (mp[rx][ry] == 6) boomm[len] = 5;
			else boomm[len] = 15;
			len++;
			mp[rx][ry] = 10;
		} else {
			if (!have[3]) have[8]--;
			mp[rx][ry] = 0, boardout(n);
		}
	} else if (mp[rx][ry] == 7) {
		if (issg) color(7);
		else color(231);
		printf("★");
	} else if (mp[rx][ry] == 8) {
		if (issg) color(12);
		else color(236);
		printf("★"), color(7);
	} else {
		if (issg) color(7);
		else color(224);
		printf("♀");
	}
	color(7);
}

void update(int L) {
	float k = 1.0 * (4 - nandu) / 2.0;
	for (int i = 0; i <= L + 1; i++) {
		for (int l = 0; l < L + 1; l++) {
			mp[i][l] = 1;
		}
	}
	srand((unsigned)time(0));
	for (int i = 0; i < L; i++) {
		mp[0][i] = mp[i][0] = 0;
		mp[i][L - 1] = mp[L - 1][i] = 1;
	}
	vector<int> X, Y;
	X.push_back(2), Y.push_back(2);
	int r, x, y, count;
	while (X.size()) {
		r = rand() % X.size();
		x = X[r], y = Y[r];
		count = 0;
		for (int i = x - 1; i < x + 2; i++) {
			for (int j = y - 1; j < y + 2; j++) {
				if (abs(x - i) + abs(y - j) == 1 && mp[i][j] == 0) {
					count++;
				}
			}
		}
		if (count <= 1) {
			mp[x][y] = 0;
			for (int i = x - 1; i < x + 2; i++) {
				for (int j = y - 1; j < y + 2; j++) {
					if (abs(x - i) + abs(y - j) == 1 && mp[i][j] == 1) {
						X.push_back(i), Y.push_back(j);
					}
				}
			}
		}
		X.erase(X.begin() + r), Y.erase(Y.begin() + r);
	}
	for (int i = L; i >= 0; i--) {
		if (mp[i][L - 1] == 0) {
			mp[i][L] = 2;
			break;
		}
	}
	for (int i = 1; i <= (L * 2 / 3) / k; i++) { //暗门
	A:
		x = rand() % L + 1, y = rand() % L + 1;
		if (mp[x][y] == 0) {
			mp[x][y] = 3;
		} else {
			goto A;
		}
	}
	for (int i = 1; i <= (L / 3) / k; i++) { //傻瓜蛋
	B:
		x = rand() % L + 1;
		y = rand() % L + 1;
		if (mp[x][y] == 0) {
			mp[x][y] = 4;
		} else {
			goto B;
		}
	}
	for (int i = 1; i <= L / k; i++) { //炸弹
	C:
		x = rand() % L + 1, y = rand() % L + 1;
		if (mp[x][y] == 0) {
			mp[x][y] = 5;
		} else {
			goto C;
		}
	}
	for (int i = 1; i <= (L / 2) / k; i++) { //地雷
	D:
		x = rand() % L + 1, y = rand() % L + 1;
		if (mp[x][y] == 0) {
			mp[x][y] = 6;
		} else {
			goto D;
		}
	}
	for (int i = 1; i <= L / 2; i++) { //星星
	E:
		x = rand() % L + 1, y = rand() % L + 1;
		if (mp[x][y] == 0) {
			mp[x][y] = 7;
		} else {
			goto E;
		}
	}
	for (int i = 1; i <= int(1.0 * log(L) / log(2)) * k; i++) { //血包
	F:
		x = rand() % L + 1, y = rand() % L + 1;
		if (mp[x][y] == 0) {
			mp[x][y] = 8;
		} else {
			goto F;
		}
	}
	for (int i = 1; i <= L / 4; i++) { //碎石
	G:
		x = rand() % L + 1, y = rand() % L + 1;
		if (mp[x][y] == 1) {
			mp[x][y] = 9;
		} else {
			goto G;
		}
	}
	mp[2][1] = 0, mp[L][1] = mp[L - 1][1] = 1;
	return ;
}

void boomclear() {
	while (!boom.empty()) {
		boom.pop();
	}
	for (int i = 1; i <= len; i++) {
		boomm[i] = 0;
	}
	len = rlen = 1;
	return ;
}
原文
存档评论6 条抓取于