版本比较
修仙小游戏
正文
增加 123 行删除 123 行
123455678910111213141515161718196 行未改动262728293030313233343535363738394041424243444546474748495051525253545556575758596061616263646566666768697071727374757676777879798081828344 行未改动12812913013113213213313413413513613713813914014114214314414414514614714836 行未改动18518618718818918919019119219358 行未改动25225325425525625625725825926026126226326226326426526626626726826926927027127227227327427527692 行未改动36937037137237337337437537637637737837938032 行未改动41341441541641741741841942042042142242342430 行未改动45545645745845945946046146246346446446546646746746846947047122 行未改动49449549649749849849950050150150250350450541 行未改动5475485495505515515525535545555555565575585595605615625635645645655665675685695705715725735745745755765775783 行未改动58258358458558658658758858959059159259259359459559559659759759859960060160260260360460560660760860961061061161261361361461561661661761861962062162262362462562662662762862963063163263363463563563663763863964064164264364364464564564664764864920 行未改动67067167267367467467567667767812 行未改动69169269369469569569669769869970070170170270370470470570670670770870971071171271371471571671671771871972022 行未改动7437447457467477477487497507512 行未改动75475575675775875875976076176219 行未改动78278378478578678678778878979011 行未改动8028038048058068068078088098108118128138138148158158168178188193 行未改动82382482582682782782882983083183183283383483583683783883984084084184284384416 行未改动8618628638648658658668678688692 行未改动87287387487587687687787887988088188288388388488588588688788888989089189189289389489589589689789889914 行未改动91491591691791891891992092192192292392492592692792892993093093193293393414 行未改动9499509519529539539549559569579589599609619629639639649659669675 行未改动97397497597697797797897998098098198298398498598698798898998999099199299311 行未改动1005100610071008100910091010101110121013101410151016101710181018101910201021102219 行未改动10421043104410451046104610471048104910505 行未改动105610571058105910601060106110621063106310641065106610676 行未改动107410751076107710781078107910801081108210831084108410851086108710881089109010911091109210931094109410951096109710981099110011011102110211031104110511061107110711081109111011119 行未改动1121112211231124112511251126112711281128112911301131113211331134113411351136113711382 行未改动1141114211431144114511451146114711481149115011511152115311541155115511561157115811596 行未改动116611671168116911701170117111721173117311741175117611773 行未改动1181118211831184118511851186118711881189118911901191119211931194119511961196119711981199120014 行未改动121512161217121812191219122012211222122312241225122612271228122812291230123112322 行未改动123512361237123812391239124012411242124312441245124612471248124812491250125112522 行未改动12551256125712581259125912601261126212635 行未改动12691270127112721273127312741275127612771278127912801281128212811282128312841285128612871287128812891290129112921292129312941295129612971297129812991300130113021303130413051306130613071308130913108 行未改动131913201321132213231323132413251326132713 行未改动134113421343134413451345134613471348134913501350135113521353135413551356135713581359136013601361136213631364136513661366136713681369137016 行未改动138713881389139013911391139213931394139513961397139813991400140014011402140314041405140514061407140814091410141014111412141314144 行未改动14191420142114221423142314241425142614275 行未改动14331434143514361437143714381439144014415 行未改动14471448144914501451145114521453145314541455145514561457145814595 行未改动```cpp#include<bits/stdc++.h>#include<windows.h>#include<stdio.h>#include<conio.h> #include<conio.h>#define key_down(key_name) GetAsyncKeyState(key_name)using namespace std;
// 双缓冲类 - 解决屏幕闪烁class DoubleBuffer {private: HANDLE hOut, hOut2; CONSOLE_SCREEN_BUFFER_INFO csbi; int width, height;
public: DoubleBuffer() { hOut = GetStdHandle(STD_OUTPUT_HANDLE); hOut2 = CreateConsoleScreenBuffer(6 行未改动 GetConsoleScreenBufferInfo(hOut, &csbi); width = csbi.dwSize.X; height = csbi.dwSize.Y; }
void switchBuffer() { SetConsoleActiveScreenBuffer(hOut2); swap(hOut, hOut2); }
void clear() { COORD coord = {0, 0}; DWORD count; FillConsoleOutputCharacter(hOut2, ' ', width * height, coord, &count); SetConsoleCursorPosition(hOut2, coord); }
void gotoxy(int x, int y) { COORD coord = {(SHORT)y, (SHORT)x}; SetConsoleCursorPosition(hOut2, coord); }
void print(string s) { DWORD count; WriteConsole(hOut2, s.c_str(), s.length(), &count, NULL); }
void print(char c) { DWORD count; WriteConsole(hOut2, &c, 1, &count, NULL); }
void setColor(int color) { SetConsoleTextAttribute(hOut2, color); }
void setColorAndBackground(int forg, int back) { WORD wColor = ((back & 0x0F) << 4) + (forg & 0x0F); SetConsoleTextAttribute(hOut2, wColor); }
~DoubleBuffer() { CloseHandle(hOut2); }};
DoubleBuffer buffer;
int ling_shi=10,jin_bi=100;double xie_liang = 10,gong_ji = 2,gong_su = 1,fang_yu = 0;double ji_chu_xie_liang = 10,ji_chu_gong_ji = 2,ji_chu_gong_su = 1,ji_chu_fang_yu = 0,e_wai_sheng_ming=0; double ji_chu_xie_liang = 10,ji_chu_gong_ji = 2,ji_chu_gong_su = 1,ji_chu_fang_yu = 0,e_wai_sheng_ming=0;int fang_xiang = 1;int xuan_zhong_x;int xuan_zhong_y; int xuan_zhong_y;
// 扩展地图,增加更多NPCchar ditu[10][10] = {{'*','*','*','*','*','*','*','*','*','*'}, {'*','r',' ','d','T',' ',' ',' ',' ','*'},44 行未改动 be_bao[i][j].count = 0; } }}
int be_bao_x=0,be_bao_y=0;string da_jing_jie[12] = {"凡人","练气","筑基","结丹","元婴","化神","练虚","合体","大乘","真仙","金仙","道祖"}; string da_jing_jie[12] = {"凡人","练气","筑基","结丹","元婴","化神","练虚","合体","大乘","真仙","金仙","道祖"};string xiao_jing_jie[6] = {"凡体","初阶","中阶","高价","圆满","无双"};int ti_sheng_ling_qi[12] = {50,100,200,400,600,1000,3000,6000,10000,40000,80000,100000};int da_jing_jie_shu=0,xiao_jing_jie_shu=0;int ling_qi_zhi = 0;
// 商品列表string gou_mai_wu_pin[] = { " ", "(1) 钢剑 攻击+5 攻速+2 ¥100\n", "(2) 铁剑 攻击+8 攻速+1 ¥150\n", "(2) 铁剑 攻击+8 攻速+1 ¥150\n", "(3) 秘银剑 攻击+12 攻速+2 ¥300\n", "(4) 海拉鲁大剑 攻击+20 攻速-0.4 ¥500\n", "(5) 霜之哀伤 攻击+30 攻速-0.2 ¥1000\n", "(6) 皮制盔甲 防御+3 ¥50\n",36 行未改动string wu_pin_shu_zhi[] = { "无", "钢剑 攻击+5 攻速+2", "铁剑 攻击+8 攻速+1", "秘银剑 攻击+12 攻速+2", "秘银剑 攻击+12 攻速+2", "海拉鲁大剑 攻击+20 攻速-0.4", "霜之哀伤 攻击+30 攻速-0.2 暴击+10%", "皮制盔甲 防御+3", "铁制盔甲 防御+6",58 行未改动 SetColor(11); buffer.print("血量: "); SetColor(12); buffer.print(to_string(xie_liang) + "/" + to_string(ji_chu_xie_liang + e_wai_sheng_ming) + " "); SetColor(11); buffer.print("攻击: "); SetColor(12); buffer.print(to_string(gong_ji) + " "); SetColor(11); buffer.print("攻速: "); SetColor(12); buffer.print(to_string(gong_su) + " "); SetColor(11); buffer.print("防御: "); SetColor(12); buffer.print(to_string(fang_yu) + "\n");
SetColor(11); buffer.print("方向: "); SetColor(12); if(fang_xiang==1) buffer.print("左"); if(fang_xiang==2) buffer.print("上"); if(fang_xiang==3) buffer.print("右"); if(fang_xiang==4) buffer.print("下"); buffer.print("\n"); buffer.print("\n");
SetColor(11); buffer.print("灵石: "); SetColor(14); buffer.print(to_string(ling_shi) + " "); SetColor(11); buffer.print("金币: "); SetColor(14); buffer.print(to_string(jin_bi) + "\n");
SetColor(11); buffer.print("境界: "); SetColor(13); buffer.print(da_jing_jie[da_jing_jie_shu] + " " + xiao_jing_jie[xiao_jing_jie_shu] + "\n"); SetColor(11); buffer.print("灵气: "); SetColor(13); buffer.print(to_string(ling_qi_zhi) + " / " + to_string(ti_sheng_ling_qi[da_jing_jie_shu] + (xiao_jing_jie_shu-1)*20) + "\n");
SetColor(11); buffer.print("武器: "); SetColor(14); buffer.print(wu_qi + " "); SetColor(11); buffer.print("防具: "); SetColor(14); buffer.print(fang_ju + "\n");
if(bao_ji_lv > 0) { SetColor(11); buffer.print("暴击: "); SetColor(12); buffer.print(to_string(bao_ji_lv) + "% "); } if(shan_bi_lv > 0) { SetColor(11); buffer.print("闪避: "); SetColor(12); buffer.print(to_string(shan_bi_lv) + "% "); } buffer.print("\n"); SetColor(7);92 行未改动 buffer.print("2. 修理装备 (需要金币20)\n"); buffer.print("3. 打造武器 (需要材料)\n"); buffer.print("4. 返回\n"); refresh();
char xuanze = getch(); if(xuanze == '4') return;
if(xuanze == '1' && haogan_du[1] >= 30) { if(ling_shi >= 50 && wu_qi != "无") { ling_shi -= 50; gong_ji += 5;32 行未改动 buffer.print("2. 炼制生命料理 (需要材料: 灵芝x1, 金币30)\n"); buffer.print("3. 购买草药 (金币10)\n"); buffer.print("4. 返回\n"); refresh();
char xuanze = getch(); if(xuanze == '4') return;
if(xuanze == '3') { if(jin_bi >= 10) { jin_bi -= 10; // 获得草药30 行未改动 buffer.print(to_string(i+1) + ". " + renwu[i].name + " (" + to_string(renwu[i].current_count) + "/" + to_string(renwu[i].target_count) + ")\n"); } } if(!you_renwu) buffer.print("暂无任务\n");
buffer.print("\n1. 接取任务\n"); buffer.print("2. 提交任务\n"); buffer.print("3. 返回\n"); refresh();
char xuanze = getch(); if(xuanze == '3') return;
if(xuanze == '1') { // 生成新任务 renwu[renwu_count].name = "消灭史莱姆"; renwu[renwu_count].desc = "消灭5只史莱姆";22 行未改动 buffer.print("2. 灵石兑换金币 (1:10)\n"); buffer.print("3. 随机传送 (需要灵石50)\n"); buffer.print("4. 返回\n"); refresh();
char xuanze = getch(); if(xuanze == '4') return;
if(xuanze == '1' && ling_shi >= 30) { ling_shi -= 30; int jiangli = rand()%100; refresh();41 行未改动 buffer.print("║ 你的金币: " + to_string(jin_bi) + "\n"); buffer.print("╠════════════════════════════════╣\n"); buffer.print("║ 你的背包:\n"); SetColor(7);
int wu_pin_bian_hao = 1; int wu_pin_wei_zhi[100][2]; int wu_pin_id_arr[100];
for(int i=0;i<=2;i++){ buffer.print("║ "); for(int j=0;j<=9;j++){ if(be_bao[i][j].name != "空") { if(be_bao[i][j].id >= 1 && be_bao[i][j].id <= 5) SetColor(12); else if(be_bao[i][j].id >= 6 && be_bao[i][j].id <= 10) SetColor(11); else if(be_bao[i][j].id >= 11 && be_bao[i][j].id <= 15) SetColor(10); else if(be_bao[i][j].id >= 16 && be_bao[i][j].id <= 20) SetColor(13);
char temp[20]; sprintf(temp, "[%2d]%-6s", wu_pin_bian_hao, be_bao[i][j].name.c_str()); buffer.print(temp); if(be_bao[i][j].count > 1) { SetColor(14); buffer.print("x" + to_string(be_bao[i][j].count)); } SetColor(7); buffer.print(" ");
wu_pin_wei_zhi[wu_pin_bian_hao][0] = i; wu_pin_wei_zhi[wu_pin_bian_hao][1] = j; wu_pin_id_arr[wu_pin_bian_hao] = be_bao[i][j].id; wu_pin_bian_hao++;3 行未改动 } } buffer.print("║\n"); }
SetColor(10); buffer.print("╠════════════════════════════════╣\n"); buffer.print("║ 输入物品编号出售 (输入0返回): "); SetColor(7); refresh();
int xuan_ze; cin >> xuan_ze;
if(xuan_ze == 0) return;
if(xuan_ze > 0 && xuan_ze < wu_pin_bian_hao) { int mai_x = wu_pin_wei_zhi[xuan_ze][0]; int mai_y = wu_pin_wei_zhi[xuan_ze][1]; int selected_id = wu_pin_id_arr[xuan_ze];
if(selected_id > 0 && selected_id <= 20) { SetColor(10); buffer.print("║ 确定要出售 " + be_bao[mai_x][mai_y].name + " 吗?\n"); buffer.print("║ 出售价格: " + to_string(mai_jia_ge[selected_id]) + " 金币\n"); buffer.print("║ 1.确认 2.取消: "); SetColor(7); refresh();
int que_ren; cin >> que_ren;
if(que_ren == 1) { jin_bi += mai_jia_ge[selected_id];
if(be_bao[mai_x][mai_y].name == wu_qi) { wu_qi = "无"; gong_ji = ji_chu_gong_ji; gong_su = ji_chu_gong_su; } if(be_bao[mai_x][mai_y].name == fang_ju) { fang_ju = "无"; fang_yu = ji_chu_fang_yu; }
for(int k=0;k<5;k++) { if(be_bao[mai_x][mai_y].name == te_shu_wu_pin[k]) { te_shu_wu_pin[k] = "无"; te_shu_wu_pin_bian_hao[k] = 0; if(selected_id == 9) shan_bi_lv -= 5; if(selected_id == 5) bao_ji_lv -= 10; } }
if(be_bao[mai_x][mai_y].count > 1) { be_bao[mai_x][mai_y].count--; } else { be_bao[mai_x][mai_y].name = "空"; be_bao[mai_x][mai_y].id = 0; be_bao[mai_x][mai_y].count = 0; }
haogan_du[0] += 1;
SetColor(10); buffer.print("║ 出售成功!获得 " + to_string(mai_jia_ge[selected_id]) + " 金币\n"); buffer.print("╚════════════════════════════════╝\n"); SetColor(7);20 行未改动 buffer.print("╔════════════ 购买系统 ════════════╗\n"); buffer.print("║ 金币:" + to_string(jin_bi) + " 灵石:" + to_string(ling_shi) + "\n"); buffer.print("╠════════════════════════════════╣\n"); SetColor(7);
for(int ye=0;ye<4;ye++) { SetColor(11); buffer.print("║ 第 " + to_string(ye+1) + " 页:\n"); SetColor(7);12 行未改动 buffer.print("╠════════════════════════════════╣\n"); SetColor(7); } }
SetColor(10); buffer.print("╠════════════════════════════════╣\n"); buffer.print("║ 输入数字购买 (输入0返回): "); SetColor(7); refresh();
int gou_mai_de; cin >> gou_mai_de;
if(gou_mai_de==0) return;
if(gou_mai_de<1 || gou_mai_de>20) { SetColor(12); buffer.print("║ 无效的选择!\n"); buffer.print("╚════════════════════════════════╝\n"); SetColor(7); refresh(); Sleep(500); continue; }
if(jin_bi < gou_mai_jia_ge[gou_mai_de]){ SetColor(12); buffer.print("║ 金币不够!\n"); buffer.print("╚════════════════════════════════╝\n");22 行未改动 } } if(f) break; }
if(f){ haogan_du[0] += 2; SetColor(10); buffer.print("║ 购买成功!\n");2 行未改动 refresh(); Sleep(500); } else { SetColor(12); buffer.print("║ 背包空间不够!\n"); buffer.print("║ 背包空间不够!\n"); buffer.print("╚════════════════════════════════╝\n"); SetColor(7); refresh(); Sleep(500);19 行未改动 ling_qi_zhi = 0; xiao_jing_jie_shu++; ji_chu_xie_liang += 2; ji_chu_gong_ji += 2;
refresh(); if(xiao_jing_jie_shu>5) { da_jing_jie_shu++; xiao_jing_jie_shu = 1;11 行未改动 buffer.print("╚════════════════════════════════╝\n"); } SetColor(7); refresh();
gong_ji = ji_chu_gong_ji; if(wu_qi == "钢剑") gong_ji += 5; else if(wu_qi == "铁剑") gong_ji += 8; else if(wu_qi == "秘银剑") gong_ji += 12; else if(wu_qi == "海拉鲁大剑") gong_ji += 20; else if(wu_qi == "霜之哀伤") gong_ji += 30;
xie_liang = ji_chu_xie_liang + e_wai_sheng_ming;
Sleep(1000); return;}
3 行未改动 while(1){ refresh(); zhuang_tai(); buffer.print("\n");
SetColor(10); buffer.print("╔════════════ 背包 ════════════╗\n"); SetColor(7);
for(int i=0;i<=2;i++){ buffer.print("║ "); for(int j=0;j<=9;j++){ if(be_bao[i][j].id >= 1 && be_bao[i][j].id <= 5) SetColor(12); else if(be_bao[i][j].id >= 6 && be_bao[i][j].id <= 10) SetColor(11); else if(be_bao[i][j].id >= 11 && be_bao[i][j].id <= 15) SetColor(10); else if(be_bao[i][j].id >= 16 && be_bao[i][j].id <= 20) SetColor(13); else SetColor(8);
if(be_bao_x==i && be_bao_y==j) { SetColorAndBackground(0, 15); char temp[10]; sprintf(temp, "%-8s", be_bao[i][j].name.c_str());16 行未改动 buffer.print(" "); } buffer.print("║\n"); }
SetColor(10); buffer.print("╠════════════════════════════╣\n"); buffer.print("║ 当前选中: "); SetColor(7);2 行未改动 } else { buffer.print("空"); } buffer.print("\n");
SetColor(10); buffer.print("║ 操作: W↑ A← S↓ D→ 移动\n"); buffer.print("║ Q装备 R使用 E退出\n"); buffer.print("╚════════════════════════════╝\n"); SetColor(7); refresh();
char be_bao_yi_dong = getch();
if(be_bao_yi_dong=='e' || be_bao_yi_dong=='E') return; if((be_bao_yi_dong=='w' || be_bao_yi_dong=='W') && be_bao_x-1>=0) be_bao_x--; else if((be_bao_yi_dong=='s' || be_bao_yi_dong=='S') && be_bao_x+1<3) be_bao_x++; else if((be_bao_yi_dong=='a' || be_bao_yi_dong=='A') && be_bao_y-1>=0) be_bao_y--; else if((be_bao_yi_dong=='d' || be_bao_yi_dong=='D') && be_bao_y+1<10) be_bao_y++;
if(be_bao_yi_dong=='q' || be_bao_yi_dong=='Q') { int id = be_bao[be_bao_x][be_bao_y].id; string name = be_bao[be_bao_x][be_bao_y].name;
if(id >= 1 && id <= 5) { if(wu_qi != "无") { for(int i=0;i<3;i++) { for(int j=0;j<10;j++) {14 行未改动 wu_qi = name; be_bao[be_bao_x][be_bao_y].name = "空"; be_bao[be_bao_x][be_bao_y].id = 0; be_bao[be_bao_x][be_bao_y].count = 0;
gong_su = ji_chu_gong_su; gong_ji = ji_chu_gong_ji;
switch(id) { case 1: gong_su += 2; gong_ji += 5; break; case 2: gong_su += 1; gong_ji += 8; break; case 3: gong_su += 2; gong_ji += 12; break; case 4: gong_su -= 0.4; gong_ji += 20; break; case 5: gong_su -= 0.2; gong_ji += 30; bao_ji_lv += 10; break; } }
if(id >= 6 && id <= 10) { if(fang_ju != "无") { for(int i=0;i<3;i++) { for(int j=0;j<10;j++) {14 行未改动 fang_ju = name; be_bao[be_bao_x][be_bao_y].name = "空"; be_bao[be_bao_x][be_bao_y].id = 0; be_bao[be_bao_x][be_bao_y].count = 0;
fang_yu = ji_chu_fang_yu; switch(id) { case 6: fang_yu += 3; break; case 7: fang_yu += 6; break; case 8: fang_yu += 10; break; case 9: fang_yu += 15; shan_bi_lv += 5; break; case 10: fang_yu += 20; break; } }
if(id >= 16 && id <= 20) { for(int k=0;k<5;k++) { if(te_shu_wu_pin[k] == "无") { te_shu_wu_pin[k] = name;5 行未改动 } } } }
if(be_bao_yi_dong=='r' || be_bao_yi_dong=='R') { int id = be_bao[be_bao_x][be_bao_y].id;
if(id >= 11 && id <= 15) { if(be_bao[be_bao_x][be_bao_y].count > 1) { be_bao[be_bao_x][be_bao_y].count--; } else { be_bao[be_bao_x][be_bao_y].name = "空"; be_bao[be_bao_x][be_bao_y].id = 0; be_bao[be_bao_x][be_bao_y].count = 0; }
refresh(); switch(id) { case 11: xie_liang += 5;11 行未改动 } refresh(); Sleep(300); }
if(id >= 16 && id <= 19) { if(be_bao[be_bao_x][be_bao_y].count > 1) { be_bao[be_bao_x][be_bao_y].count--; } else { be_bao[be_bao_x][be_bao_y].name = "空"; be_bao[be_bao_x][be_bao_y].id = 0; be_bao[be_bao_x][be_bao_y].count = 0; }
refresh(); switch(id) { case 16: ji_chu_gong_su += 0.5;19 行未改动 refresh(); Sleep(300); } }
int suo_xu_ling_qi = ti_sheng_ling_qi[da_jing_jie_shu] + (xiao_jing_jie_shu-1)*20; if(ling_qi_zhi >= suo_xu_ling_qi) { tu_po(); }5 行未改动 zai_zhan_dou = true; dang_qian_guai_wu = guai_wu_index; guai_wu_xie_liang = guai_wu[guai_wu_index].xie_ling; guai_wu_gong_ji = guai_wu[guai_wu_index].gong_ji;
while(zai_zhan_dou) { refresh();
SetColor(12); buffer.print("╔════════════ 战斗 ════════════╗\n"); SetColor(11); buffer.print("║ 玩家血量: "); SetColor(7); buffer.print(to_string(xie_liang) + "/" + to_string(ji_chu_xie_liang + e_wai_sheng_ming) + "\n");6 行未改动 buffer.print("║ 按空格键攻击 ESC逃跑\n"); buffer.print("╚════════════════════════════╝\n"); SetColor(7); refresh();
if(_kbhit()) { char key = getch(); if(key == 32) { int shang_hai = gong_ji - fang_yu; if(shang_hai < 1) shang_hai = 1;
if(rand()%100 < bao_ji_lv) { shang_hai *= 2; SetColor(12); buffer.print("║ 暴击!\n"); SetColor(7); }
guai_wu_xie_liang -= shang_hai; buffer.print("║ 你对怪物造成了 " + to_string(shang_hai) + " 点伤害!\n");
if(guai_wu_xie_liang <= 0) { SetColor(10); buffer.print("║ 怪物被打败了!\n"); buffer.print("║ 获得灵石 +5,金币 +20\n"); SetColor(7); ling_shi += 5; jin_bi += 20;
int diao_luo_lv = 30; for(int k=0;k<5;k++) { if(te_shu_wu_pin_bian_hao[k] == 20) diao_luo_lv += 20; }
int diao_luo = rand()%100; if(diao_luo < diao_luo_lv) { buffer.print("║ 怪物掉落了物品!\n"); int wu_pin = rand()%5;9 行未改动 } } } }
guai_wu[guai_wu_index].alive = false; mao_xian_dt[guai_wu[guai_wu_index].x][guai_wu[guai_wu_index].y] = ' ';
zai_zhan_dou = false; refresh(); Sleep(1000); break; }
if(rand()%100 >= shan_bi_lv) { int monster_shang_hai = guai_wu_gong_ji; if(monster_shang_hai < 1) monster_shang_hai = 1; xie_liang -= monster_shang_hai;2 行未改动 SetColor(11); buffer.print("║ 你闪避了怪物的攻击!\n"); SetColor(7); }
if(xie_liang <= 0) { SetColor(12); buffer.print("║ 你被打败了...游戏结束\n"); buffer.print("╚════════════════════════════╝\n"); SetColor(7); refresh(); system("pause"); exit(0); }
refresh(); Sleep(500); } else if(key == 27) {6 行未改动 Sleep(500); break; } }
Sleep(100); }
zai_zhan_dou = false; dang_qian_guai_wu = -1;}
3 行未改动 int mx=1,my=1; int mxuan_zhong_x=2,mxuan_zhong_y=1; fang_xiang = 4; int guai_wu_shu=0;
for(int i=0;i<10;i++) { guai_wu[i].alive = false; }
for(int i=0;i<10;i++){ for(int j=0;j<10;j++){ if(i==1 && j==1) continue; if(i==0 || j==0 || i==9 || j==9){ mao_xian_dt[i][j] = '*'; continue; } } int sheng_cheng = rand()%5; if(sheng_cheng==0){ mao_xian_dt[i][j] = ' '; }14 行未改动 } } } mao_xian_dt[1][1]='r';
while(1){ refresh(); zhuang_tai(); buffer.print("\n\n"); if(fang_xiang==1) mxuan_zhong_x=mx,mxuan_zhong_y=my-1; if(fang_xiang==2) mxuan_zhong_y=my,mxuan_zhong_x=mx-1; if(fang_xiang==3) mxuan_zhong_x=mx,mxuan_zhong_y=my+1; if(fang_xiang==4) mxuan_zhong_y=my,mxuan_zhong_x=mx+1;
for(int i=0;i<10;i++){ for(int j=0;j<10;j++){ if(mxuan_zhong_x==i && mxuan_zhong_y==j) SetColorAndBackground(15,4); buffer.print(mao_xian_dt[i][j]);2 行未改动 } buffer.print("\n"); } refresh();
char yi_dong; if(_kbhit() != 0){ yi_dong = getch(); int nx = mx,ny = my; if(yi_dong=='i') return; if(yi_dong==72) fang_xiang=2; else if(yi_dong==75) fang_xiang=1; else if(yi_dong==77) fang_xiang=3; else if(yi_dong==80) fang_xiang=4; else if(yi_dong==80) fang_xiang=4; else if(yi_dong=='w' && mx-1>=0 && (mao_xian_dt[mx-1][my]==' ' || mao_xian_dt[mx-1][my]=='&')) nx--; else if(yi_dong=='s' && mx+1<10 && (mao_xian_dt[mx+1][my]==' ' || mao_xian_dt[mx+1][my]=='&')) nx++; else if(yi_dong=='a' && my-1>=0 && (mao_xian_dt[mx][my-1]==' ' || mao_xian_dt[mx][my-1]=='&')) ny--; else if(yi_dong=='d' && my+1<10 && (mao_xian_dt[mx][my+1]==' ' || mao_xian_dt[mx][my+1]=='&')) ny++;2 行未改动 if(fang_xiang==1) gong_ji_y--; else if(fang_xiang==2) gong_ji_x--; else if(fang_xiang==3) gong_ji_y++; else if(fang_xiang==4) gong_ji_x++;
if(mao_xian_dt[gong_ji_x][gong_ji_y] == 'B') { for(int i=0;i<6;i++) { if(guai_wu[i].alive && guai_wu[i].x == gong_ji_x && guai_wu[i].y == gong_ji_y) { zhan_dou(i);5 行未改动 else if(yi_dong=='e') { da_kai_be_bao(); system("cls"); }
if(mao_xian_dt[nx][ny] == '&') { SetColor(14); buffer.print("╔════════════════════════════╗\n"); buffer.print("║ 你打开了一个宝箱!\n"); int jiang_li = rand()%6; if(jiang_li == 0) { ling_shi += 10; buffer.print("║ 获得灵石 +10\n"); } else if(jiang_li == 1) { jin_bi += 30; buffer.print("║ 获得金币 +30\n"); } else if(jiang_li == 2) { for(int bi=0;bi<3;bi++) for(int bj=0;bj<10;bj++) else if(jiang_li == 2) { for(int bi=0;bi<3;bi++) for(int bj=0;bj<10;bj++) if(be_bao[bi][bj].name == "空") { be_bao[bi][bj].name = "一阶灵晶"; be_bao[bi][bj].id = 13; be_bao[bi][bj].count = 1; break; } buffer.print("║ 获得一阶灵晶\n"); } else if(jiang_li == 3) { for(int bi=0;bi<3;bi++) for(int bj=0;bj<10;bj++) for(int bi=0;bi<3;bi++) for(int bj=0;bj<10;bj++) if(be_bao[bi][bj].name == "空") { be_bao[bi][bj].name = "金苹果"; be_bao[bi][bj].id = 11; be_bao[bi][bj].count = 1; break; } buffer.print("║ 获得金苹果\n"); } else if(jiang_li == 4) { for(int bi=0;bi<3;bi++) for(int bj=0;bj<10;bj++) for(int bi=0;bi<3;bi++) for(int bj=0;bj<10;bj++) if(be_bao[bi][bj].name == "空") { be_bao[bi][bj].name = "速度药水"; be_bao[bi][bj].id = 16; be_bao[bi][bj].count = 1; break; } buffer.print("║ 获得速度药水\n"); } else { for(int bi=0;bi<3;bi++) for(int bj=0;bj<10;bj++) for(int bi=0;bi<3;bi++) for(int bj=0;bj<10;bj++) if(be_bao[bi][bj].name == "空") { be_bao[bi][bj].name = "铁剑"; be_bao[bi][bj].id = 2; be_bao[bi][bj].count = 1; break; } buffer.print("║ 获得铁剑\n"); } buffer.print("╚════════════════════════════╝\n"); SetColor(7); refresh(); Sleep(1000); }
mao_xian_dt[mx][my] = ' '; mao_xian_dt[nx][ny] = 'r'; mx=nx; my=ny; }8 行未改动 int nx = x,ny = y; if(yi_dong==72) fang_xiang=2; else if(yi_dong==75) fang_xiang=1; else if(yi_dong==77) fang_xiang=3; else if(yi_dong==80) fang_xiang=4; else if(yi_dong==80) fang_xiang=4; else if((yi_dong=='w' || yi_dong=='W') && x-1>=0 && ditu[x-1][y]==' ') nx--; else if((yi_dong=='s' || yi_dong=='S') && x+1<10 && ditu[x+1][y]==' ') nx++; else if((yi_dong=='a' || yi_dong=='A') && y-1>=0 && ditu[x][y-1]==' ') ny--; else if((yi_dong=='d' || yi_dong=='D') && y+1<10 && ditu[x][y+1]==' ') ny++;13 行未改动 else if(yi_dong=='1' && ditu[xuan_zhong_x][xuan_zhong_y]=='d') mao_xian(); else if(yi_dong=='i' || yi_dong=='I') { da_kai_be_bao(); }
ditu[x][y] = ' '; ditu[nx][ny] = 'r'; x=nx; y=ny; }} }
void SetPos(int x,int y){ COORD coord = {(SHORT)y, (SHORT)x}; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);}
int main(){ srand(time(0)); initBeibao();
// 隐藏光标 CONSOLE_CURSOR_INFO cursorInfo; GetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursorInfo); cursorInfo.bVisible = false; SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursorInfo);
cout << "这里是一个修仙的世界,大家都过着幸福的生活,可是有一天,灾厄天降..." << endl; Sleep(200); cout << "你需要收集资源,调查这片大陆的秘密,兴许可以拯救它..." << endl; Sleep(200);16 行未改动 cout << "空格键攻击\n"; Sleep(200); cout << "I键打开背包\n"; Sleep(200); cout << "靠近NPC时按Q键互动\n"; cout << "靠近NPC时按Q键互动\n"; Sleep(200); cout << "地图符号说明:\n"; cout << "r 你 A商人 T铁匠 F药师 C村长 G神秘人\n"; cout << "B敌人 &宝箱 d冒险入口 *墙壁\n"; cout << "按任意键继续..."; getch(); } system("cls");
while(true){ refresh(); zhuang_tai(); buffer.print("\n\n");
if(fang_xiang==1) xuan_zhong_x=x,xuan_zhong_y=y-1; if(fang_xiang==2) xuan_zhong_y=y,xuan_zhong_x=x-1; if(fang_xiang==3) xuan_zhong_x=x,xuan_zhong_y=y+1; if(fang_xiang==4) xuan_zhong_y=y,xuan_zhong_x=x+1;
// 显示地图 for(int i=0;i<10;i++){ for(int j=0;j<10;j++){ // 根据不同NPC显示不同颜色4 行未改动 else if(ditu[i][j] == 'G') SetColor(13); // 神秘人紫色 else if(ditu[i][j] == 'd') SetColor(9); // 冒险入口蓝色 else if(ditu[i][j] == '*') SetColor(8); // 墙壁灰色 else SetColor(7); // 默认白色
if(xuan_zhong_x==i && xuan_zhong_y==j) { SetColorAndBackground(0, 15); buffer.print(ditu[i][j]); buffer.print(" ");5 行未改动 } buffer.print("\n"); } SetColor(7);
// 显示当前选中格子的信息 if(ditu[xuan_zhong_x][xuan_zhong_y] != ' ' && ditu[xuan_zhong_x][xuan_zhong_y] != '*') { buffer.print("\n当前选中: "); switch(ditu[xuan_zhong_x][xuan_zhong_y]) {5 行未改动 case 'd': buffer.print("冒险入口 (按1进入)"); break; } buffer.print("\n"); }
refresh();
jp();
int suo_xu_ling_qi = ti_sheng_ling_qi[da_jing_jie_shu] + (xiao_jing_jie_shu-1)*20; if(ling_qi_zhi >= suo_xu_ling_qi) { tu_po(); }5 行未改动