懒人免安装版本
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#include"maze.h"
using namespace std;
int langu = 1, sthe = 0, speed = 100, n = 15, m = 15, radius = 3, type = 3, methodcount = 4, themecount = 3, gamemode = 5;
string mode = "11010";
enum colorsf {
red = FOREGROUND_INTENSITY | FOREGROUND_RED,
green = FOREGROUND_INTENSITY | FOREGROUND_GREEN,
blue = FOREGROUND_INTENSITY | FOREGROUND_BLUE,
yellow = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN,
pink = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE,
cyan = FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE,
white = FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
};
enum colorsb {
redb = BACKGROUND_INTENSITY | BACKGROUND_RED,
greenb = BACKGROUND_INTENSITY | BACKGROUND_GREEN,
blueb = BACKGROUND_INTENSITY | BACKGROUND_BLUE,
yellowb = BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN,
pinkb = BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_BLUE,
cyanb = BACKGROUND_INTENSITY | BACKGROUND_GREEN | BACKGROUND_BLUE,
whiteb = BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE
};
string menu_c[100] = {"更新日志", "操作说明", "设置", "开始游戏"};
string menu_e[100] = {"Change log", "Operation instruction", "Settings", "Start game"};
string set_c[100] = {"切换语言", "切换主题", "迷宫设置"};
string set_e[100] = {"Change language", "Change theme", "Change the maze"};
string lan[100] = {"中文", "English"};
string tip_c = "用上下键进行选择,z或enter键进行确定,x或shift键取消(退出)。";
string tip_e = "use up/down arrow to select, press 'z' or 'enter' to select, press 'x' or 'shift' to cancel(exit).";
string thtip_c = "框选主题以预览,z或enter键确定,x或shift键取消";
string thtip_e =
"frame select the theme to preview, press 'z' or 'enter' to determine the theme, press 'x' or 'shift' to cancel";
string theme_c[100] = {"米黄色", "五颜六色", "全白"};
string theme_e[100] = {"beige", "colorful", "white"};
string name_c[100] = {"生成方式", "迷宫行数", "迷宫列数", "迷宫可视范围(输入 0 全屏)", "是否按h键可以提示?", "是否加尖刺?", "是否启动钥匙模式?", "怪物数量?","几个迷宫?"};
string name_e[100] = {
"Maze generation method", "The row of the maze", "The column of the maze",
"The range of visibility of the maze (enter 0 to select full screen)", "Enable press h key to get a hint?",
"Enable spike?", "Enable key mode?", "How many monster?", "How many mazes?"
};
int sel_tc[100]={2,2,2,10,9};
string sel_c[100][100] = {
{"DFS生成", "A*生成", "Kruskal生成", "BFS生成"}, {"int", "5", "200"}, {"int", "5", "200"}, {"int", "0", "50"}, {"否", "是"},
{"否", "是"}, {"否", "是"}, {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}, {"1", "2", "3", "4", "5", "6", "7", "8", "9"}
};
string sel_e[100][100] = {
{"DFS spanning", "A* spanning", "Kruskal spanning", "BFS spanning"}, {"int", "5", "200"}, {"int", "5", "200"},
{"int", "0", "50"}, {"No", "Yes"}, {"No", "Yes"}, {"No", "Yes"}, {"1", "2", "3", "4", "5", "6", "7", "8", "9"},
{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}
};
string exitmaze_c[100] = {"退出", "返回"};
string exitmaze_e[100] = {"give up", "resume"};
string changel_c = R"(3.4 增加同时玩多个迷宫的模式。
3.3 添加怪物。
3.2 优化钥匙模式,增加游戏说明。
3.1 增加钥匙模式。
3.0 大更新了,自己探索一下更新了些什么吧!
2.6 美化迷宫的UI。
2.5 增加了真正的BFS生成,同时修复了英文版本中的一些语法错误。
2.4 支持在玩的时候按shift键退出了!
2.3 加强了一下A*生成。
2.2 修复了一个BUG。
2.1 将BFS生成改为A*生成,并增加 Kruskal生成。
同时修复了一些错字(词)。
2.0 更改成了一个更好的UI,并添加了BFS生成方式!
1.1 [机翻]新UI!您可以使用默认设置!
1.0 [机翻]拥有DFS生成!)";
string changel_e = R"(3.4 Added a mode that you can play more mazes at once.
3.3 Added monster.
3.2 Optimized key mode and added operation instruction.
3.1 Added key mode.
3.0 BIG update!Explore what is updated by yourself!
2.6 Made a better UI for the maze.
2.5 Added the real BFS spanning, and fixed some grammatical errors in English version.
2.4 Now you can give up by pressing 'shift' while playing!
2.3 A* spanning is more difficult than before.
2.2 Fixed a bug.
2.1 Renamed BFS spanning to A* spanning,and added Kruskal spanning.
And fixed some typo, too.
2.0 Changed into a better UI, and add BFS spanning!
1.1 New UI! You can use default setting!
1.0 Have DFS spanning!)";
string control_c = R"(浅蓝色是你,蓝色是终点。
按上下左右键来移动。
红色是尖刺,碰到会死。
紫色是怪物,会随机移动,碰到也会死。
钥匙模式中,黄色是钥匙,深蓝色是门,你需要有钥匙才能穿过门。
按h键可以获得到终点的路径的提示,如果钥匙模式中你还没有钥匙,那么会先提示到钥匙的路径。)";
string control_e = R"(Light blue is you, and blue is the end.
Use the arrow keys to move.
Red are spikes, touching them will kill you.
Purple are monsters, will move randomly, touching them will kill you, too.
In the key mode, yellow is the key, deep blue is the door, you need a key to pass through the door.
Pressing the "h" key will give you a hint on the path to the end, if you don't have a key in key mode, it will first give you a hint on the path to the key.)";
string logtip_c = "按下x或shift键退出";
string logtip_e = "press 'x' or 'shift' to exit";
string logcmaze_c = "按下x或shift键保存并退出";
string logcmaze_e = "press 'x' or 'shift' to save and exit";
struct theme {
int title, s, t, tip;
} themes[103] = {
{0x0E, 0x0E, white, 0x0E},
{red, green, white, pink},
{white, white, white, white}
};
void gotoxy(int x, int y) {
COORD pos;
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void hidecursor() {
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}
enum UTkey {
up = 1, down = 2, leftt = 3, rightt = 4, hint = 5, enter = 6, shift = 7
};
template<typename T>
void ccolor(T str, int col) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), col);
cout << str;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
}
string chars(string ch, int times) {
string s = "";
for (int i = 1; i <= times; i++)
s += ch;
return s;
}
bool pressing(int x) {
return GetAsyncKeyState(toupper(x)) & 0x8000;
}
int scanc(int await = 250) {
Sleep(await);
while (1) {
if (pressing(VK_UP))
return up;
if (pressing(VK_DOWN))
return down;
if (pressing(VK_LEFT))
return leftt;
if (pressing(VK_RIGHT))
return rightt;
if (pressing('z'))
return enter;
if (pressing('h'))
return hint;
if (pressing(VK_RETURN))
return enter;
if (pressing('x'))
return shift;
if (pressing(VK_SHIFT)) {
keybd_event(VK_SHIFT, MapVirtualKey(VK_SHIFT, 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_SHIFT, MapVirtualKey(VK_SHIFT, 0), 0, 0);
keybd_event(VK_SHIFT, MapVirtualKey(VK_SHIFT, 0), KEYEVENTF_KEYUP, 0);
return shift;
}
}
}
int nawscanc() {
if (pressing(VK_UP))
return up;
if (pressing(VK_DOWN))
return down;
if (pressing(VK_LEFT))
return leftt;
if (pressing(VK_RIGHT))
return rightt;
if (pressing('z'))
return enter;
if (pressing('h'))
return hint;
if (pressing(VK_RETURN))
return enter;
if (pressing('x'))
return shift;
if (pressing(VK_SHIFT)) {
keybd_event(VK_SHIFT, MapVirtualKey(VK_SHIFT, 0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_SHIFT, MapVirtualKey(VK_SHIFT, 0), 0, 0);
keybd_event(VK_SHIFT, MapVirtualKey(VK_SHIFT, 0), KEYEVENTF_KEYUP, 0);
return shift;
}
return -1;
}
int selectwhat(string title, string text[], int textcount, string tip, int select) {
ccolor(title + "\n", themes[sthe].title);
for (int i = 0; i < textcount; i++)
ccolor("\n " + text[i] + "\n", themes[sthe].t);
cout << "\n";
ccolor(tip, themes[sthe].tip);
while (1) {
gotoxy(0, 2 * select + 1);
ccolor(chars("-", text[select].size() + 2), themes[sthe].s);
ccolor("\n|", themes[sthe].s);
gotoxy(text[select].size() + 1, 2 * select + 2);
ccolor("|\n", themes[sthe].s);
ccolor(chars("-", text[select].size() + 2), themes[sthe].s);
switch (scanc()) {
case up:
if (select != 0) {
gotoxy(0, 2 * select + 1);
ccolor(chars(" ", text[select].size() + 2), themes[sthe].s);
ccolor("\n ", themes[sthe].s);
gotoxy(text[select].size() + 1, 2 * select + 2);
ccolor(" \n", themes[sthe].s);
ccolor(chars(" ", text[select].size() + 2), themes[sthe].s);
select--;
}
break;
case down:
if (select < textcount - 1) {
gotoxy(0, 2 * select + 1);
ccolor(chars(" ", text[select].size() + 2), themes[sthe].s);
ccolor("\n ", themes[sthe].s);
gotoxy(text[select].size() + 1, 2 * select + 2);
ccolor(" \n", themes[sthe].s);
ccolor(chars(" ", text[select].size() + 2), themes[sthe].s);
select++;
}
break;
case enter:
return select;
case shift:
return -1;
}
}
}
void show_log() {
if (langu) {
ccolor("更新日志\n", themes[sthe].title);
ccolor(changel_c, themes[sthe].t);
cout << "\n";
ccolor(logtip_c, themes[sthe].tip);
} else {
ccolor("Change log\n", themes[sthe].title);
ccolor(changel_e, themes[sthe].t);
cout << "\n";
ccolor(logtip_e, themes[sthe].tip);
}
while (scanc() != shift);
system("cls");
}
void show_control() {
if (langu) {
ccolor("操作说明\n", themes[sthe].title);
ccolor(control_c, themes[sthe].t);
cout << "\n";
ccolor(logtip_c, themes[sthe].tip);
} else {
ccolor("Operation instruction\n", themes[sthe].title);
ccolor(control_e, themes[sthe].t);
cout << "\n";
ccolor(logtip_e, themes[sthe].tip);
}
while (scanc() != shift);
system("cls");
}
void cthe() {
int textcount = themecount;
string text[100], title, tip;
for (int i = 0; i < textcount; i++)
if (langu)
text[i] = theme_c[i];
else
text[i] = theme_e[i];
if (langu) {
title = "主题";
tip = thtip_c;
} else {
title = "theme";
tip = thtip_e;
}
int select = sthe;
ccolor(title + "\n", themes[select].title);
for (int i = 0; i < textcount; i++)
ccolor("\n " + text[i] + "\n", themes[select].t);
cout << "\n";
ccolor(tip, themes[select].tip);
gotoxy(0, 2 * select + 1);
ccolor(chars("-", text[select].size() + 2), themes[select].s);
ccolor("\n|", themes[select].s);
gotoxy(text[select].size() + 1, 2 * select + 2);
ccolor("|\n", themes[select].s);
ccolor(chars("-", text[select].size() + 2), themes[select].s);
while (1) {
switch (scanc()) {
case up:
if (select != 0)
select--;
break;
case down:
if (select < textcount - 1)
select++;
break;
case enter:
system("cls");
sthe = select;
return;
case shift:
system("cls");
return;
}
system("cls");
ccolor(title + "\n", themes[select].title);
for (int i = 0; i < textcount; i++)
ccolor("\n " + text[i] + "\n", themes[select].t);
cout << "\n";
ccolor(tip, themes[select].tip);
gotoxy(0, 2 * select + 1);
ccolor(chars("-", text[select].size() + 2), themes[select].s);
ccolor("\n|", themes[select].s);
gotoxy(text[select].size() + 1, 2 * select + 2);
ccolor("|\n", themes[select].s);
ccolor(chars("-", text[select].size() + 2), themes[select].s);
}
}
void clangu() {
int x = 1 - langu;
if (langu == 1)
x = selectwhat("语言", lan, 2, "", x);
else
x = selectwhat("Language", lan, 2, "", x);
system("cls");
switch (x) {
case 0:
langu = 1;
break;
case 1:
langu = 0;
break;
case -1:
return;
}
}
int selectnum(string title, string text, int init, int mi, int ma) {
assert(mi <= init && init <= ma);
ccolor(title + "\n", themes[sthe].title);
ccolor(text, themes[sthe].t);
ccolor(" " + to_string(init) + "\n", themes[sthe].s);
Sleep(250);
while (1) {
gotoxy(text.size() + 2, 1);
switch (scanc(100)) {
case leftt:
if (init != mi) {
init--;
ccolor(to_string(init) + " ", themes[sthe].s);
}
break;
case rightt:
if (init != ma) {
init++;
ccolor(to_string(init) + " ", themes[sthe].s);
}
break;
case enter:
return init;
case shift:
return -1;
}
}
}
void cmaze() {
int seled[100], select = 0, textcount = gamemode + 4;
string text[100], sel[100][100];
if (langu == 1) {
for (int i = 0; i < textcount; i++) {
text[i] = name_c[i];
for (int j = 0; j < 100; j++)
sel[i][j] = sel_c[i][j];
}
ccolor("迷宫设置\n", themes[sthe].title);
} else {
for (int i = 0; i < textcount; i++) {
text[i] = name_e[i];
for (int j = 0; j < 100; j++)
sel[i][j] = sel_e[i][j];
}
ccolor("Maze settings\n", themes[sthe].title);
}
seled[0] = type - 1;
seled[1] = n;
seled[2] = m;
seled[3] = radius;
for (int i = 0; i < gamemode; i++)
seled[i + 4] = mode[i] - '0';
for (int i = 0; i < textcount; i++)
if (i != 1 && i != 2 && i != 3) {
ccolor("\n " + text[i] + " : < ", themes[sthe].t);
ccolor(sel[i][seled[i]], themes[sthe].s);
ccolor(" >\n", themes[sthe].t);
} else {
ccolor("\n " + text[i] + " : < ", themes[sthe].t);
ccolor(seled[i], themes[sthe].s);
ccolor(" >\n", themes[sthe].t);
}
cout << "\n";
if (langu == 1)
ccolor(logcmaze_c, themes[sthe].tip);
else
ccolor(logcmaze_e, themes[sthe].tip);
while (1) {
gotoxy(0, 2 * select + 1);
ccolor(chars("-", text[select].size() + 2), themes[sthe].s);
ccolor("\n|", themes[sthe].s);
if (select != 1 && select != 2 && select != 3) {
ccolor(text[select], themes[sthe].t);
ccolor("|", themes[sthe].s);
ccolor(": < ", themes[sthe].t);
ccolor(sel[select][seled[select]], themes[sthe].s);
ccolor(" > \n", themes[sthe].t);
} else {
ccolor(text[select], themes[sthe].t);
ccolor("|", themes[sthe].s);
ccolor(": < ", themes[sthe].t);
ccolor(seled[select], themes[sthe].s);
ccolor(" > \n", themes[sthe].t);
}
ccolor(chars("-", text[select].size() + 2), themes[sthe].s);
switch (scanc(100)) {
case up:
if (select != 0) {
gotoxy(0, 2 * select + 1);
ccolor(chars(" ", text[select].size() + 2), themes[sthe].s);
ccolor("\n ", themes[sthe].s);
gotoxy(text[select].size() + 1, 2 * select + 2);
ccolor(" \n", themes[sthe].s);
ccolor(chars(" ", text[select].size() + 2), themes[sthe].s);
select--;
}
break;
case down:
if (select < textcount - 1) {
gotoxy(0, 2 * select + 1);
ccolor(chars(" ", text[select].size() + 2), themes[sthe].s);
ccolor("\n ", themes[sthe].s);
gotoxy(text[select].size() + 1, 2 * select + 2);
ccolor(" \n", themes[sthe].s);
ccolor(chars(" ", text[select].size() + 2), themes[sthe].s);
select++;
}
break;
case leftt:
if (select < 4) {
if (select == 0) {
seled[select]--;
if (seled[select] == -1)
seled[select] = methodcount - 1;
}
if (select == 1 || select == 2)
if (seled[select] != 15)
seled[select]--;
if (select == 3)
if (seled[select] != 0)
seled[select]--;
}
else{
seled[select]--;
if (seled[select] == -1)
seled[select] = sel_tc[select-4]-1;
}
break;
case rightt:
if (select < 4) {
if (select == 0) {
seled[select]++;
if (seled[select] == methodcount)
seled[select] = 0;
}
if (select == 1 || select == 2)
if (seled[select] != 200)
seled[select]++;
if (select == 3)
if (seled[select] != 50)
seled[select]++;
}
else{
seled[select]++;
if (seled[select] == sel_tc[select-4])
seled[select] = 0;
}
break;
case shift:
type = seled[0] + 1;
n = seled[1];
m = seled[2];
radius = seled[3];
for (int i = 0; i < gamemode; i++)
mode[i] = seled[i + 4] + '0';
system("cls");
return;
}
}
}
void settings() {
int x = 0;
while (1) {
if (langu == 1)
x = selectwhat("设置", set_c, 3, "", x);
else
x = selectwhat("Settings", set_e, 3, "", x);
system("cls");
switch (x) {
case 0:
clangu();
break;
case 1:
cthe();
break;
case 2:
cmaze();
break;
case -1:
return;
}
}
}
maintain a[12];
int exitmaze() {
int x;
if (langu == 1)
x = selectwhat("退出?", exitmaze_c, 2, "", 1);
else
x = selectwhat("give up?", exitmaze_e, 2, "", 1);
system("cls");
return x;
}
void start() {
int mazecount=mode[4]-'0'+1;
pair<bool, pair<map<char, unsigned char>, vector<vector<char> > > > x;
for(int k=1;k<=mazecount;k++){
if (type == 2)
x=a[k].genmaze(n, m, radius, type, 0, 0, mode);
else
x=a[k].genmaze(n, m, radius, type, 1, 1, mode);
}
if (langu == 1)
ccolor("准备!", yellow);
else
ccolor("Ready!", yellow);
Sleep(1000);
system("cls");
map<char, unsigned char> cs=x.second.first;
pair<int, vector<vector<char> > > y;
vector<vector<char> > z;
int movel=0,monl=0;
while (1) {
Sleep(20);
back:
if(movel==0){
int x=nawscanc();
if(x!=-1){
movel=4;
if (x == shift) {
system("cls");
x = exitmaze();
if (!x)
return;
goto back;
}
for(int k=1;k<=mazecount;k++){
y = a[k].move(x);
z = y.second;
for (int i = 0; i < z.size(); i++) {
gotoxy(0, i+(k-1)*(radius?radius*2+2:n+1));
for (int j = 0; j < z[i].size(); j++)
ccolor(" ", cs[z[i][j]]);
cout <<chars(" ",30)<<"\n";
}
cout << chars(chars(" ",radius*2+30)+"\n",3);
if (y.first == 0) {
system("cls");
if (langu == 1)
ccolor("你输了!", red);
else
ccolor("You lose!", red);
Sleep(1000);
system("cls");
return;
}
if (y.first == 2) {
system("cls");
if (langu == 1)
ccolor("你嬴了!", yellow);
else
ccolor("You win!", yellow);
Sleep(1000);
system("cls");
return;
}
}
}
}
else
movel--;
if(monl==0){
for(int k=1;k<=mazecount;k++){
a[k].move_monster();
y = a[k].move(-1);
z = y.second;
for (int i = 0; i < z.size(); i++) {
gotoxy(0, i+(k-1)*(radius?radius*2+2:n+1));
for (int j = 0; j < z[i].size(); j++)
ccolor(" ", cs[z[i][j]]);
cout <<chars(" ",30)<<"\n";
}
cout << chars(chars(" ",radius*2+30)+"\n",3);
if (y.first == 0) {
system("cls");
if (langu == 1)
ccolor("你输了!", red);
else
ccolor("You lose!", red);
Sleep(1000);
system("cls");
return;
}
if (y.first == 2) {
system("cls");
if (langu == 1)
ccolor("你嬴了!", yellow);
else
ccolor("You win!", yellow);
Sleep(1000);
system("cls");
return;
}
}
monl=10;
}
else
monl--;
}
}
void menu() {
int x = 0;
while (1) {
while (1) {
if (langu == 1)
x = selectwhat("Maze v3.4", menu_c, 4, tip_c, x);
else
x = selectwhat("Maze v3.4", menu_e, 4, tip_e, x);
system("cls");
switch (x) {
case 0:
show_log();
break;
case 1:
show_control();
break;
case 2:
settings();
break;
case 3:
start();
break;
case -1:
return;
}
}
}
}
int main() {
hidecursor();
// keybd_event(VK_SHIFT,MapVirtualKey(VK_SHIFT,0),0,0);
// keybd_event(VK_SHIFT,MapVirtualKey(VK_SHIFT,0),KEYEVENTF_KEYUP,0);
menu();
return 0;
}.h
continue updating