正文
增加 219 行删除 1490 行
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113823 行未改动138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914204 行未改动14251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814796 行未改动1486148714881489149014911492149314 行未改动150815091510151115121513151415155 行未改动152115221523152415251526152715281529153015 行未改动154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157910 行未改动159015911592159315941595159615975 行未改动1603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916506 行未改动165716581659166016611662166316641665166614 行未改动168116821683168416851686168716883 行未改动1692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417152 行未改动171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917403 行未改动1744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217 行未改动179017911792179317941795179617978 行未改动180618071808180918101811181218137 行未改动18211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018813 行未改动18851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819092 行未改动1912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219536 行未改动1960196119621963196419651966196719681969197019711972197319741975197619771978197919804 行未改动19851986198719881989199019911992199319941995199619975 行未改动200320042005200620072008200920102011201220132014201520162017201820192020202120223 行未改动202620272028202920302031203220332034203520362037203820392040204120422043204415 行未改动206020612062206320642065206620672068**提示:所有游戏仅供 Windows 系统使用。****你可以通过右边的标题栏快速查看版本。**## 《僵尸庄园》### v1.0```cpp line-numbers#include <iostream>#include <windows.h>#include <conio.h>#include <cstdlib>#include <ctime>#include <cmath>#include <queue>#include <bitset>using namespace std;const int WIDTH = 1000;const int HEIGHT = 1000;const int RENDER_SIZE = (25 - 1) / 2;const int LOSE_SCORE = -1;const int WIN_SCORE = 100;const char PORTAL_CHAR = 'O';const int dx[] = {0,0,-1,1};const int dy[] = {-1,1,0,0};char map[HEIGHT + 5][WIDTH + 5];bitset<WIDTH + 5> apple[HEIGHT + 5];bitset<WIDTH + 5> zombie[HEIGHT + 5];bool vis[HEIGHT + 5][WIDTH + 5];int pl_x = HEIGHT / 2,pl_y = WIDTH / 2;int score = 0,combo = 0;int zombie_live = 0;namespace GameTool{double Euclid_dis(pair<int,int> pos1,pair<int,int> pos2){int x1 = pos1.first,y1 = pos1.second;int x2 = pos2.first,y2 = pos2.second;double res = sqrt(double((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));return res;}void SlowOutput(string str,int speed = 50){for(char ch : str){cout << ch;if(ch == ' ' || ch == '\n') continue;Sleep(speed);}}};struct BFSNode{int x,y;pair<int,int> last;};void GenerateApple(int cnt){for(int i = 1;i <= cnt;i++){int apple_x = rand() % HEIGHT + 1;int apple_y = rand() % WIDTH + 1;if(apple[apple_x][apple_y]) continue;if(map[apple_x][apple_y] == PORTAL_CHAR) continue;apple[apple_x][apple_y] = true;}}void InitMap(){for(int i = 1;i <= HEIGHT;i++){for(int j = 1;j <= WIDTH;j++){if(rand() % 10 == 0){map[i][j] = '#';} else{map[i][j] = '.';}}}for(int i = 0;i <= HEIGHT + 1;i++){map[i][0] = '#';map[i][WIDTH + 1] = '#';}for(int i = 0;i <= WIDTH + 1;i++){map[0][i] = '#';map[HEIGHT + 1][i] = '#';}for(int i = 1;i <= HEIGHT * WIDTH / 100;i++){int x = rand() % HEIGHT + 1;int y = rand() % WIDTH + 1;if(map[x][y] == '#') continue;apple[x][y] = true;}}void RenderScreen(){for(int i = pl_x - RENDER_SIZE;i <= pl_x + RENDER_SIZE;i++){for(int j = pl_y - RENDER_SIZE;j <= pl_y + RENDER_SIZE;j++){if(GameTool::Euclid_dis({pl_x,pl_y},{i,j}) > RENDER_SIZE){cout << ' ';} else if(i < 0 || i > HEIGHT + 1 || j < 0 || j > WIDTH + 1){cout << ' ';} else if(i == pl_x && j == pl_y){cout << 'P';} else if(apple[i][j]){cout << 'A';}else if(zombie[i][j]){cout << 'Z';} else{cout << map[i][j];}cout << ' ';}cout << '\n';}cout << "\n - X 坐标:" << pl_x << " Y 坐标:" << pl_y << '\n';cout << " - 积分: " << score << '\n';cout << " - 连击数: " << combo << "\n\n";cout << " - 存活僵尸数: " << zombie_live << "\n\n";if(combo >= 3){cout << " 系统赠送了你 " << floor(sqrt(combo - 2)) << " 积分\n";}cout << flush;}void SummonZombie(){int limit_x = min(HEIGHT,pl_x + 30);int limit_y = min(WIDTH,pl_y + 30);int down_limit_x = max(1,pl_x - 30);int down_limit_y = max(1,pl_y - 30);int randX = rand() % (limit_x - down_limit_x + 1) + down_limit_x;int randY = rand() % (limit_y - down_limit_y + 1) + down_limit_y;if(map[randX][randY] == '#') return;if(map[randX][randY] == PORTAL_CHAR) return;zombie[randX][randY] = true;}void ZForwardToP(){for(int i = max(1,pl_x - 30);i <= min(HEIGHT,pl_x + 30);i++){for(int j = max(1,pl_y - 30);j <= min(WIDTH,pl_y + 30);j++){vis[i][j] = false;}}queue<BFSNode> q;q.push({pl_x,pl_y,{-1,-1}});while(!q.empty()){BFSNode now = q.front();q.pop();int x = now.x;int y = now.y;int lastx = now.last.first;int lasty = now.last.second;if(x < max(1,pl_x - 30) || x > min(HEIGHT,pl_x + 30) ||y < max(1,pl_y - 30) || y > min(WIDTH,pl_y + 30)){continue;}if(vis[x][y]) continue;vis[x][y] = true;if(map[x][y] == '#') continue;if(zombie[x][y]){if(lastx != -1 && lasty != -1 && zombie[lastx][lasty] == false){zombie[x][y] = false;zombie[lastx][lasty] = true;}}for(int i = 0;i < 4;i++){int xx = x + dx[i];int yy = y + dy[i];q.push({xx,yy,{x,y}});}}}void HandleKey(){if(_kbhit()){char ch = _getch();if(ch == 'a' && map[pl_x][pl_y - 1] != '#'){pl_y--;} else if(ch == 'd' && map[pl_x][pl_y + 1] != '#'){pl_y++;} else if(ch == 'w' && map[pl_x - 1][pl_y] != '#'){pl_x--;} else if(ch == 's' && map[pl_x + 1][pl_y] != '#'){pl_x++;} else if(ch == 'q'){cout << "\n" << flush;system("pause");}}if(pl_y < 1) pl_y = 1;if(pl_y > WIDTH) pl_y = WIDTH;if(pl_x < 1) pl_x = 1;if(pl_x > HEIGHT) pl_x = HEIGHT;}void EatApple(){if(apple[pl_x][pl_y] == false){return;}score++;combo++;if(combo >= 3){score += floor(sqrt(combo - 2));}apple[pl_x][pl_y] = false;for(int i = 1;i <= HEIGHT;i++){for(int j = 1;j <= WIDTH;j++){if(zombie[i][j]){zombie[i][j] = false;zombie_live = max(0,zombie_live - 1);return;}}}}void ZombieAttack(){if(zombie[pl_x][pl_y]){score -= 3;combo = 0;zombie_live--;zombie[pl_x][pl_y] = false;}}void HelloUI(){using namespace GameTool;SlowOutput("========== 欢迎来到 僵尸庄园v1.0 ==========\n\n");SlowOutput(" 在这里,你需要收集地上的苹果,每个\n");SlowOutput(" 苹果可以获得 1 积分。\n");SlowOutput(" 初始状态你没有积分。\n\n");SlowOutput(" 当你快速的吃掉 3 个以上的苹果,\n");SlowOutput(" 系统将会奖励你积分,\n");SlowOutput(" 数量以连击数量为准。\n");SlowOutput(" 你开始会有 3s 的无敌时间。\n\n");cout << " - ";system("pause & cls");SlowOutput("========== 欢迎来到 僵尸庄园v1.0 ==========\n\n",0);SlowOutput(" 但是,庄园里的稻草人都变异了,\n");SlowOutput(" 会变成僵尸追击你。\n\n");SlowOutput(" 如果你不幸被他们碰到,\n");SlowOutput(" 你将会失去 3 个积分。\n");SlowOutput(" 但那只僵尸会消失不见。 \n\n");SlowOutput(" 每当你吃下一个苹果,\n");SlowOutput(" 将会随机抽选一只僵尸消失不见。\n\n");cout << " - ";system("pause & cls");SlowOutput("========== 欢迎来到 僵尸庄园v1.0 ==========\n\n",0);SlowOutput(" 当你在当前的情形中获得 100 积分\n");SlowOutput(" 在整个庄园右下角将会出现一个出口,\n");SlowOutput(" 当你进入这个出口,你就逃出了这个庄园。\n\n");SlowOutput(" 若你积分小于 0,\n");SlowOutput(" 你将消失不见并永远变成一个僵尸。\n\n");SlowOutput(" 祝你好运。 Good Luck. \n\n");cout << " - ";system("pause & cls");cout << "========== 游戏操作指南 ==========\n\n";cout << " A 键:向左移动。\n";cout << " D 键:向右移动。\n";cout << " W 键:向上移动。\n";cout << " S 键:向下移动。\n";cout << " Q 键:暂停游戏。\n\n";cout << " - ";system("pause & cls");SlowOutput("========== 游戏操作指南 ==========\n\n",0);SlowOutput(" 庄园是一个 1000 * 1000 的正方形矩阵,\n");SlowOutput(" '#' 代表墙,'.' 代表空地,\n");SlowOutput(" 'A' 代表苹果,'Z' 代表僵尸。\n\n");SlowOutput(" 庄园外围被一圈铁栏杆围着,你无法出入。\n\n");SlowOutput(" - 准备好了吗?");system("pause");}bool CheckResult(){if(score <= LOSE_SCORE){system("cls");cout << "你被僵尸残忍杀害!" << flush;return true;}if(score >= WIN_SCORE && map[1000][1000] != PORTAL_CHAR){system("cls");cout << "传送门已开启!";for(int i = 998;i <= 1000;i++){for(int j = 998;j <= 1000;j++){map[i][j] = PORTAL_CHAR;}}cout << "按 Q 键退出。" << flush;while(_getch() != 'q');}if(map[pl_x][pl_y] == PORTAL_CHAR){system("cls");cout << "你成功逃出了庄园!" << flush;return true;}return false;}int main(){HelloUI();ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);srand(time(NULL));system("color f0");system("mode con cols=60 lines=35");InitMap();int timestamp = 1;int last_score = 0;while(true){RenderScreen();HandleKey();EatApple();if(timestamp % 100 == 0){GenerateApple(10);}if(timestamp > 60){ZombieAttack();}if(timestamp % 10 == 0){ZForwardToP();}if(timestamp % 60 == 0){SummonZombie();zombie_live++;}if(timestamp % 60 == 0){if(score <= last_score){combo = 0;} else{last_score = score;}}if(CheckResult()) break;timestamp++;Sleep(50);system("cls");}int end = time(NULL);cout << " 用时 " << (timestamp - 1) / 20 << " 秒。\n\n";cout << "按 Q 键结束游戏。" << flush;while(_getch() != 'q');return 0;}```### v1.0.2```cpp line-numbers#include <iostream>#include <windows.h>#include <conio.h>#include <cstdlib>#include <ctime>#include <cmath>#include <cctype>#include <queue>#include <bitset>using namespace std;const int WIDTH = 300;const int HEIGHT = 300;int RENDER_SIZE = (19 - 1) / 2;const int LOSE_SCORE = -1;const int WIN_SCORE = 100;const int dx[] = {0,0,-1,1};const int dy[] = {-1,1,0,0};char map[HEIGHT + 5][WIDTH + 5];bitset<WIDTH + 5> apple[HEIGHT + 5];bitset<WIDTH + 5> zombie[HEIGHT + 5];bitset<WIDTH + 5> vis[HEIGHT + 5];int pl_x = HEIGHT / 2,pl_y = WIDTH / 2;int score = 0,combo = 0;int zombie_live = 0;enum Color{BLACK = 0,BLUE = 1,GREEN = 2,CYAN = 3,RED = 4,MAGENTA = 5,YELLOW = 6,WHITE = 7,GRAY = 8,LIGHT_BLUE = 9,LIGHT_GREEN = 10,LIGHT_CYAN = 11,LIGHT_RED = 12,LIGHT_MAGENTA = 13,LIGHT_YELLOW = 14,BRIGHT_WHITE = 15};namespace GameTool{double Euclid_dis(pair<int,int> pos1,pair<int,int> pos2){int x1 = pos1.first,y1 = pos1.second;int x2 = pos2.first,y2 = pos2.second;double res = sqrt(double((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));return res;}void SlowOutput(string str,int speed = 50){for(char ch : str){cout << ch;if(ch == ' ' || ch == '\n') continue;Sleep(speed);}}void CursorMove(int x,int y){HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);COORD pos = {(SHORT)x,(SHORT)y};SetConsoleCursorPosition(h,pos);}void HideCursor(){HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);CONSOLE_CURSOR_INFO cinfo;GetConsoleCursorInfo(h,&cinfo);cinfo.bVisible = false;SetConsoleCursorInfo(h,&cinfo);}void ShowCursor(){HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);CONSOLE_CURSOR_INFO cinfo;GetConsoleCursorInfo(h,&cinfo);cinfo.bVisible = true;SetConsoleCursorInfo(h,&cinfo);}void SetTextColor(int fg = RED,int bg = BRIGHT_WHITE){HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleTextAttribute(h,(bg << 4) | fg);}};struct BFSNode{int x,y;pair<int,int> last;};void GenerateApple(int cnt){for(int i = 1;i <= cnt;i++){int apple_x = rand() % HEIGHT + 1;int apple_y = rand() % WIDTH + 1;if(apple[apple_x][apple_y]) continue;if(map[apple_x][apple_y] == '#') continue;if(map[apple_x][apple_y] == 'O') continue;apple[apple_x][apple_y] = true;}}void InitMap(){for(int i = 1;i <= HEIGHT;i++){for(int j = 1;j <= WIDTH;j++){if(rand() % 10 == 0){map[i][j] = '#';} else{map[i][j] = '.';}}}for(int i = 0;i <= HEIGHT + 1;i++){map[i][0] = '#';map[i][WIDTH + 1] = '#';}for(int i = 0;i <= WIDTH + 1;i++){map[0][i] = '#';map[HEIGHT + 1][i] = '#';}GenerateApple(HEIGHT * WIDTH / 100);}void RenderScreen(){for(int i = pl_x - RENDER_SIZE;i <= pl_x + RENDER_SIZE;i++){for(int j = pl_y - RENDER_SIZE;j <= pl_y + RENDER_SIZE;j++){if(GameTool::Euclid_dis({pl_x,pl_y},{i,j}) > RENDER_SIZE){cout << ' ';} else if(i < 0 || i > HEIGHT + 1 || j < 0 || j > WIDTH + 1){cout << ' ';} else if(i == pl_x && j == pl_y){GameTool::SetTextColor(GREEN);cout << 'P';GameTool::SetTextColor(BLACK);} else if(apple[i][j]){GameTool::SetTextColor(LIGHT_RED);cout << 'A';GameTool::SetTextColor(BLACK);}else if(zombie[i][j]){GameTool::SetTextColor(GREEN,RED);cout << 'Z';GameTool::SetTextColor(BLACK);} else{cout << map[i][j];}cout << ' ';}cout << '\n';}cout << "\n - X 坐标:" << pl_x << " Y 坐标:" << pl_y << " \n";cout << " - 积分:" << score << " \n";cout << " - 连击数: " << combo << " \n\n";cout << " - 存活僵尸数: " << zombie_live << " \n\n";if(combo >= 3){cout << " 系统赠送了你 " << floor(sqrt(combo - 2)) << " 积分\n";}}void SummonZombie(){int limit_x = min(HEIGHT,pl_x + 30);int limit_y = min(WIDTH,pl_y + 30);int down_limit_x = max(1,pl_x - 30);int down_limit_y = max(1,pl_y - 30);int randX = rand() % (limit_x - down_limit_x + 1) + down_limit_x;int randY = rand() % (limit_y - down_limit_y + 1) + down_limit_y;if(map[randX][randY] == '#') return;if(map[randX][randY] == 'O') return;zombie[randX][randY] = true;}void ZForwardToP(){for(int i = max(1,pl_x - 30);i <= min(HEIGHT,pl_x + 30);i++){for(int j = max(1,pl_y - 30);j <= min(WIDTH,pl_y + 30);j++){vis[i][j] = false;}}queue<BFSNode> q;q.push({pl_x,pl_y,{-1,-1}});while(!q.empty()){BFSNode now = q.front();q.pop();int x = now.x;int y = now.y;int lastx = now.last.first;int lasty = now.last.second;if(x < max(1,pl_x - 30) || x > min(HEIGHT,pl_x + 30) ||y < max(1,pl_y - 30) || y > min(WIDTH,pl_y + 30)){continue;}if(vis[x][y]) continue;vis[x][y] = true;if(map[x][y] == '#') continue;if(zombie[x][y]){if(lastx != -1 && lasty != -1 && zombie[lastx][lasty] == false){zombie[x][y] = false;zombie[lastx][lasty] = true;}}for(int i = 0;i < 4;i++){int xx = x + dx[i];int yy = y + dy[i];q.push({xx,yy,{x,y}});}}}void ChargeRenderSize(){system("cls");int r;cout << " 注意:调整后请自行调整窗口大小。\n\n";cout << "请输入新的渲染范围半径:" ;cin >> r;if(r < 4 || r > 50){cout << "请勿设置不合理的渲染距离。\n";system("pause");return;}RENDER_SIZE = r;system("cls");}void HandleKey(){if(_kbhit()){char ch = _getch();ch = tolower(ch);if(ch == 'a' && map[pl_x][pl_y - 1] != '#'){pl_y--;} else if(ch == 'd' && map[pl_x][pl_y + 1] != '#'){pl_y++;} else if(ch == 'w' && map[pl_x - 1][pl_y] != '#'){pl_x--;} else if(ch == 's' && map[pl_x + 1][pl_y] != '#'){pl_x++;} else if(ch == 'z'){ChargeRenderSize();} else if(ch == 'q'){cout << '\n';system("pause & cls");}}}void EatApple(){if(apple[pl_x][pl_y] == false){return;}score++;combo++;if(combo >= 3){score += floor(sqrt(combo - 2));}apple[pl_x][pl_y] = false;for(int i = 1;i <= HEIGHT;i++){for(int j = 1;j <= WIDTH;j++){if(zombie[i][j]){zombie[i][j] = false;zombie_live = max(0,zombie_live - 1);return;}}}}void ZombieAttack(){if(zombie[pl_x][pl_y]){score -= 3;combo = 0;zombie_live--;zombie[pl_x][pl_y] = false;}}void HelloUI(){using namespace GameTool;SlowOutput("========== 欢迎来到 僵尸庄园v1.0.2 ==========\n\n");SlowOutput(" 在这里,你需要收集地上的苹果,每个\n");SlowOutput(" 苹果可以获得 1 积分。\n");SlowOutput(" 初始状态你没有积分。\n\n");SlowOutput(" 当你快速的吃掉 3 个以上的苹果,\n");SlowOutput(" 系统将会奖励你积分,\n");SlowOutput(" 数量以连击数量为准。\n\n");SlowOutput(" 你开始会有 3s 的无敌时间。\n\n");cout << " - ";system("pause & cls");SlowOutput("========== 欢迎来到 僵尸庄园v1.0.2 ==========\n\n",0);SlowOutput(" 但是,庄园里的稻草人都变异了,\n");SlowOutput(" 会变成僵尸追击你。\n\n");SlowOutput(" 如果你不幸被他们碰到,\n");SlowOutput(" 你将会失去 3 个积分。\n");SlowOutput(" 但那只僵尸会消失不见。 \n\n");SlowOutput(" 每当你吃下一个苹果,\n");SlowOutput(" 将会随机抽选一只僵尸消失不见。\n\n");cout << " - ";system("pause & cls");SlowOutput("========== 欢迎来到 僵尸庄园v1.0.2 ==========\n\n",0);SlowOutput(" 当你在当前的情形中获得 100 积分,\n");SlowOutput(" 在整个庄园右下角将会出现一个出口,\n");SlowOutput(" 当你进入这个出口,你就逃出了这个庄园。\n\n");SlowOutput(" 若你积分小于 0,\n");SlowOutput(" 你将消失不见并永远变成一个僵尸。\n\n");SlowOutput(" 祝你好运。 Good Luck. \n\n");cout << " - ";system("pause & cls");cout << "========== 更新公告 ==========\n\n";cout << " 1. 优化了视觉,僵尸、玩家、苹果将\n 显示不同的颜色。\n";cout << " 2. 修复了部分文案bug。 \n";cout << " 3. 修复bug:锁定大写时无法移动。\n";cout << " 4. 降低了游戏难度,地图大小从 1000 * 1000\n 变为 300 * 300。\n";cout << " 5. 渲染范围可根据需求调整。\n\n";cout << " - ";system("pause & cls");cout << "========== 游戏操作指南 ==========\n\n";cout << " A 键:向左移动。\n";cout << " D 键:向右移动。\n";cout << " W 键:向上移动。\n";cout << " S 键:向下移动。\n";cout << " Z 键:调整渲染距离。\n";cout << " Q 键:暂停游戏。\n\n";cout << " - ";system("pause & cls");SlowOutput("========== 游戏操作指南 ==========\n\n",0);SlowOutput(" 庄园是一个 300 * 300 的正方形矩阵,\n");SlowOutput(" '#' 代表墙,'.' 代表空地,\n");SlowOutput(" 'A' 代表苹果,'Z' 代表僵尸。\n\n");SlowOutput(" 庄园外围被一圈铁栏杆围着,你无法出入。\n\n");SlowOutput(" 注意:如果你的电脑上安装了联想电脑管家,\n");SlowOutput(" 建议将其暂时关闭,因为这个软件可能导致终端卡顿。\n\n");SlowOutput(" - 准备好了吗?");system("pause & cls");}bool CheckResult(){if(score <= LOSE_SCORE){system("cls");cout << "你被僵尸残忍杀害!";return true;}if(score >= WIN_SCORE && map[HEIGHT][WIDTH] != 'O'){system("cls");cout << "传送门已开启!";for(int i = HEIGHT - 2;i <= HEIGHT;i++){for(int j = WIDTH - 2;j <= WIDTH;j++){map[i][j] = 'O';}}cout << "按 Q 键退出。";while(_getch() != 'q');}if(map[pl_x][pl_y] == 'O'){system("cls");cout << "你成功逃出了庄园!";return true;}return false;}int main(){HelloUI();srand(time(NULL));system("color f0");system("mode con cols=55 lines=35");GameTool::HideCursor();InitMap();int timestamp = 1;int last_score = 0;while(true){RenderScreen();HandleKey();EatApple();if(timestamp % 100 == 0){GenerateApple(10);}if(timestamp > 60){ZombieAttack();}if(timestamp % 10 == 0){ZForwardToP();}if(timestamp % 60 == 0){SummonZombie();zombie_live++;}if(timestamp % 60 == 0){if(score <= last_score){combo = 0;} else{last_score = score;}}if(CheckResult()) break;timestamp++;Sleep(50);GameTool::CursorMove(0,0);}GameTool::ShowCursor();cout << " 用时 " << (timestamp - 1) / 20 << " 秒。\n\n";cout << "按 Q 键结束游戏。";while(_getch() != 'q');return 0;}```### v1.0.3```cpp line-numbers#include <iostream>#include <fstream>#include <windows.h>#include <conio.h>#include <cstdlib>#include <ctime>#include <cmath>#include <cctype>#include <queue>#include <bitset>using namespace std;const int WIDTH = 300;const int HEIGHT = 300;int RENDER_SIZE = (19 - 1) / 2;const int LOSE_SCORE = -1;const int WIN_SCORE = 100;const int dx[] = {0,0,-1,1};const int dy[] = {-1,1,0,0};char map[HEIGHT + 5][WIDTH + 5];bitset<WIDTH + 5> apple[HEIGHT + 5];bitset<WIDTH + 5> zombie[HEIGHT + 5];bitset<WIDTH + 5> vis[HEIGHT + 5];int pl_x = HEIGHT / 2,pl_y = WIDTH / 2;int score = 0,combo = 0;int zombie_live = 0;enum Color{BLACK = 0,BLUE = 1,GREEN = 2,CYAN = 3,RED = 4,MAGENTA = 5,YELLOW = 6,WHITE = 7,GRAY = 8,LIGHT_BLUE = 9,LIGHT_GREEN = 10,LIGHT_CYAN = 11,LIGHT_RED = 12,LIGHT_MAGENTA = 13,LIGHT_YELLOW = 14,BRIGHT_WHITE = 15};namespace GameTool{double Euclid_dis(pair<int,int> pos1,pair<int,int> pos2){int x1 = pos1.first,y1 = pos1.second;int x2 = pos2.first,y2 = pos2.second;double res = sqrt(double((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));return res;}void SlowOutput(string str,int speed = 50){for(char ch : str){cout << ch;if(ch == ' ' || ch == '\n') continue;Sleep(speed);}}void CursorMove(int x,int y){HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);COORD pos = {(SHORT)x,(SHORT)y};SetConsoleCursorPosition(h,pos);}void HideCursor(){HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);CONSOLE_CURSOR_INFO cinfo;GetConsoleCursorInfo(h,&cinfo);cinfo.bVisible = false;SetConsoleCursorInfo(h,&cinfo);}void ShowCursor(){HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);CONSOLE_CURSOR_INFO cinfo;GetConsoleCursorInfo(h,&cinfo);cinfo.bVisible = true;SetConsoleCursorInfo(h,&cinfo);}void SetTextColor(int fg = RED,int bg = BRIGHT_WHITE){HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);SetConsoleTextAttribute(h,(bg << 4) | fg);}};struct BFSNode{int x,y;pair<int,int> last;};void GenerateApple(int cnt){for(int i = 1;i <= cnt;i++){int apple_x = rand() % HEIGHT + 1;int apple_y = rand() % WIDTH + 1;if(apple[apple_x][apple_y]) continue;if(map[apple_x][apple_y] == '#') continue;if(map[apple_x][apple_y] == 'O') continue;apple[apple_x][apple_y] = true;}}void InitMap(){for(int i = 1;i <= HEIGHT;i++){for(int j = 1;j <= WIDTH;j++){if(rand() % 10 == 0){map[i][j] = '#';} else{map[i][j] = '.';}}}for(int i = 0;i <= HEIGHT + 1;i++){map[i][0] = '#';map[i][WIDTH + 1] = '#';}for(int i = 0;i <= WIDTH + 1;i++){map[0][i] = '#';map[HEIGHT + 1][i] = '#';}GenerateApple(HEIGHT * WIDTH / 100);}void RenderScreen(){for(int i = pl_x - RENDER_SIZE;i <= pl_x + RENDER_SIZE;i++){for(int j = pl_y - RENDER_SIZE;j <= pl_y + RENDER_SIZE;j++){if(GameTool::Euclid_dis({pl_x,pl_y},{i,j}) > RENDER_SIZE){cout << ' ';} else if(i < 0 || i > HEIGHT + 1 || j < 0 || j > WIDTH + 1){cout << ' ';} else if(i == pl_x && j == pl_y){GameTool::SetTextColor(GREEN);cout << 'P';GameTool::SetTextColor(BLACK);} else if(apple[i][j]){GameTool::SetTextColor(LIGHT_RED);cout << 'A';GameTool::SetTextColor(BLACK);}else if(zombie[i][j]){GameTool::SetTextColor(GREEN,RED);cout << 'Z';GameTool::SetTextColor(BLACK);} else{cout << map[i][j];}cout << ' ';}cout << '\n';}cout << "\n - X 坐标:" << pl_x << " Y 坐标:" << pl_y << " \n";cout << " - 积分:" << score << " \n";cout << " - 连击数: " << combo << " \n\n";cout << " - 存活僵尸数: " << zombie_live << " \n\n";if(combo >= 3){cout << " 系统赠送了你 " << floor(sqrt(combo - 2)) << " 积分\n";}}void SummonZombie(){int limit_x = min(HEIGHT,pl_x + 30);int limit_y = min(WIDTH,pl_y + 30);int down_limit_x = max(1,pl_x - 30);int down_limit_y = max(1,pl_y - 30);int randX = rand() % (limit_x - down_limit_x + 1) + down_limit_x;int randY = rand() % (limit_y - down_limit_y + 1) + down_limit_y;if(map[randX][randY] == '#') return;if(map[randX][randY] == 'O') return;zombie[randX][randY] = true;}void ZForwardToP(){for(int i = max(1,pl_x - 30);i <= min(HEIGHT,pl_x + 30);i++){for(int j = max(1,pl_y - 30);j <= min(WIDTH,pl_y + 30);j++){vis[i][j] = false;}}queue<BFSNode> q;q.push({pl_x,pl_y,{-1,-1}});while(!q.empty()){BFSNode now = q.front();q.pop();int x = now.x;int y = now.y;int lastx = now.last.first;int lasty = now.last.second;if(x < max(1,pl_x - 30) || x > min(HEIGHT,pl_x + 30) ||y < max(1,pl_y - 30) || y > min(WIDTH,pl_y + 30)){continue;}if(vis[x][y]) continue;vis[x][y] = true;if(map[x][y] == '#') continue;if(map[x][y] == 'O') continue;if(zombie[x][y]){if(lastx != -1 && lasty != -1 && zombie[lastx][lasty] == false){zombie[x][y] = false;zombie[lastx][lasty] = true;}}for(int i = 0;i < 4;i++){int xx = x + dx[i];int yy = y + dy[i];q.push({xx,yy,{x,y}});}}}void ChargeRenderSize(){system("cls");GameTool::ShowCursor();int r;cout << " 注意:调整后请自行调整窗口大小。\n\n";cout << "请输入新的渲染范围半径(输入 4~50 的整数):" ;cin >> r;if(r < 4 || r > 50){cout << "\n请勿设置不合理的渲染距离。\n\n";GameTool::HideCursor();system("pause");return;}RENDER_SIZE = r;GameTool::HideCursor();system("cls");}void HandleKey(){if(_kbhit()){char ch = _getch();ch = tolower(ch);if(ch == 'a' && map[pl_x][pl_y - 1] != '#'){pl_y--;} else if(ch == 'd' && map[pl_x][pl_y + 1] != '#'){pl_y++;} else if(ch == 'w' && map[pl_x - 1][pl_y] != '#'){pl_x--;} else if(ch == 's' && map[pl_x + 1][pl_y] != '#'){pl_x++;} else if(ch == 'z'){ChargeRenderSize();} else if(ch == 'q'){cout << '\n';system("pause & cls");}}}void EatApple(){if(apple[pl_x][pl_y] == false){return;}score++;combo++;if(combo >= 3){score += floor(sqrt(combo - 2));}apple[pl_x][pl_y] = false;for(int i = 1;i <= HEIGHT;i++){for(int j = 1;j <= WIDTH;j++){if(zombie[i][j]){zombie[i][j] = false;zombie_live = max(0,zombie_live - 1);return;}}}}void ZombieAttack(){if(zombie[pl_x][pl_y]){score -= 3;combo = 0;zombie_live--;zombie[pl_x][pl_y] = false;}}void HelloUI(){using namespace GameTool;ifstream file("config.dat");string line;file >> line;if(line.find("HelloUIDisplay:true") != string::npos){char choose;cout << "检测到你已经看过游戏介绍,是否跳过?(T/F)\n";cin >> choose;if(choose == 'T'){file.close();return;} else{system("cls");}}file.close();SlowOutput("========== 欢迎来到 僵尸庄园v1.0.3 ==========\n\n");SlowOutput(" 在这里,你需要收集地上的苹果,每个\n");SlowOutput(" 苹果可以获得 1 积分。\n");SlowOutput(" 初始状态你没有积分。\n\n");SlowOutput(" 当你快速的吃掉 3 个以上的苹果,\n");SlowOutput(" 系统将会奖励你积分,\n");SlowOutput(" 数量以连击数量为准。\n\n");SlowOutput(" 你开始会有 3s 的无敌时间。\n\n");cout << " - ";system("pause & cls");SlowOutput("========== 欢迎来到 僵尸庄园v1.0.3 ==========\n\n",0);SlowOutput(" 但是,庄园里的稻草人都变异了,\n");SlowOutput(" 会变成僵尸追击你。\n\n");SlowOutput(" 如果你不幸被他们碰到,\n");SlowOutput(" 你将会失去 3 个积分。\n");SlowOutput(" 但那只僵尸会消失不见。 \n\n");SlowOutput(" 每当你吃下一个苹果,\n");SlowOutput(" 将会随机抽选一只僵尸消失不见。\n\n");cout << " - ";system("pause & cls");SlowOutput("========== 欢迎来到 僵尸庄园v1.0.3 ==========\n\n",0);SlowOutput(" 当你在当前的情形中获得 100 积分,\n");SlowOutput(" 在整个庄园右下角将会出现一个出口,\n");SlowOutput(" 当你进入这个出口,你就逃出了这个庄园。\n\n");SlowOutput(" 若你积分小于 0,\n");SlowOutput(" 你将消失不见并永远变成一个僵尸。\n\n");SlowOutput(" 祝你好运。 Good Luck. \n\n");cout << " - ";system("pause & cls");cout << "========== 更新公告 ==========\n\n";cout << " 1. 现在看完游戏介绍后可以选择跳过。(存储信息\n 在 config.dat 里)\n";cout << " 2. 修复bug:苹果可能生成在墙里。\n";cout << " 3. 修复bug:玩家可能生成在墙里。\n";cout << " 4. 修复bug:调整渲染范围时不显示光标。\n";cout << " 5. 修复bug:僵尸可以覆盖传送门。\n";cout << " 6. 修复bug:上一帧的动画可能显示在下一帧里。\n\n";cout << " - ";system("pause & cls");cout << "========== 游戏操作指南 ==========\n\n";cout << " A 键:向左移动。\n";cout << " D 键:向右移动。\n";cout << " W 键:向上移动。\n";cout << " S 键:向下移动。\n";cout << " Z 键:调整渲染距离。\n";cout << " Q 键:暂停游戏。\n\n";cout << " - ";system("pause & cls");SlowOutput("========== 游戏操作指南 ==========\n\n",0);SlowOutput(" 庄园是一个 300 * 300 的正方形矩阵,\n");SlowOutput(" '#' 代表墙,'.' 代表空地,\n");SlowOutput(" 'A' 代表苹果,'Z' 代表僵尸。\n\n");SlowOutput(" 庄园外围被一圈铁栏杆围着,你无法出入。\n\n");SlowOutput(" 注意:如果你的电脑上安装了联想电脑管家,\n");SlowOutput(" 建议将其暂时关闭,因为这个软件可能导致终端卡顿。\n\n");SlowOutput(" - 准备好了吗?");system("pause & cls");ofstream file2("config.dat");file2 << "HelloUIDisplay:true";file2.close();}bool CheckResult(){if(score <= LOSE_SCORE){system("cls");cout << "你被僵尸残忍杀害!";return true;}if(score >= WIN_SCORE && map[HEIGHT][WIDTH] != 'O'){system("cls");cout << "传送门已开启!";for(int i = HEIGHT - 2;i <= HEIGHT;i++){for(int j = WIDTH - 2;j <= WIDTH;j++){map[i][j] = 'O';}}cout << "按 Q 键退出。";while(_getch() != 'q');}if(map[pl_x][pl_y] == 'O'){system("cls");cout << "你成功逃出了庄园!";return true;}return false;}int main(){HelloUI();srand(time(NULL));system("color f0");system("mode con cols=55 lines=35");GameTool::HideCursor();InitMap();int timestamp = 1;int last_score = 0;while(true){RenderScreen();HandleKey();EatApple();if(timestamp % 100 == 0){GenerateApple(10);}if(timestamp > 60){ZombieAttack();}if(timestamp % 10 == 0){ZForwardToP();}if(timestamp % 60 == 0){SummonZombie();zombie_live++;}if(timestamp % 60 == 0){if(score <= last_score && combo > 0){combo = 0;system("cls");} else{last_score = score;}}if(CheckResult()) break;timestamp++;Sleep(50);GameTool::CursorMove(0,0);}GameTool::ShowCursor();cout << " 用时 " << (timestamp - 1) / 20 << " 秒。\n\n";cout << "按 Q 键结束游戏。";while(_getch() != 'q');return 0;}```### v1.1 测试版```cpp line-numbers#include <bits/stdc++.h>#include <windows.h>#include <conio.h>using namespace std;typedef pair<string,int> Item;const int WIDTH = 300;const int HEIGHT = 300;int RENDER_SIZE = (19 - 1) / 2;3 行未改动const int dx[] = {0,0,-1,1};const int dy[] = {-1,1,0,0};const unordered_map<string,pair<int,int> > CHEST_CAN_OPEN = {{"生命恢复药剂",{1,3}}, /* 30% */{"积分",{4,7}}, /* 40% */{"剑",{8,10}} /* 30% */};char world[HEIGHT + 5][WIDTH + 5];int zombie_hp[HEIGHT + 5][WIDTH + 5];bitset<WIDTH + 5> chest[HEIGHT + 5];bitset<WIDTH + 5> apple[HEIGHT + 5];bitset<WIDTH + 5> zombie[HEIGHT + 5];bitset<WIDTH + 5> is_hurt[HEIGHT + 5];bitset<WIDTH + 5> vis[HEIGHT + 5];unordered_map<string,int> bag;string hand_item_name = "";int pl_x = HEIGHT / 2,pl_y = WIDTH / 2;int pl_hp = 20;int score = 0,combo = 0;enum ForeColor{Black = 30,Red = 31,Green = 32,Yellow = 33,Blue = 34,Magenta = 35,Cyan = 36,White = 37,BrightBlack = 90,BrightRed = 91,BrightGreen = 92,BrightYellow = 93,BrightBlue = 94,BrightMagenta = 95,BrightCyan = 96,BrightWhite = 97};enum BackColor{BBlack = 40,BRed = 41,BGreen = 42,BYellow = 43,4 行未改动};namespace GameTool{double Euclid_dis(pair<int,int> pos1,pair<int,int> pos2){int x1 = pos1.first,y1 = pos1.second;int x2 = pos2.first,y2 = pos2.second;double res = sqrt(double((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)));return res;}void SlowOutput(string str,int speed = 50){for(char ch : str){cout << ch;if(ch == ' ' || ch == '\n') continue;Sleep(speed);}}void CursorMove(int x,int y){HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);COORD pos = {(SHORT)x,(SHORT)y};SetConsoleCursorPosition(h,pos);}void OpenVT(){HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);DWORD dwMode = 0;if(GetConsoleMode(h,&dwMode)){dwMode |= 0x0004;if(SetConsoleMode(h,dwMode));else{cout << "请使用 Win10 以上的系统游玩!";exit(0);}}}void HideCursor(){HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);CONSOLE_CURSOR_INFO cinfo;GetConsoleCursorInfo(h,&cinfo);cinfo.bVisible = false;SetConsoleCursorInfo(h,&cinfo);}void ShowCursor(){HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);CONSOLE_CURSOR_INFO cinfo;GetConsoleCursorInfo(h,&cinfo);cinfo.bVisible = true;SetConsoleCursorInfo(h,&cinfo);6 行未改动inline void SetBackColor(BackColor bg = BBrightWhite){cout << "\033[" << (int)bg << "m";}inline void ResetColor(){SetTextColor();SetBackColor();}14 行未改动if(world[apple_x][apple_y] == '#') continue;if(world[apple_x][apple_y] == 'O') continue;apple[apple_x][apple_y] = true;}}void GenerateChest(int cnt){for(int i = 1;i <= cnt;i++){5 行未改动if(world[chest_x][chest_y] == 'O') continue;chest[chest_x][chest_y] = true;}}void InitMap(){for(int i = 1;i <= HEIGHT;i++){for(int j = 1;j <= WIDTH;j++){if(rand() % 10 == 0){15 行未改动}GenerateApple(HEIGHT * WIDTH / 100);GenerateChest(HEIGHT * WIDTH / 2000);}void RenderScreen(){for(int i = pl_x - RENDER_SIZE;i <= pl_x + RENDER_SIZE;i++){for(int j = pl_y - RENDER_SIZE;j <= pl_y + RENDER_SIZE;j++){if(GameTool::Euclid_dis({pl_x,pl_y},{i,j}) > RENDER_SIZE){cout << ' ';} else if(i < 0 || i > HEIGHT + 1 || j < 0 || j > WIDTH + 1){cout << ' ';} else if(i == pl_x && j == pl_y){if(is_hurt[i][j]){GameTool::SetTextColor(Red);is_hurt[i][j] = false;} else{GameTool::SetTextColor(Green);}cout << 'P';GameTool::ResetColor();} else if(apple[i][j]){GameTool::SetTextColor(BrightRed);cout << 'A';GameTool::ResetColor();}else if(zombie[i][j]){if(is_hurt[i][j]){GameTool::SetTextColor(Red);is_hurt[i][j] = false;} else{GameTool::SetTextColor(Green);GameTool::SetBackColor(BRed);}10 行未改动cout << ' ';}cout << '\n';}cout << "\n - X 坐标:" << pl_x << " Y 坐标:" << pl_y << string(10,' ') << '\n';cout << " - 积分:" << score << string(20,' ') << '\n';cout << " - 连击数: " << combo << string(20,' ') << '\n' << string(20,' ') << '\n';5 行未改动}cout << " - 背包:" << string(20,' ') << '\n';for(Item item : bag){if(item.first == hand_item_name){cout << " > " << item.first << " " << item.second << " 个 <" << string(20,' ') << '\n';} else{cout << " " << item.first << " " << item.second << " 个" << string(20,' ') << '\n';}}cout << string(30,' ') << '\n' << string(30,' ') << '\n';}void SummonZombie(){int limit_x = min(HEIGHT,pl_x + RENDER_SIZE * 4);int limit_y = min(WIDTH,pl_y + RENDER_SIZE * 4);int down_limit_x = max(1,pl_x - RENDER_SIZE * 4);int down_limit_y = max(1,pl_y - RENDER_SIZE * 4);int randX = rand() % (limit_x - down_limit_x + 1) + down_limit_x;int randY = rand() % (limit_y - down_limit_y + 1) + down_limit_y;if(world[randX][randY] == '#') return;if(world[randX][randY] == 'O') return;zombie_hp[randX][randY] = 20;zombie[randX][randY] = true;}void RemoveDiedZombie(){int limit_x = min(HEIGHT,pl_x + RENDER_SIZE * 4);int limit_y = min(WIDTH,pl_y + RENDER_SIZE * 4);int down_limit_x = max(1,pl_x - RENDER_SIZE * 4);int down_limit_y = max(1,pl_y - RENDER_SIZE * 4);for(int i = down_limit_x;i <= limit_x;i++){for(int j = down_limit_y;j <= limit_y;j++){if(zombie_hp[i][j] <= 0){zombie_hp[i][j] = 0;zombie[i][j] = false;}}}}void ZForwardToP(){int limit_x = min(HEIGHT,pl_x + RENDER_SIZE * 4);6 行未改动vis[i][j] = false;}}queue<BFSNode> q;q.push({pl_x,pl_y,{-1,-1}});while(!q.empty()){BFSNode now = q.front();q.pop();14 行未改动vis[x][y] = true;if(world[x][y] == '#') continue;if(world[x][y] == 'O') continue;if(zombie[x][y]){if(lastx != -1 && lasty != -1 && zombie[lastx][lasty] == false){zombie[x][y] = false;3 行未改动}}for(int i = 0;i < 4;i++){int xx = x + dx[i];int yy = y + dy[i];q.push({xx,yy,{x,y}});}}}void ZombieAttack(){if(zombie[pl_x][pl_y]){score -= 3;pl_hp -= 5;combo = 0;is_hurt[pl_x][pl_y] = true;zombie[pl_x][pl_y] = false;}}void UseHandItem(){if(hand_item_name.empty()) return;2 行未改动for(int i = -2;i <= 2;i++){for(int j = -2;j <= 2;j++){int x = pl_x + i;int y = pl_y + j;if(zombie[x][y]){zombie_hp[x][y] -= 10;is_hurt[x][y] = true;}}}} else if(hand_item_name == "生命恢复药剂"){pl_hp += 15;}bag[hand_item_name]--;if(bag[hand_item_name] <= 0){bag.erase(hand_item_name);hand_item_name.clear();}}void ChargeRenderSize(){system("cls");3 行未改动cout << " 注意:调整后请自行调整窗口大小。\n\n";cout << "请输入新的渲染范围半径(输入 4~25 的整数):" ;cin >> r;if(r < 4 || r > 25){cout << "\n请勿设置不合理的渲染距离。\n\n";GameTool::HideCursor();system("pause");return;}RENDER_SIZE = r;GameTool::HideCursor();system("cls");}void SwitchHandItem(int idx){if(bag.size() >= idx){hand_item_name = (next(bag.begin(),idx - 1) -> first);}}void HandleKey(){if(_kbhit()){char ch = _getch();ch = tolower(ch);17 行未改动cout << '\n';system("pause & cls");}}}void EatApple(){if(apple[pl_x][pl_y] == false){8 行未改动if(combo >= 3){score += floor(sqrt(combo - 2));}apple[pl_x][pl_y] = false;}void OpenChest(){if(chest[pl_x][pl_y]){7 行未改动int item_cnt = rand() % 4 + 1;while(item_cnt--){int rand_num = rand() % 10 + 1;for(auto item : CHEST_CAN_OPEN){if(rand_num >= item.second.first && rand_num <= item.second.second){if(item.first == "积分"){open_items[item.first] += rand() % 21 + 10;} else{open_items[item.first]++;}break;}}}cout << " 你开出了以下物品:\n";for(auto item : open_items){cout << " - " << item.first << "*" << item.second << '\n';if(item.first == "积分"){score += item.second;} else{bag[item.first] += item.second;}}cout << "\n 物品已自动放入背包。\n\n";chest[pl_x][pl_y] = false;system("pause & cls");}}void HelloUI(){using namespace GameTool;ifstream file("config.dat");string line;file >> line;if(line.find("HelloUIDisplay:true") != string::npos){char choose;cout << "检测到你已经看过游戏介绍,是否跳过?(T/F)\n";cin >> choose;if(choose == 'T'){file.close();return;} else{system("cls");}}file.close();SlowOutput("========== 欢迎来到 僵尸庄园v1.1 ==========\n\n");SlowOutput(" 在这里,你需要收集地上的苹果,每个\n");SlowOutput(" 苹果可以获得 1 积分。\n");SlowOutput(" 初始状态你没有积分。\n\n");SlowOutput(" 当你快速的吃掉 3 个以上的苹果,\n");3 行未改动cout << " - ";system("pause & cls");SlowOutput("========== 欢迎来到 僵尸庄园v1.1 ==========\n\n",0);SlowOutput(" 但是,庄园里的稻草人都变异了,\n");SlowOutput(" 会变成僵尸追击你。\n\n");SlowOutput(" 如果你不幸被他们碰到,\n");SlowOutput(" 你将会失去 3 个积分 和 10 点血。\n");SlowOutput(" 但那只僵尸会消失不见。 \n\n");SlowOutput(" 每当你吃下一个苹果,\n");SlowOutput(" 将会随机抽选一只僵尸消失不见。\n\n");cout << " - ";system("pause & cls");SlowOutput("========== 欢迎来到 僵尸庄园v1.1 ==========\n\n",0);SlowOutput(" 庄园里每隔一会儿就会刷新一个宝箱,\n");SlowOutput(" 里面可以开出物品如下: \n");SlowOutput(" 剑、生命恢复药剂。\n\n");SlowOutput(" 剑的刷新几率为 30%,\n");SlowOutput(" 生命恢复药剂几率为 30%。\n");SlowOutput(" 积分几率为 40%。\n\n");SlowOutput(" 剑可以对周围 5 * 5 僵尸造成 10 点伤害,\n");SlowOutput(" 此物品为一次性品。\n\n");2 行未改动cout << " - ";system("pause & cls");SlowOutput("========== 欢迎来到 僵尸庄园v1.1 ==========\n\n",0);SlowOutput(" 当你在当前的情形中获得 200 积分,\n");SlowOutput(" 在整个庄园右下角将会出现一个出口,\n");SlowOutput(" 当你进入这个出口,你就逃出了这个庄园。\n\n");SlowOutput(" 若你血量小于 0,\n");SlowOutput(" 你将消失不见并永远变成一个僵尸。\n\n");SlowOutput(" 祝你好运。 Good Luck. \n\n");cout << " - ";system("pause & cls");cout << "========== 更新公告 ==========\n\n";cout << " 1. 当前苹果刷新不在定时刷新,\n 而是吃掉一个苹果后补齐一个。\n";cout << " 2. 新增玩家血量,上限 20 点。\n";cout << " 3. 新增僵尸血量,上限 20 点。\n";cout << " 4. 移除僵尸存活数,被血量顶替。\n";cout << " 5. 增加处理范围为 4 倍渲染范围。\n";cout << " 6. 将打开传送门的分数增加为 200。\n";cout << " 7. 使用 ANSI 转义码(Win10+)进行颜色切换,增加系统兼容性判断。\n";cout << " 8. 计时方式改为 tick 计时,保证公平性。\n";cout << " 9. 改进僵尸攻击逻辑。\n";cout << " 10. 增加宝箱,内可开出 剑和生命恢复药剂。\n 刷新概率:剑 50%,生命恢复药剂 20%。\n";cout << " - 剑使用时可以对 5 * 5 范围的僵尸造成 10 点伤害。\n";cout << " - 生命恢复药剂使用时可以瞬间恢复 15 点血,\n\n";cout << " - ";system("pause & cls");cout << "========== 游戏操作指南 ==========\n\n";cout << " A 键:向左移动。\n";cout << " D 键:向右移动。\n";cout << " W 键:向上移动。\n";cout << " S 键:向下移动。\n";cout << " E 键:使用当前物品。\n";cout << " Z 键:调整渲染距离。\n";cout << " Q 键:暂停游戏。\n";cout << " 数字 1 键:切换手持物品为背包内第 1 个物品。\n";cout << " 数字 2 键:切换手持物品为背包内第 2 个物品。\n\n";6 行未改动SlowOutput(" '#' 代表墙,'.' 代表空地,\n");SlowOutput(" 'A' 代表苹果,'Z' 代表僵尸,\n");SlowOutput(" 'G' 代表宝箱。\n\n");SlowOutput(" 庄园外围被一圈铁栏杆围着,你无法出入。\n\n");SlowOutput(" 注意:如果你的电脑上安装了联想电脑管家,\n");SlowOutput(" 建议将其暂时关闭,因为这个软件可能导致终端卡顿。\n\n");SlowOutput(" - 准备好了吗?");system("pause & cls");ofstream file2("config.dat");file2 << "HelloUIDisplay:true";file2.close();}bool CheckResult(){if(pl_hp <= LOSE_SCORE || score <= LOSE_SCORE){system("cls");cout << "你被僵尸残忍杀害!";return true;}4 行未改动for(int i = HEIGHT - 2;i <= HEIGHT;i++){for(int j = WIDTH - 2;j <= WIDTH;j++){world[i][j] = 'O';}}cout << "按 Q 键退出。";while(_getch() != 'q');}if(world[pl_x][pl_y] == 'O'){system("cls");5 行未改动return false;}int main(){GameTool::OpenVT();HelloUI();srand(time(NULL));system("color f0");system("mode con cols=55 lines=40");GameTool::HideCursor();InitMap();int timestamp = 1;int last_score = 0;while(true){3 行未改动EatApple();OpenChest();if(timestamp % 50 == 0){GenerateChest(2);}if(timestamp > 60){ZombieAttack();}if(timestamp % 10 == 0){ZForwardToP();RemoveDiedZombie();}if(timestamp % 60 == 0){SummonZombie();}if(timestamp % 60 == 0){15 行未改动cout << " 用时 " << timestamp - 1 << " tick。\n\n";cout << "按 Q 键结束游戏。";while(_getch() != 'q');return 0;}```12345678910111213141516171819202122232425262728293 行未改动33343536373839404142434445464748495051525354555657585960616263646566674 行未改动727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221236 行未改动13013113213313413513613713813914014114 行未改动1561571581591601611621631641655 行未改动17117217317417517617717817918018118218318418518618718818919015 行未改动20620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224310 行未改动2542552562572582592602612622635 行未改动2692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323336 行未改动34034134234334434534634734834935035135214 行未改动3673683693703713723733743753763 行未改动3803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094102 行未改动4134144154164174184194204214224234244254264274284294304314324334344354364374383 行未改动44244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747817 行未改动4964974984995005015025035045058 行未改动5145155165175185195205215225237 行未改动5315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765773 行未改动5815825835845855865875885895905915925935945955965975985996006016026036042 行未改动6076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486 行未改动6556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997004 行未改动7057067077087097107117127137147157167177187195 行未改动7257267277287297307317327337347357367377387397407417427437443 行未改动74874975075175275375475575675775875976076176276376476576615 行未改动782783784785786787788789790791792793794795796797**提示:所有游戏仅供 Windows 系统使用。****你可以通过左边的标题栏快速查看版本。**## 《僵尸庄园》- 源码下载地址:[https://wwana.lanzoue.com/i4oqR47ftfri](https://wwana.lanzoue.com/i4oqR47ftfri)密码:`yxnb`### 最新版快捷下载**版本:`v1.1.2`**```cpp line-numbers#include <bits/stdc++.h>#include <windows.h>#include <conio.h>using namespace std;#if __cplusplus < 201107L#define unordered_map map#endiftypedef pair<string,int> Item;typedef pair<int,int> Pii;const int WIDTH = 300;const int HEIGHT = 300;int RENDER_SIZE = (19 - 1) / 2;3 行未改动const int dx[] = {0,0,-1,1};const int dy[] = {-1,1,0,0};unordered_map<string,pair<int,int> > CHEST_CAN_OPEN;char world[HEIGHT + 5][WIDTH + 5];bitset<WIDTH + 5> chest[HEIGHT + 5];bitset<WIDTH + 5> apple[HEIGHT + 5];int zombie_hp[HEIGHT + 5][WIDTH + 5];bitset<WIDTH + 5> zombie[HEIGHT + 5];bitset<WIDTH + 5> zombie_hurt[HEIGHT + 5];bitset<WIDTH + 5> vis[HEIGHT + 5];HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);int pl_x = HEIGHT / 2,pl_y = WIDTH / 2;int pl_hp = 20;int score = 0,combo = 0;short player_mode = 0; // default:0 hurt:1 heal:2unordered_map<string,int> bag;string hand_item_name = "";enum ForeColor{Black = 30,Red = 31,Green = 32,Yellow = 33,Blue = 34,Magenta = 35,Cyan = 36,White = 37,BrightBlack = 90,BrightRed = 91,BrightGreen = 92,BrightYellow = 93,BrightBlue = 94,BrightMagenta = 95,BrightCyan = 96,BrightWhite = 97,};enum BackColor{BBlack = 40,BRed = 41,BGreen = 42,BYellow = 43,4 行未改动};namespace GameTool{inline int Euclid_dis(pair<int,int> pos1,pair<int,int> pos2){int x1 = pos1.first,y1 = pos1.second;int x2 = pos2.first,y2 = pos2.second;int res = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);return res;};void SlowOutput(string str,int speed = 50){for(int i = 0;i < str.length();i++){char ch = str[i];cout << ch;if(ch == ' ' || ch == '\n') continue;Sleep(speed);}}void CursorMove(int x,int y){COORD pos = {(SHORT)x,(SHORT)y};SetConsoleCursorPosition(h,pos);}void OpenVT(){DWORD dwMode = 0;if(GetConsoleMode(h,&dwMode)){dwMode |= 0x0004;if(SetConsoleMode(h,dwMode)){}else{cout << "请使用 Win10 以上的系统游玩!";exit(0);}}}void HideCursor(){CONSOLE_CURSOR_INFO cinfo;GetConsoleCursorInfo(h,&cinfo);cinfo.bVisible = false;SetConsoleCursorInfo(h,&cinfo);}void ShowCursor(){CONSOLE_CURSOR_INFO cinfo;GetConsoleCursorInfo(h,&cinfo);cinfo.bVisible = true;SetConsoleCursorInfo(h,&cinfo);6 行未改动inline void SetBackColor(BackColor bg = BBrightWhite){cout << "\033[" << (int)bg << "m";}inline void SetTextCustomColor(string RGB){cout << "\033[38;2;" << RGB << "m";}inline void ResetColor(){SetTextColor();SetBackColor();}14 行未改动if(world[apple_x][apple_y] == '#') continue;if(world[apple_x][apple_y] == 'O') continue;apple[apple_x][apple_y] = true;}return;}void GenerateChest(int cnt){for(int i = 1;i <= cnt;i++){5 行未改动if(world[chest_x][chest_y] == 'O') continue;chest[chest_x][chest_y] = true;}return;}void InitItemMap(){CHEST_CAN_OPEN["生命恢复药剂"] = make_pair(1,3); // 30%CHEST_CAN_OPEN["积分"] = make_pair(4,7); // 40%CHEST_CAN_OPEN["剑"] = make_pair(8,10); // 30%return;}void InitMap(){for(int i = 1;i <= HEIGHT;i++){for(int j = 1;j <= WIDTH;j++){if(rand() % 10 == 0){15 行未改动}GenerateApple(HEIGHT * WIDTH / 100);GenerateChest(HEIGHT * WIDTH / 2000);return;}void RenderScreen(bool render_info = true){for(int i = pl_x - RENDER_SIZE;i <= pl_x + RENDER_SIZE;i++){for(int j = pl_y - RENDER_SIZE;j <= pl_y + RENDER_SIZE;j++){if(GameTool::Euclid_dis(make_pair(pl_x,pl_y),make_pair(i,j)) > RENDER_SIZE * RENDER_SIZE){cout << ' ';} else if(i < 0 || i > HEIGHT + 1 || j < 0 || j > WIDTH + 1){cout << ' ';} else if(i == pl_x && j == pl_y){if(player_mode == 1){GameTool::SetTextColor(Red);} else if(player_mode == 2){GameTool::SetTextCustomColor("255;105;180"); // pink} else{GameTool::SetTextColor(Green);}player_mode = 0;cout << 'P';GameTool::ResetColor();} else if(apple[i][j]){GameTool::SetTextColor(BrightRed);cout << 'A';GameTool::ResetColor();} else if(zombie[i][j]){if(zombie_hurt[i][j]){GameTool::SetTextColor(Red);if(zombie_hp[i][j] > 0) zombie_hurt[i][j] = false;} else{GameTool::SetTextColor(Green);GameTool::SetBackColor(BRed);}10 行未改动cout << ' ';}cout << '\n';}if(render_info == false) return;cout << "\n - X 坐标:" << pl_x << " Y 坐标:" << pl_y << string(10,' ') << '\n';cout << " - 积分:" << score << string(20,' ') << '\n';cout << " - 连击数: " << combo << string(20,' ') << '\n' << string(20,' ') << '\n';5 行未改动}cout << " - 背包:" << string(20,' ') << '\n';for(unordered_map<string,int>::iterator item = bag.begin();item != bag.end();item++){if(item->first == hand_item_name){cout << " > " << item->first << " " << item->second << " 个 <" << string(20,' ') << '\n';} else{cout << " " << item->first << " " << item->second << " 个" << string(20,' ') << '\n';}}cout << string(30,' ') << '\n' << string(30,' ') << '\n';return;}void SummonZombie(){int limit_x,limit_y,down_limit_x,down_limit_y;if(score > WIN_SCORE && rand() % 2 == 0){limit_x = HEIGHT;limit_y = WIDTH;down_limit_x = HEIGHT - 20;down_limit_y = WIDTH - 20;} else{limit_x = min(HEIGHT,pl_x + RENDER_SIZE * 4);limit_y = min(WIDTH,pl_y + RENDER_SIZE * 4);down_limit_x = max(1,pl_x - RENDER_SIZE * 4);down_limit_y = max(1,pl_y - RENDER_SIZE * 4);}int randX = rand() % (limit_x - down_limit_x + 1) + down_limit_x;int randY = rand() % (limit_y - down_limit_y + 1) + down_limit_y;if(world[randX][randY] == '#') return;if(world[randX][randY] == 'O') return;zombie_hp[randX][randY] = 20;zombie[randX][randY] = true;return;}void RemoveDiedZombie(){int limit_x = min(HEIGHT,pl_x + RENDER_SIZE * 4);int limit_y = min(WIDTH,pl_y + RENDER_SIZE * 4);int down_limit_x = max(1,pl_x - RENDER_SIZE * 4);int down_limit_y = max(1,pl_y - RENDER_SIZE * 4);for(int i = down_limit_x;i <= limit_x;i++){for(int j = down_limit_y;j <= limit_y;j++){if(zombie_hp[i][j] <= 0){zombie_hp[i][j] = 0;zombie[i][j] = false;zombie_hurt[i][j] = false;}}}return;}void ZForwardToP(){int limit_x = min(HEIGHT,pl_x + RENDER_SIZE * 4);6 行未改动vis[i][j] = false;}}BFSNode start;start.x = pl_x,start.y = pl_y,start.last = make_pair(-1,-1);queue<BFSNode> q;q.push(start);while(!q.empty()){BFSNode now = q.front();q.pop();14 行未改动vis[x][y] = true;if(world[x][y] == '#') continue;if(world[x][y] == 'O') continue;if(apple[x][y]) continue;if(chest[x][y]) continue;if(zombie[x][y]){if(lastx != -1 && lasty != -1 && zombie[lastx][lasty] == false){zombie[x][y] = false;3 行未改动}}for(int i = 0;i < 4;i++){BFSNode nxt;nxt.x = x + dx[i];nxt.y = y + dy[i];nxt.last = make_pair(x,y);q.push(nxt);}}return;}void ZombieAttack(){if(zombie[pl_x][pl_y] && zombie_hp[pl_x][pl_y] > 0){score -= 3;pl_hp -= 5;combo = 0;player_mode = 1;zombie[pl_x][pl_y] = false;}return;}void UseHandItem(){if(hand_item_name.empty()) return;2 行未改动for(int i = -2;i <= 2;i++){for(int j = -2;j <= 2;j++){int x = pl_x + i;int y = pl_y + j;if(zombie[x][y] && zombie_hp[x][y] > 0){zombie_hp[x][y] -= 10;zombie_hurt[x][y] = true;}}}} else if(hand_item_name == "生命恢复药剂"){pl_hp = min(pl_hp + 15,20);player_mode = 2;}bag[hand_item_name]--;if(bag[hand_item_name] <= 0){bag.erase(hand_item_name);hand_item_name.clear();}return;}void ChargeRenderSize(){system("cls");3 行未改动cout << " 注意:调整后请自行调整窗口大小。\n\n";cout << "请输入新的渲染范围半径(输入 4~25 的整数):" ;cin >> r;cin.ignore(1024,'\n');if(r < 4 || r > 25){cout << "\n请勿设置不合理的渲染距离。\n\n";GameTool::HideCursor();system("pause & cls");return;}RENDER_SIZE = r;GameTool::HideCursor();system("cls");return;}void SwitchHandItem(int idx){if(bag.size() >= idx){unordered_map<string,int>::iterator target = bag.begin();advance(target,idx - 1);hand_item_name = (*target).first;}return;}void HandleKey(){if(_kbhit()){char ch = _getch();ch = tolower(ch);17 行未改动cout << '\n';system("pause & cls");}}return;}void EatApple(){if(apple[pl_x][pl_y] == false){8 行未改动if(combo >= 3){score += floor(sqrt(combo - 2));}apple[pl_x][pl_y] = false;return;}void OpenChest(){if(chest[pl_x][pl_y]){7 行未改动int item_cnt = rand() % 4 + 1;while(item_cnt--){int rand_num = rand() % 10 + 1;for(unordered_map<string,pair<int,int> >::iterator item = CHEST_CAN_OPEN.begin();item != CHEST_CAN_OPEN.end();item++){if(rand_num >= item->second.first && rand_num <= item->second.second){if(item->first == "积分"){open_items[item->first] += rand() % 6 + 5;} else if(item->first == "剑"){open_items[item->first] += 3;} else{open_items[item->first]++;}break;}}}cout << " 你开出了以下物品:\n";for(unordered_map<string,int>::iterator item = open_items.begin();item != open_items.end();item++){cout << " - " << item->first << "*" << item->second << '\n';if(item->first == "积分"){score += item->second;} else{bag[item->first] += item->second;}}cout << "\n 物品已自动放入背包。\n\n";chest[pl_x][pl_y] = false;system("pause & cls");}return;}void HelloUI(){using namespace GameTool;system("cls");SlowOutput("========== 欢迎来到 僵尸庄园v1.1.2 ==========\n\n");SlowOutput(" 在这里,你需要收集地上的苹果,每个\n");SlowOutput(" 苹果可以获得 1 积分。\n");SlowOutput(" 初始状态你没有积分。\n\n");SlowOutput(" 当你快速的吃掉 3 个以上的苹果,\n");3 行未改动cout << " - ";system("pause & cls");SlowOutput("========== 欢迎来到 僵尸庄园v1.1.2 ==========\n\n",0);SlowOutput(" 但是,庄园里的稻草人都变异了,\n");SlowOutput(" 会变成僵尸追击你,\n");SlowOutput(" 它们也拥有 20 点血。\n\n");SlowOutput(" 如果你不幸被他们碰到,\n");SlowOutput(" 你将会失去 3 个积分 和 5 点血。\n");SlowOutput(" 但那只僵尸会消失不见。 \n\n");cout << " - ";system("pause & cls");SlowOutput("========== 欢迎来到 僵尸庄园v1.1.2 ==========\n\n",0);SlowOutput(" 庄园里每隔一会儿就会刷新一个宝箱,\n");SlowOutput(" 里面可以开出物品如下: \n");SlowOutput(" 剑、生命恢复药剂和积分。\n\n");SlowOutput(" 剑的刷新几率为 30%(1 次 3 把),\n");SlowOutput(" 生命恢复药剂几率为 30%。\n");SlowOutput(" 积分几率为 40%。\n\n");SlowOutput(" 剑可以对周围 5 * 5 僵尸造成 10 点伤害,\n");SlowOutput(" 此物品为一次性品。\n\n");2 行未改动cout << " - ";system("pause & cls");SlowOutput("========== 欢迎来到 僵尸庄园v1.1.2 ==========\n\n",0);SlowOutput(" 当你在当前的情形中获得 200 积分,\n");SlowOutput(" 在整个庄园右下角将会出现一个传送门,\n");SlowOutput(" 当你进入这个传送门,你就逃出了这个庄园。\n\n");SlowOutput(" 若你血量小于 0 或者 积分小于 0,\n");SlowOutput(" 你将消失不见并永远变成一个僵尸。\n\n");SlowOutput(" 祝你好运。 Good Luck. \n\n");cout << " - ";system("pause & cls");cout << "========== 更新公告 ==========\n\n";cout << " 1. 修复部分文案错误。\n";cout << " 2. 增加生命恢复动画。\n";cout << " 3. 增加主菜单。\n";cout << " 4. 移除 config.dat,改为用户主动选择。\n";cout << " 5. 如果开启传送门,僵尸将会有 50% 的几率刷新在传送门附近。\n";cout << " 6. 加快僵尸速度,从原本的 20tick 变为 10tick。\n";cout << " 7. 死亡后僵尸将一直保持受伤状态,直到被清除。\n";cout << " 8. 修复 bug:玩家受伤动画错误。\n";cout << " 9. 修复 bug:死亡后的僵尸仍可以攻击玩家。\n";cout << " 10. 修复 bug:死亡后的僵尸受伤动画仍然存在,只是不显示。\n";cout << " 11. 修复 bug:僵尸受伤动画和玩家共用导致可能出现无效受伤动画。\n";cout << " 12. 修复 bug:输入大写 Q 时无法退出结束动画。\n\n";cout << " - ";system("pause & cls");cout << "========== 游戏操作指南 ==========\n\n";cout << " A 键:向左移动。\n";cout << " D 键:向右移动。\n";cout << " W 键:向上移动。\n";cout << " S 键:向下移动。\n";cout << " U 键:使用当前物品。\n";cout << " Z 键:调整渲染距离。\n";cout << " Q 键:暂停游戏。\n";cout << " 数字 1 键:切换手持物品为背包内第 1 个物品。\n";cout << " 数字 2 键:切换手持物品为背包内第 2 个物品。\n\n";6 行未改动SlowOutput(" '#' 代表墙,'.' 代表空地,\n");SlowOutput(" 'A' 代表苹果,'Z' 代表僵尸,\n");SlowOutput(" 'G' 代表宝箱。\n\n");SlowOutput(" 庄园外围被一圈铁栏杆围着,你无法出入。\n\n");SlowOutput(" 提示:建议使用旧版终端游玩。\n\n");system("pause & cls");return;}void MainUI(){using namespace GameTool;RENDER_SIZE = 4;RenderScreen(false);RENDER_SIZE = 9;CursorMove(20,2);cout << "僵尸庄园 v1.1.2";CursorMove(21,4);cout << "制作者:yuxiao";CursorMove(0,10);SlowOutput(" 1. 开始游戏\n");SlowOutput(" 2. 查看帮助\n\n");SlowOutput(" 输入序号以执行操作。");while(true){char ch = _getch();if(ch == '1'){break;} else if(ch == '2'){HelloUI();}}system("cls");return;}bool CheckResult(){if(pl_hp <= 0 || score <= LOSE_SCORE){system("cls");cout << "你被僵尸残忍杀害!";return true;}4 行未改动for(int i = HEIGHT - 2;i <= HEIGHT;i++){for(int j = WIDTH - 2;j <= WIDTH;j++){world[i][j] = 'O';apple[i][j] = false;zombie[i][j] = false;}}cout << "按 Q 键退出。";while(tolower(_getch()) != 'q');}if(world[pl_x][pl_y] == 'O'){system("cls");5 行未改动return false;}int main(){system("color f0");system("mode con cols=55 lines=40");srand(time(NULL));GameTool::OpenVT();InitItemMap();InitMap();MainUI();GameTool::HideCursor();int timestamp = 1;int last_score = 0;while(true){3 行未改动EatApple();OpenChest();if(timestamp % 50 == 0){GenerateChest(5);}if(timestamp > 60){ZombieAttack();}if(timestamp % 10 == 0){RemoveDiedZombie();ZForwardToP();}if(timestamp % 40 == 0){SummonZombie();}if(timestamp % 60 == 0){15 行未改动cout << " 用时 " << timestamp - 1 << " tick。\n\n";cout << "按 Q 键结束游戏。";while(tolower(_getch()) != 'q');return 0;}```## 《2D Minecraft》- 源码下载地址:[https://wwana.lanzoue.com/iK4iO45onecd](https://wwana.lanzoue.com/iK4iO45onecd)密码:`yxnb`注:下载完后把后缀名 `.txt` 删掉,会自动变成 `.cpp`。(需开启显示扩展名)