我做了一个新的游戏:
【小心】
游戏说明:
●你
■方块
☆手电筒
◎出口
W
A S D
移动
游戏背景:
你去一幢废弃的楼内探险
你迷路了
要找到出口(终点)
太黑了,你只能看到附近的格子
手电筒会让你看的远些
#undef UNICODE #undef _UNICODE #include#include #include #include #include #include #include #include #include using namespace std; namespace _game { //常量 const long long ESC = 27, Enter = 13, Tab = 9, Shang = 38, Xia = 40, Zuo = 37, You = 39, Kong = ' ', z_sb = VK_LBUTTON, y_sb = VK_RBUTTON, Shift = VK_SHIFT, z_Shift = VK_LSHIFT, y_Shift = VK_RSHIFT, Ctrl = VK_CONTROL, z_Ctrl = VK_LCONTROL, y_Ctrl = VK_RCONTROL, Alt = VK_MENU, z_Alt = VK_LMENU, y_Alt = VK_RMENU, A = 'A', B = 'B', C = 'C', D = 'D', E = 'E', F = 'F', G = 'G', H = 'H', I = 'I', J = 'J', K = 'K', L = 'L', M = 'M', N = 'N', O = 'O', P = 'P', Q = 'Q', R = 'R', S = 'S', T = 'T', U = 'U', V = 'V', W = 'W', X = 'X', Y = 'Y', Z = 'Z'; //结构体 struct cdhs//存档结构体 { void out(int n, string name)//输出存档 { ofstream cd(&name[0]); cd << n; return; } void out(long long n, string name) { ofstream cd(&name[0]); cd << n; return; } void out(bool n, string name) { ofstream cd(&name[0]); cd << n; return; } void out(char n, string name) { ofstream cd(&name[0]); cd << n; return; } void out(string n, string name) { ofstream cd(&name[0]); cd << n; return; }//重载 void in(int& n, string name)//读入存档 { ifstream cd(&name[0]); cd >> n; return; } void in(long long& n, string name) { ifstream cd(&name[0]); cd >> n; return; } void in(bool& n, string name) { ifstream cd(&name[0]); cd >> n; return; } void in(char& n, string name) { ifstream cd(&name[0]); cd >> n; return; } void in(string& n, string name) { ifstream cd(&name[0]); cd >> n; return; }//重载 }; struct hl//行列 { long long h, l; }; //函数 bool axj(long long key) { return (GetKeyState(key) < 0); } void bout(string n, long long s = 50, bool f = 0, char key = 13)//输出 { for (long long i = 0; i < n.size(); i++) { if (f && GetKeyState(key) < 0) { cout << n.substr(i, n.size()); return; } cout << n[i]; Sleep(s); } return; } void ckbb()//查看当前b_game.h库版本信息 { system("cls"); cout << "库名:b_game.hn"; cout << "类型:拓展库n"; cout << "版本号:2.0.1n"; return; } void gs(long long h, long long l, string z)//格式 { for (long long i = 1; i <= h; i++) cout << "n"; for (long long i = 1; i <= l; i++) cout << " "; cout << z; return; } hl sbwz(bool x = 1, bool n = 1)//鼠标位置 { HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE); HWND h = GetForegroundWindow(); CONSOLE_FONT_INFO consoleCurrentFont; hl hl; POINT p; if (x) { GetCursorPos(&p); ScreenToClient(h, &p); } else { GetCursorPos(&p); } if (n) { GetCurrentConsoleFont(hOutput, FALSE, &consoleCurrentFont); p.x /= consoleCurrentFont.dwFontSize.X; p.y /= consoleCurrentFont.dwFontSize.Y; } hl.h = p.y + 1; hl.l = p.x + 1; return hl; } void yanse(int n)//颜色 { SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), n); return; } void ycbj()//移除快速编辑模式 { HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); DWORD mode; GetConsoleMode(hStdin, &mode); mode &= ~ENABLE_QUICK_EDIT_MODE; SetConsoleMode(hStdin, mode); return; } void ycgb()//隐藏光标 { CONSOLE_CURSOR_INFO cursor; cursor.bVisible = FALSE; cursor.dwSize = sizeof(cursor); HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorInfo(handle, &cursor); return; } void ydgb(long long h, long long l)//移动光标 { COORD pos = { l - 1,h - 1 }; HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleCursorPosition(hOut, pos); return; } } using namespace _game; //常量 const string yz_ren = "●", yz_fk = "■", yz_sdt = "☆", yz_gw = "◆", yz_kong = " ", yz_zd = "◎"; const long long dts = 1, ys_ren = 249, ys_fk = 240, ys_sdt = 250, ys_gw = 244, ys_kong = 240, ys_zd = 250; const short dt[dts + 1][41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,1,0,1, 0,1,0,1,0,1,0,0,0,0,1,0,1,1,1,0,1,1,1,0,1,0,1,1,0,1,0,1,0,1,0,1,0,0,0,0,0,0,1,0,1, 0,1,0,1,0,1,1,1,1,1,1,0,1,0,1,0,1,0,0,0,1,0,1,0,0,1,0,1,0,1,0,1,0,0,1,0,1,1,1,0,1, 0,1,0,1,0,0,0,0,0,0,0,0,1,0,1,0,0,0,1,1,1,0,1,1,1,1,0,1,0,1,0,0,0,0,0,0,0,0,0,0,1, 0,1,0,1,0,1,1,1,0,1,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,0,1,1,0,1,1,0,1, 0,1,0,1,0,1,0,0,0,1,0,0,1,0,1,1,1,0,1,1,1,0,1,1,1,1,0,1,1,1,0,0,1,0,0,0,0,0,1,0,1, 0,1,0,1,0,1,1,1,0,1,1,1,1,0,1,1,0,0,1,0,1,0,1,0,1,0,0,0,0,0,1,0,1,1,1,1,1,1,1,0,1, 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0,1, 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, } }; //变量 long long dtbh = 1, ksd = 2; bool cx_flag = 1; struct gw { long long h, l; long long sj_h, sj_l; void csh() { return; } }; struct wp { long long h, l; void csh() { h = rand() % 40 + 1; l = rand() % 40 + 1; while (dt[dtbh][h][l] != 0) { h = rand() % 40 + 1; l = rand() % 40 + 1; } return; } }; struct ren : wp { }wj; struct sdt : wp { bool f = 1; }sdt; struct zd : wp { }zd; void csh(); void out(); void in(); void bd(); int main() { srand(time(0)); yanse(240); system("cls"); system("mode con cols=81 lines=40"); system("title 小心"); ycgb(); cout << "正在加载..."; csh(); // system("cls"); while (cx_flag) { out(); in(); bd(); Sleep(100); ydgb(41, 1); yanse(7); } _getch(); return 0; } void csh() { wj.csh(); sdt.csh(); zd.csh(); return; } void out() { yanse(7); system("cls"); for (long long i = wj.h - ksd; i <= wj.h + ksd; i++) { for (long long j = wj.l - ksd; j <= wj.l + ksd; j++) { ydgb(i, j * 2 - 1); if (i < 1 || j < 1 || i>40 || j>40) { continue; } else if (i == zd.h && j == zd.l) { yanse(ys_zd); cout << yz_zd; } else if (i == sdt.h && j == sdt.l && sdt.f) { yanse(ys_sdt); cout << yz_sdt; } else if (i == wj.h && j == wj.l) { yanse(ys_ren); cout << yz_ren; } else if (dt[dtbh][i][j] == 1) { yanse(ys_fk); cout << yz_fk; } else { yanse(ys_kong); cout << yz_kong; } } } return; } void bd() { if (wj.h == sdt.h && wj.l == sdt.l && sdt.f) { sdt.f = 0; ksd = 4; } if (wj.h == zd.h && wj.l == zd.l) { yanse(240); system("cls"); cout << "你赢了!!!nnn"; cout << "按空格继续"; while (_getch() != ' '); cx_flag = 0; return; } return; } void in() { if (axj('A') && wj.l - 1 > 1 && dt[dtbh][wj.h][wj.l - 1] == 0) { wj.l--; } if (axj('D') && wj.l + 1 < 40 && dt[dtbh][wj.h][wj.l + 1] == 0) { wj.l++; } if (axj('W') && wj.h - 1 > 1 && dt[dtbh][wj.h - 1][wj.l] == 0) { wj.h--; } if (axj('S') && wj.h + 1 < 40 && dt[dtbh][wj.h + 1][wj.l] == 0) { wj.h++; } return; }



