版本比较
小游戏
正文
增加 604 行删除 552 行
112345637895678910111213141516171819202122232425262728293031101112131415161718192021222324252627282930313334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091323334939435363738396 行未改动46474849505152535455565758593 行未改动63646566120676869707119 行未改动91929394951489697989910016 行未改动1171181191201731211221231241256 行未改动1321331341351881361371381391401411421431441451461471481491501511521531541551561571581591601611621951631641651981661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352012022362372382392052402412422082432442452102462472482122492502512522142532542162172182192552562572212582592602612622632642652662672682692702712722732742752762772782792802812822832282842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233242333253262352362373273283292393303313323332432442453343353363373383392472483403413423433443453463473482542552563493503513523532582592603543553563573583593603612652662673623633643653663673683692723703713723733743753763773783793803813823833842743853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864872804884894902832842852862872882892902914914924934944954964974983003013023033043053063073083093103113123133143153163173184995005015025035045055065075085095105115125135145155165175185195205217 行未改动5295305315323345335345355365374 行未改动54254354454534754654754854955055135355255355455555655755855956056156236336436556356456556636736836937037137237337437556756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561637737837938038138261761838561962038738838939039139239339439539639739839940040140240340440562162262362462562662762862963063163263363463563663740763863964064164264364464564664764864965065165265340941041141241341441541641741841942065442265565665765865966066166266366466566666766866967043043167167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772844372973073173273373473573645173773845345473974074174274345874474546074674774874975075146646746875275375475575675775834 行未改动7937947957965117977987998008018028038045198058068078088093 行未改动813814815816531532817818819820821535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630822823824632633825826827636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715828829830831832833834835836837838839840841842843844845846847848718849850851721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757852853854855856857858759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789859860861862863864791792793794795865797798799800801802803804805806807808809810811812866867868869870871872814815816817818819820873874875876877878879880881882883884885823824825826827828829830831832833834835836837838839840841842843886887888845889890891847848849850851852853854855856857858859860892893894895896897898899900901902903864865866867868869870871872873874875904905906907908909910911912913914915916917918919920921922923924925926927928```## 0.1.5.a版### 代码注:请在同一个文件夹内创建下面几个文件,保证文件名字正确#### game.cpp```cpp#include <bits/stdc++.h>using namespace std;#include "tool.cpp"#include "enemy.cpp"
class enemy{public:
struct enemykind { string name; int bl_v; int enemy_at_powwer; }; enemykind kind[1000]={{" natural",500,100}, {}, };
int Enemy_Unit_Combination[10][10000]={{1,1,1,1,1}};
int e[100],at_powwer[100]; string enemy_name[100]; void emy(int en_co)//敌方初始化 { for(int i=1;i<=5;i++) { enemy_name[i]=kind[Enemy_Unit_Combination[i][en_co-1]].name; e[i]=kind[Enemy_Unit_Combination[i][en_co-1]].bl_v; at_powwer[i]=kind[Enemy_Unit_Combination[i][en_co-1]].enemy_at_powwer; }using namespace std;#ifdef _WIN32#define CLEAR_SCREEN system("cls")#define GETCH _getch()#include <conio.h>#include <windows.h>#else #define CLEAR_SCREEN system("clear") #include <termios.h> #include <unistd.h> // Linux/Mac 无回显读取 char getch_char() { struct termios oldt, newt; char ch; tcgetattr(STDIN_FILENO, &oldt); newt = oldt; newt.c_lflag &= ~(ICANON | ECHO); tcsetattr(STDIN_FILENO, TCSANOW, &newt); ch = getchar(); tcsetattr(STDIN_FILENO, TCSANOW, &oldt); return ch; } void print()//显示敌方状态 { cout<<" 敌方状态 "<<endl; cout<<" -----------------------------------------------------------------------"<<endl; cout<<" | | | | | |"<<endl; cout<<" 名字"; for(int i=1;i<=5;i++) { cout<<"|"; if(e[i]==0) { printf(" "); continue; } cout<<enemy_name[i]; //printf("%13s",enemy_name[i]); } cout<<"|"<<endl; cout<<"生命值"; for(int i=1;i<=5;i++) { cout<<"|"; if(e[i]==0) { //string s="消亡"; cout<<" 消亡"; continue; } printf("%13d",e[i]); } cout<<"|"<<endl; cout<<"攻击力"; for(int i=1;i<=5;i++) { cout<<"|"; if(e[i]==0) { printf(" "); continue; } printf("%13d",at_powwer[i]); } cout<<"|"<<endl; cout<<" 位置| 1 | 2 | 3 | 4 | 5 |"<<endl; cout<<" -----------------------------------------------------------------------"<<endl; } int ifkia()//全灭判断 { for(int i=0;i<10;i++) { if(e[i]) { return 0; } } return 1; }private:}; #define GETCH getch_char()#endif
enemy en_o;//敌人对象class The_lostclass The_lost//玩家{public:
int att_power=100;6 行未改动 The_lost() { att_power=100; lostnl=0; life=1500; name="lost"; recovery_state = false; recovery_turn = 0; damage_record = 0; rationality=0; } void lostaskill(int d,int *lostnl,int *e,int *rationality)//普攻 { *lostnl=*lostnl+20;3 行未改动 damage_record += damage; cout<<"【回复状态】记录普攻伤害:"<<damage<<" 累计:"<<damage_record<<endl; } *rationality+=1; if(e[d] <= 0) if(e[d] <= 0) { e[d] = 0; } }19 行未改动 { e[d] = 0; } }
void lostqskill(int *lostnl,int *e)//大招 void lostqskill(int *lostnl)//大招 { if(*lostnl>=qenergy) { *lostnl-=qenergy;16 行未改动 }
//每回合结束时调用,更新回复状态 void update_recovery_state() { if(recovery_state) if(recovery_state) { int damage_record_per=0.5; recovery_turn--; cout<<"【回复状态】剩余回合:"<<recovery_turn<<endl;6 行未改动 if(recovery_turn==0) { recovery_state = false; damage_record = 0; } } } }private: int qenergy=180;//e技能能量、q技能能量};
string screen_stirp[20]={"==============================================================",//0 //界面显示条,长最长60+2字符 "| |",//1 "| wating. |",//2 "| wating.. |",//3 "| wating... |",//4 "| "," |",//小型区(10+1) // 5 6 " "};//mini款 // 7
The_lost lost;int bag[100000];string storage_breakdown[100000]={ "金币", "升级书"};
string spoil[100000]={"50.5"};
class operateclass operate//操作类{public: int generate()//生成敌方
string operate_log[10000];
int start_fight() { while(1) { int copy_o=0; cout<<"=============================================================="<<endl; cout<<"| 选择关卡 |"<<endl; cout<<"| ----- |"<<endl; cout<<"| | 1 | |"<<endl; cout<<"| ----- |"<<endl; cout<<"| 按q退出 |"<<endl; cout<<"=============================================================="<<endl; string a; a=GETCH; if(a=="q") { break; } while(1) { CLEAR_SCREEN; cout<<"选择第"<<a<<"关"<<endl; cout<<"按s开始 按c查看详情 按k修改行为复制是否开启,当前:"; if(copy_o) { cout<<"■"<<endl; } else { cout<<"□"<<endl; } cout<<"按q退出"<<endl; string o; o=GETCH; if(o=="s") { select(stoi(a)); } else if(o=="c") { CLEAR_SCREEN; cout << "关卡" << a << "详情:" << endl;
cout << "按任意键返回" << endl; GETCH; CLEAR_SCREEN; } else if(o=="k") { copy_o = !copy_o; CLEAR_SCREEN; } else if(o=="q") { break; } }
}
}
int generate(int level)//生成敌方 { cout<<"战斗开始"<<endl; en_o.emy(1); en_o.print(); enemy.emy(level); enemy.print(); return 0; } The_lost lost; queue <string>actionqueue;//行动队列 queue <int>numberqueue;//编号队列 //行动队列中的单位会轮换行动 int select(int rs)//选择角色 int select(int number_of_level)//选择关卡 { generate(number_of_level); for(int i=0;i<5;i++) for(int i=1;i<=1;i++) { string rolename="lost"; actionqueue.push("monster"); actionqueue.push(rolename); numberqueue.push(i); }
for(int i=0;i<rs;i++) for(int i=1;i<=5;i++) { string rolename; cout<<"踏上前来,你是:(me)"<<endl; cin>>rolename; actionqueue.push(rolename); actionqueue.push(enemy.enemy_name[i]); numberqueue.push(i); } while (!en_o.ifkia())//回合轮换
int if_vitcter=0; while (1)//回合轮换 { // int o; //cin>>o;//--------------------------------------------------------------------------------------------------------------------------------------------------------- string ppp=actionqueue.front(); int a=numberqueue.front(); move(ppp); actionqueue.pop(); numberqueue.pop(); actionqueue.push(ppp); numberqueue.push(a); if(enemy.ifkia()) { if_vitcter=1; break; } else if(lost.life<=0) { if_vitcter=0; break; } } if(if_vitcter) { cout<<"战斗胜利"<<endl; cout<<"战斗胜利"<<endl; lost.att_power=100; lost.lostnl=0; lost.life=1500; lost.name="lost"; lost.recovery_state = false; lost.recovery_turn = 0; lost.damage_record = 0; lost.rationality=0; int give[1000]; string strgive[1000]; tool.char_dependent_segmentation(strgive,spoil[number_of_level-1],'.'); tool.str_to_int(give,strgive); cout<<"获得:"<<endl; for(int i=0;i<10;i++) { if(give[i]) { cout<<screen_stirp[7]<<storage_breakdown[i]<<":"<<give[i]<<endl; bag[i]+=give[i]; } } } else { cout<<"战斗失败"<<endl; lost.att_power=100; lost.lostnl=0; lost.life=1500; lost.name="lost"; lost.recovery_state = false; lost.recovery_turn = 0; lost.damage_record = 0; lost.rationality=0;
} return 0; } int move(string role) { if(role=="me")//迷途之人便是你 你的操作 if(role=="lost") { //cout<<"迷途之人"<<endl; cout<<" 选择操作 当前能量:"<<lost.lostnl<<" 理性点:"<<lost.rationality<<endl; cout<<"a e q"<<endl; cout<<" 选择操作 当前能量:"<<lost.lostnl<<" 理性点:"<<lost.rationality<<" 生命值:"<<lost.life<<endl; cout<<"a:普攻 e:技能 q:大招"<<endl; char operationoptions; cin>>operationoptions; operationoptions=GETCH; if(operationoptions=='a') { int d; en_o.print(); cout<<"请选择目标(1~5):"<<endl; cin>>d; CLEAR_SCREEN; enemy.print(); cout<<"发动普攻,请选择目标1~5:"<<endl; char d_char = GETCH; d = d_char - '0'; //d-=1; lost.lostaskill(d,&lost.lostnl,en_o.e,&lost.rationality); en_o.print(); lost.lostaskill(d,&lost.lostnl,enemy.e,&lost.rationality); CLEAR_SCREEN; enemy.print(); cout<<endl; } if(operationoptions=='e') { int d; CLEAR_SCREEN; en_o.print(); cout<<"请选择目标(1~5):"<<endl; cin>>d; enemy.print(); cout<<"发动技能,请选择目标(1~5):"<<endl; int d_char = GETCH; d = d_char - '0'; //d-=1; en_o.print(); lost.losteskill(d,&lost.lostnl,en_o.e,&lost.rationality); en_o.print(); enemy.print(); lost.losteskill(d,&lost.lostnl,enemy.e,&lost.rationality); CLEAR_SCREEN; enemy.print(); cout<<endl; } if(operationoptions=='q') { en_o.print(); lost.lostqskill(&lost.lostnl,en_o.e); en_o.print(); //enemy.print(); lost.lostqskill(&lost.lostnl); CLEAR_SCREEN; enemy.print(); cout<<endl; } lost.update_recovery_state(); } else if(role=="monster") else if(role==" natural"&&enemy.e[numberqueue.front()]>0) { Natural_Number natural_number; CLEAR_SCREEN; enemy.print(); unsigned int seed = chrono::system_clock::now().time_since_epoch().count(); mt19937 engine(seed); uniform_int_distribution<int> int_dist(1, 4); int random_int = int_dist(engine); cout<<"敌方"<<numberqueue.front()<<"号敌人,natural_number发动技能:"<<endl; if(180-lost.lostnl<10) { if(random_int>=2) { natural_number.attack_2(&lost.lostnl,numberqueue.front()); cout<<"pass"<<endl; cout<<"attack_2"<<endl; cout<<"抽取了玩家能量,玩家能量剩余:"<<lost.lostnl<<endl; } else { natural_number.attack_1(&lost.life,numberqueue.front()); cout<<"attack_1"<<endl; cout<<"攻击玩家,玩家生命剩余:"<<lost.life<<endl; } } else { if(random_int==1) { natural_number.attack_2(&lost.lostnl,numberqueue.front()); cout<<"attack_2"<<endl; cout<<"抽取了玩家能量,玩家能量剩余:"<<lost.lostnl<<endl; } else { natural_number.attack_1(&lost.life,numberqueue.front()); cout<<"attack_1"<<endl; cout<<"攻击玩家,玩家生命剩余:"<<lost.life<<endl; } } std::this_thread::sleep_for(std::chrono::milliseconds(1000)); CLEAR_SCREEN; enemy.print();
} return 0; }
//养成
int yangcheng2(string name) { cout<<screen_stirp[0]<<endl; cout<<"所选角色:"<<name<<endl; cout<<screen_stirp[5]<<"1. "<<screen_stirp[6]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[0]<<endl; }
int yangcheng1() { string nameye[10][10]={{"lost(1)"}}; // 显示角色 string name; int page=1; int max_page=2; while (1) { cout<<screen_stirp[0]<<endl; cout<<"|所有角色: |"<<endl; cout<<screen_stirp[5]<<"1."<<nameye[page-1][0]<<" "<<screen_stirp[6]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[0]<<endl; cout<<"输入角色序号1~9 z:上一页 x:下一页 q:退出"<<endl; name=GETCH; if(name=="z") { if(page==1) { page=max_page; } page--; } else if(name=="x") { if(page==max_page) { page=1; } page++; } else if(name=="q") { CLEAR_SCREEN; return 0; } else if(name>="1"&&name<="9") { yangcheng2(nameye[page-1][stoi(name)-1]); } } }
};
operate o;
class displayclass display//显示类{public: string screen_stirp[20]={"==============================================================",//0 //界面显示条,长最长60+2字符 "| |",//1 "| wating. |",//2 "| wating.. |",//3 "| wating... |",//4 "| "," |",//小型区(10+1) // 5 6 " "};//mini款 // 7//------------------------------------------------------------------------游戏开始显示 struct AnimationFrame { string text; string progress_bar; }; // 预定义动画帧 vector<AnimationFrame> loading_frames = { {screen_stirp[2], "□□□□□□□□□□□□□□□□□□□□"}, {screen_stirp[3], "■□□□□□□□□□□□□□□□□□□□"}, {screen_stirp[4], "■■□□□□□□□□□□□□□□□□□□"}, {screen_stirp[2], "■■■□□□□□□□□□□□□□□□□□"}, {screen_stirp[3], "■■■■□□□□□□□□□□□□□□□□"}, {screen_stirp[4], "■■■■■□□□□□□□□□□□□□□□"}, {screen_stirp[2], "■■■■■■□□□□□□□□□□□□□□"}, {screen_stirp[3], "■■■■■■■□□□□□□□□□□□□□"}, {screen_stirp[4], "■■■■■■■■□□□□□□□□□□□□"}, {screen_stirp[2], "■■■■■■■■■□□□□□□□□□□□"}, {screen_stirp[3], "■■■■■■■■■■□□□□□□□□□□"}, {screen_stirp[4], "■■■■■■■■■■■□□□□□□□□□"}, {screen_stirp[2], "■■■■■■■■■■■■□□□□□□□□"}, {screen_stirp[3], "■■■■■■■■■■■■■□□□□□□□"}, {screen_stirp[4], "■■■■■■■■■■■■■■□□□□□□"}, {screen_stirp[2], "■■■■■■■■■■■■■■■□□□□□"}, {screen_stirp[3], "■■■■■■■■■■■■■■■■□□□□"}, {screen_stirp[4], "■■■■■■■■■■■■■■■■■□□□"}, {screen_stirp[2], "■■■■■■■■■■■■■■■■■■□□"}, {screen_stirp[3], "■■■■■■■■■■■■■■■■■■■□"}, {screen_stirp[3], "■□□□□□□□□□□□□□□□□□□□"}, {screen_stirp[4], "■■□□□□□□□□□□□□□□□□□□"}, {screen_stirp[2], "■■■□□□□□□□□□□□□□□□□□"}, {screen_stirp[3], "■■■■□□□□□□□□□□□□□□□□"}, {screen_stirp[4], "■■■■■□□□□□□□□□□□□□□□"}, {screen_stirp[2], "■■■■■■□□□□□□□□□□□□□□"}, {screen_stirp[3], "■■■■■■■□□□□□□□□□□□□□"}, {screen_stirp[4], "■■■■■■■■□□□□□□□□□□□□"}, {screen_stirp[2], "■■■■■■■■■□□□□□□□□□□□"}, {screen_stirp[3], "■■■■■■■■■■□□□□□□□□□□"}, {screen_stirp[4], "■■■■■■■■■■■□□□□□□□□□"}, {screen_stirp[2], "■■■■■■■■■■■■□□□□□□□□"}, {screen_stirp[3], "■■■■■■■■■■■■■□□□□□□□"}, {screen_stirp[4], "■■■■■■■■■■■■■■□□□□□□"}, {screen_stirp[2], "■■■■■■■■■■■■■■■□□□□□"}, {screen_stirp[3], "■■■■■■■■■■■■■■■■□□□□"}, {screen_stirp[4], "■■■■■■■■■■■■■■■■■□□□"}, {screen_stirp[2], "■■■■■■■■■■■■■■■■■■□□"}, {screen_stirp[3], "■■■■■■■■■■■■■■■■■■■□"}, {screen_stirp[4], "■■■■■■■■■■■■■■■■■■■■"}
};7 行未改动 cout << frame.progress_bar; cout << screen_stirp[7] + screen_stirp[7] + screen_stirp[6] << endl; cout << screen_stirp[1] << endl << screen_stirp[0] << endl; }
int start_screen()//开始屏幕显示 { int a; cout<<screen_stirp[0]<<endl<<screen_stirp[1]<<endl;4 行未改动 cout<<"输入任意内容以开始游戏:"; cin>>a; cout<<endl; cout<<"欢迎来到“名为数学的游戏”游戏马上开始"<<endl;
// 播放加载动画 for (const auto& frame : loading_frames) { render_frame(frame); std::this_thread::sleep_for(std::chrono::milliseconds(300)); }
return 0; }//------------------------------------------------------------------------游戏开始显示//------------------------------------------------------------------------角色 or 战斗
int display_role() { string nameye[10][10]={{"lost(1)"}}; // 显示角色 string name; cout<<"请输入名称(me):"; cin>>name; if(name=="me") int page=1; int max_page=2; while (1) { cout<<"角色名称:"<<name<<endl; cout<<"角色技能:"<<endl; cout << screen_stirp[7] + "天赋:探索者 羁绊:独行者" << endl; cout << screen_stirp[7] + screen_stirp[7] + "天赋: 作为独行于此的你,步步为艰,你将探索此地,学习便是你最好的武器,(经过学习你将会获得新的一套技能)" << endl; cout << screen_stirp[7] + "形态:无知 初来乍到,你一无所知" << endl; cout << screen_stirp[7] + screen_stirp[7] + "普攻a: 回复一个理性点,对指定敌方单体造成80%攻击力的伤害,回复20能量" << endl; cout << screen_stirp[7] + screen_stirp[7] + "E技能e: 消耗一个理性点,对指定敌方单体造成200%攻击力的伤害,回复30能量" << endl; cout << screen_stirp[7] + screen_stirp[7] + "Q技能q: 消耗180能量,回复两个理性点,进入「回复」状态,持续三回合,此状态下记录角色造成的伤害,在状态中,每回合结束后将记录的伤害的50%转化为血量回复量" << endl;
cout<<screen_stirp[0]<<endl; cout<<"|所有角色: |"<<endl; cout<<screen_stirp[5]<<"1."<<nameye[page-1][0]<<" "<<screen_stirp[6]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[0]<<endl; cout<<"输入角色序号1~9 z:上一页 x:下一页 q:退出"<<endl; name=GETCH; if(name=="z") { if(page==1) { page=max_page; } page--; } else if(name=="x") { if(page==max_page) { page=1; } page++; } else if(name=="q") { CLEAR_SCREEN; return 0; } else if(nameye[page-1][stoi(name)-1]=="lost(1)") { CLEAR_SCREEN; cout<<"角色名称:"<<nameye[page-1][stoi(name)-1]<<endl; cout<<"角色技能:"<<endl; cout << screen_stirp[7] + "天赋:探索者 形态:1" << endl; cout << screen_stirp[7] + screen_stirp[7] + "天赋: 作为独行于此的你,步步为艰,你将探索此地,学习便是你最好的武器,(经过学习你将会获得新的一套技能)" << endl; cout << screen_stirp[7] + "形态:无知 初来乍到,你一无所知" << endl; cout << screen_stirp[7] + screen_stirp[7] + "普攻a: 回复一个理性点,对指定敌方单体造成80%攻击力的伤害,回复20能量" << endl; cout << screen_stirp[7] + screen_stirp[7] + "E技能e: 消耗一个理性点,对指定敌方单体造成200%攻击力的伤害,回复30能量" << endl; cout << screen_stirp[7] + screen_stirp[7] + "Q技能q: 消耗180能量,回复两个理性点,进入「回复」状态,持续三回合,此状态下记录角色造成的伤害,在状态中,每回合结束后将记录的伤害的50%转化为血量回复量" << endl; cout << "按任意键以返回" << endl; string returnq; returnq=GETCH; } CLEAR_SCREEN; } else { cout<<"(请勿重复进行无效输入,否则电脑堆栈将爆炸)木有欧"<<endl; display_role(); } return 0; }
int choose_look_or_fight() int choose() { cout<<screen_stirp[0]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<"| 输入“c”查看角色 |"<<endl; cout<<"| 输入“f”开始战斗 |"<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[0]<<endl; string a; // 清除输入缓冲区 cin.ignore(numeric_limits<streamsize>::max(),'\n'); cout<<"请输入:"; cin>>a; // 清除输入缓冲区 cin.ignore(numeric_limits<streamsize>::max(), '\n'); if(a=="c") while(1) { cout<<screen_stirp[0]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<"| 输入“c”查看角色 |"<<endl; cout<<"| 输入“f”开始战斗 |"<<endl; cout<<"| 输入“g”养成角色 |"<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[0]<<endl; string a; a=GETCH; if(a=="c") { CLEAR_SCREEN; display_role(); display_role(); } else if(a=="f") { o.select(1); } else if(a=="g") { CLEAR_SCREEN; o.yangcheng1(); } else { CLEAR_SCREEN; } } else if(a=="f") { operate fight; fight.generate(); fight.select(1);//只有一个角色 } else { cout<<"(请勿重复进行无效输入,否则电脑堆栈将爆炸)无效输入,请重新输入:"<<endl; choose_look_or_fight(); } return 0; }
};
int main(){
#ifdef _WIN32 SetConsoleOutputCP(65001); // Windows GBK SetConsoleCP(65001); #else setlocale(LC_ALL, ""); // Linux/Mac UTF-8 #endif
display screen; //screen.start_screen();//不知道为啥,把注释解了就会出事 cin.ignore(numeric_limits<streamsize>::max(),'\n'); screen.choose_look_or_fight(); screen.choose(); // operate fight; // fight.generate(); // fight.select(1);//只有一个角色 return 0;}```
#### tool.cpp```cpp#include <bits/stdc++.h>
using namespace std;
struct TOOL{ template<size_t N> void char_dependent_segmentation(string (&ans)[N],string in,char a)//依照a分割字符串in,存入ans { int w=0; for(char y:in) { if(y==a) { w++; } else { ans[w]+=y; } } }
template<size_t N> void str_to_int(int (&ans)[N],string in[N])//将字符串数组转换为int数组 { for(int i=0;i<n;i++) { if(in[i]=="") { ans[i]=0; continue; } ans[i]=stoi(in[i]); } }
}tool;```
#### enemy.cpp```cpp#include <bits/stdc++.h>#include "tool.cpp"
using namespace std;
class enemyclass Enemy // 敌人总基类{public:
struct enemykind { string name; int bl_v; int enemy_at_powwer; int enemy_at_power; }; enemykind kind[1000]={{" natural",500,100},
enemykind kind[1000]={{" natural",200,50}, {}, };
int Enemy_Unit_Combination[10][10000]={{1,1,1,1,1}}; int Enemy_Unit_Combination[10000][10]={{1,1,1,1,1}};
int e[100],at_powwer[100]; int e[100],at_power[100]; string enemy_name[100]; void emy(int en_co)//敌方初始化 { for(int i=1;i<=5;i++) { enemy_name[i]=kind[Enemy_Unit_Combination[i][en_co-1]].name; e[i]=kind[Enemy_Unit_Combination[i][en_co-1]].bl_v; at_powwer[i]=kind[Enemy_Unit_Combination[i][en_co-1]].enemy_at_powwer; enemy_name[i]=kind[Enemy_Unit_Combination[en_co-1][i-1]-1].name; e[i]=kind[Enemy_Unit_Combination[en_co-1][i-1]-1].bl_v; at_power[i]=kind[Enemy_Unit_Combination[en_co-1][i-1]-1].enemy_at_power; } } void print()//显示敌方状态 {34 行未改动 { printf(" "); continue; } printf("%13d",at_powwer[i]); printf("%13d",at_power[i]); } cout<<"|"<<endl; cout<<" 位置| 1 | 2 | 3 | 4 | 5 |"<<endl; cout<<" -----------------------------------------------------------------------"<<endl; } int ifkia()//全灭判断 { for(int i=0;i<10;i++) for(int i=1;i<=5;i++) { if(e[i]) { return 0;3 行未改动 }private:};
enemy en_o;//敌人对象class The_lostEnemy enemy;//敌人对象
class Ordinary_Enemy : public Enemy //普通敌人{public:
int att_power=100; int lostnl=0,life=1500; string name="the lost"; bool recovery_state = false; // 「回复」状态标记 int recovery_turn = 0; // 「回复」状态剩余回合 int damage_record = 0; // 「回复」状态下记录的伤害值 int rationality=0;//理性点,普攻后增加,消耗以发动e技能,理智点属于各个角色独有,不与其他角色共享 The_lost() { att_power=100; lostnl=0; } void lostaskill(int d,int *lostnl,int *e,int *rationality)//普攻 { *lostnl=*lostnl+20; int damage = 0.8 * att_power; e[d]-=damage; if(recovery_state) { damage_record += damage; cout<<"【回复状态】记录普攻伤害:"<<damage<<" 累计:"<<damage_record<<endl; } *rationality+=1; if(e[d] <= 0) { e[d] = 0; } } void losteskill(int d,int *lostnl,int *e,int *rationality)//e技能 { if(*rationality>0) { *rationality-=1; } else { cout<<"理性不足"<<endl; return; } int damage = 2 * att_power; e[d]-=damage; if(recovery_state) { damage_record += damage; cout<<"【回复状态】记录E技能伤害:"<<damage<<" 累计:"<<damage_record<<endl; } *lostnl+=30; if(e[d] <= 0) { e[d] = 0; } } void lostqskill(int *lostnl,int *e)//大招 { if(*lostnl>=qenergy) { *lostnl-=qenergy; } else { cout<<"能量不足"<<endl; return; }
// 大招核心逻辑:回复2个理性点,进入回复状态(持续2回合),重置伤害记录 rationality += 2; recovery_state = true; recovery_turn = 3+1; damage_record = 0; cout<<"【Q技能生效】回复2个理性点(当前:"<<rationality<<"),进入「回复」状态,持续3回合!"<<endl;
// 回复状态结束处理(如果是状态到期)- 此处由回合逻辑触发,这里仅初始化状态 *lostnl+=30; }
//每回合结束时调用,更新回复状态 void update_recovery_state() { if(recovery_state) { int damage_record_per=0.5; recovery_turn--; cout<<"【回复状态】剩余回合:"<<recovery_turn<<endl; int heal = damage_record * damage_record_per; damage_record*=damage_record_per; life += heal; // 生命值不超过上限 if(life > 1500) life = 1500; cout<<"【回复状态】累计造成伤害:"<<damage_record<<",转化"<<heal<<"点记录值(当前:"<<life<<")"<<endl; if(recovery_turn==0) { recovery_state = false; damage_record = 0; } } }private: int qenergy=180;//e技能能量、q技能能量 virtual void attack_1(int* player_data,int bianhao) = 0;//第一种普攻 virtual void attack_2(int* player_data,int bianhao) = 0;//第二种普攻};
class operateclass Elite_Enemy : public Enemy //精英敌人{public: int generate()//生成敌方 { cout<<"战斗开始"<<endl; en_o.emy(1); en_o.print(); return 0; } The_lost lost; queue <string>actionqueue;//行动队列 //行动队列中的单位会轮换行动 int select(int rs)//选择角色 { for(int i=0;i<5;i++) { actionqueue.push("monster"); } for(int i=0;i<rs;i++) { string rolename; cout<<"踏上前来,你是:(me)"<<endl; cin>>rolename; actionqueue.push(rolename); } while (!en_o.ifkia())//回合轮换 { string ppp=actionqueue.front(); move(ppp); actionqueue.pop(); actionqueue.push(ppp); } cout<<"战斗胜利"<<endl; return 0; } int move(string role) { if(role=="me")//迷途之人便是你 你的操作 { //cout<<"迷途之人"<<endl; cout<<" 选择操作 当前能量:"<<lost.lostnl<<" 理性点:"<<lost.rationality<<endl; cout<<"a e q"<<endl; char operationoptions; cin>>operationoptions; if(operationoptions=='a') { int d; en_o.print(); cout<<"请选择目标(1~5):"<<endl; cin>>d; //d-=1; lost.lostaskill(d,&lost.lostnl,en_o.e,&lost.rationality); en_o.print(); cout<<endl; } if(operationoptions=='e') { int d; en_o.print(); cout<<"请选择目标(1~5):"<<endl; cin>>d; //d-=1; en_o.print(); lost.losteskill(d,&lost.lostnl,en_o.e,&lost.rationality); en_o.print(); cout<<endl; } if(operationoptions=='q') { en_o.print(); lost.lostqskill(&lost.lostnl,en_o.e); en_o.print(); cout<<endl; } lost.update_recovery_state(); } else if(role=="monster") { cout<<"pass"<<endl; } return 0; } virtual void attack_1(int* player_life) = 0;//第一种普攻 virtual void attack_2(int* player_life) = 0;//第二种普攻 virtual void eattack(int* player_life) = 0;//e技能 virtual void generate() = 0;//召唤 virtual void qattacking(int* player_life) = 0;//大招蓄力 virtual void qattack(int* player_life) = 0;//大招};class Boss : public Enemy //boss or boss的一个形态{public: virtual void attack_1(int* player_life) = 0;//第一种普攻 virtual void attack_2(int* player_life) = 0;//第二种普攻 virtual void eattack_1(int* player_life) = 0;//第一种e技能 virtual void eattack_2(int* player_life) = 0;//第二种e技能 virtual void eattack_3(int* player_life) = 0;//第三种e技能 virtual void strenger(int* player_life) = 0;//强化 virtual void generate() = 0;//召唤 virtual void qattacking(int* player_life) = 0;//大招蓄力 virtual void qattack(int* player_life) = 0;//大招};
class displayclass Natural_Number : public Ordinary_Enemy{public: string screen_stirp[20]={"==============================================================",//0 //界面显示条,长最长60+2字符 "| |",//1 "| wating. |",//2 "| wating.. |",//3 "| wating... |",//4 "| "," |",//小型区(10+1) // 5 6 " "};//mini款 // 7//------------------------------------------------------------------------游戏开始显示 struct AnimationFrame { string text; string progress_bar; }; // 预定义动画帧 vector<AnimationFrame> loading_frames = { {screen_stirp[2], "□□□□□□□□□□□□□□□□□□□□"}, {screen_stirp[3], "■□□□□□□□□□□□□□□□□□□□"}, {screen_stirp[4], "■■□□□□□□□□□□□□□□□□□□"}, {screen_stirp[2], "■■■□□□□□□□□□□□□□□□□□"}, {screen_stirp[3], "■■■■□□□□□□□□□□□□□□□□"}, {screen_stirp[4], "■■■■■□□□□□□□□□□□□□□□"}, {screen_stirp[2], "■■■■■■□□□□□□□□□□□□□□"}, {screen_stirp[3], "■■■■■■■□□□□□□□□□□□□□"}, {screen_stirp[4], "■■■■■■■■□□□□□□□□□□□□"}, {screen_stirp[2], "■■■■■■■■■□□□□□□□□□□□"}, {screen_stirp[3], "■■■■■■■■■■□□□□□□□□□□"}, {screen_stirp[4], "■■■■■■■■■■■□□□□□□□□□"}, {screen_stirp[2], "■■■■■■■■■■■■□□□□□□□□"}, {screen_stirp[3], "■■■■■■■■■■■■■□□□□□□□"}, {screen_stirp[4], "■■■■■■■■■■■■■■□□□□□□"}, {screen_stirp[2], "■■■■■■■■■■■■■■■□□□□□"}, {screen_stirp[3], "■■■■■■■■■■■■■■■■□□□□"}, {screen_stirp[4], "■■■■■■■■■■■■■■■■■□□□"}, {screen_stirp[2], "■■■■■■■■■■■■■■■■■■□□"}, {screen_stirp[3], "■■■■■■■■■■■■■■■■■■■□"}, {screen_stirp[4], "■■■■■■■■■■■■■■■■■■■■"} void attack_1(int* player_data,int bianhao) override {//从玩家血量中选择最大的两个数,拼和成一个百分数,此次攻击所造成的的伤害为攻击力与这个百分数乘算的结果 int p_l = *player_data; // 步骤1:提取玩家血量的每一位数字 int every_b_l[5] = {0}; int digit_count = 0; // 记录实际提取的数字位数 int temp = p_l;
}; // 渲染单个帧的通用方法 void render_frame(const AnimationFrame& frame) { cout << screen_stirp[0] << endl << screen_stirp[1] << endl; cout << screen_stirp[1] << endl << screen_stirp[1] << endl; cout << screen_stirp[1] << endl << screen_stirp[1] << endl; cout <<frame.text << endl; cout << screen_stirp[5] + screen_stirp[7] + screen_stirp[7]; cout << frame.progress_bar; cout << screen_stirp[7] + screen_stirp[7] + screen_stirp[6] << endl; cout << screen_stirp[1] << endl << screen_stirp[0] << endl; } int start_screen()//开始屏幕显示 { int a; cout<<screen_stirp[0]<<endl<<screen_stirp[1]<<endl; cout<<screen_stirp[5]<<"-- --"<<screen_stirp[6]<<endl; cout<<screen_stirp[5]<<"( 名为数学的游戏 )"<<screen_stirp[6]<<endl; cout<<screen_stirp[5]<<"-- --"<<screen_stirp[6]<<endl<<screen_stirp[1]<<endl; cout<<screen_stirp[5]<<" (输入任意内容以开始游戏) "<<screen_stirp[6]<<endl<<screen_stirp[1]<<endl<<screen_stirp[1]<<endl<<screen_stirp[0]<<endl; cout<<"输入任意内容以开始游戏:"; cin>>a; cout<<endl; cout<<"欢迎来到“名为数学的游戏”游戏马上开始"<<endl; // 播放加载动画 for (const auto& frame : loading_frames) { render_frame(frame); std::this_thread::sleep_for(std::chrono::milliseconds(300)); // 分解玩家血量的每一位数字 while (temp > 0 && digit_count < 5) { every_b_l[digit_count++] = temp % 10; // 取个位数字 temp = temp / 10; // 去掉个位 } return 0; }//------------------------------------------------------------------------游戏开始显示//------------------------------------------------------------------------角色 or 战斗
int display_role() { // 显示角色 string name; cout<<"请输入名称(me):"; cin>>name; if(name=="me") { cout<<"角色名称:"<<name<<endl; cout<<"角色技能:"<<endl; cout << screen_stirp[7] + "天赋:探索者 羁绊:独行者" << endl; cout << screen_stirp[7] + screen_stirp[7] + "天赋: 作为独行于此的你,步步为艰,你将探索此地,学习便是你最好的武器,(经过学习你将会获得新的一套技能)" << endl; cout << screen_stirp[7] + "形态:无知 初来乍到,你一无所知" << endl; cout << screen_stirp[7] + screen_stirp[7] + "普攻a: 回复一个理性点,对指定敌方单体造成80%攻击力的伤害,回复20能量" << endl; cout << screen_stirp[7] + screen_stirp[7] + "E技能e: 消耗一个理性点,对指定敌方单体造成200%攻击力的伤害,回复30能量" << endl; cout << screen_stirp[7] + screen_stirp[7] + "Q技能q: 消耗180能量,回复两个理性点,进入「回复」状态,持续三回合,此状态下记录角色造成的伤害,在状态中,每回合结束后将记录的伤害的50%转化为血量回复量" << endl; int num1, num2; // 对提取的数字降序排序 std::sort(every_b_l, every_b_l+5, std::greater<int>()); num1 = every_b_l[0]; // 最大的数字 num2 = every_b_l[1]; // 第二大的数字 // cout<<num1<<endl<<num2<<endl;
} else { cout<<"(请勿重复进行无效输入,否则电脑堆栈将爆炸)木有欧"<<endl; display_role(); } return 0; // 步骤3:拼接成百分数(比如num1=9, num2=5 → 95% → 0.95) double percentage = (num1 * 10 + num2) / 100.0; percentage*=enemy.at_power[bianhao]; *player_data-=percentage; cout<<"-"<<percentage<<endl; } void attack_2(int* player_date,int bianhao) override{//从玩家能量中选择最大的一个数,拼和成一个百分数,此次攻击会吸取玩家能量,大小为攻击力与这个百分数乘算的结果,此次攻击后玩家不会获得手机 int p_l = *player_date; // 步骤1:提取玩家能量的每一位数字 int every_b_l[5] = {0}; // 初始化数组,最多存储5位数字 int digit_count = 0; // 记录实际提取的数字位数 int temp = p_l;
int choose_look_or_fight() { cout<<screen_stirp[0]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<"| 输入“c”查看角色 |"<<endl; cout<<"| 输入“f”开始战斗 |"<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[1]<<endl; cout<<screen_stirp[0]<<endl; string a; // 清除输入缓冲区 cin.ignore(numeric_limits<streamsize>::max(),'\n'); cout<<"请输入:"; cin>>a; // 清除输入缓冲区 cin.ignore(numeric_limits<streamsize>::max(), '\n'); if(a=="c") // 分解玩家能量的每一位数字 while (temp > 0 && digit_count < 5) { display_role(); every_b_l[digit_count++] = temp % 10; // 取个位数字 temp = temp / 10; // 去掉个位 } else if(a=="f") { operate fight; fight.generate(); fight.select(1);//只有一个角色 } else { cout<<"(请勿重复进行无效输入,否则电脑堆栈将爆炸)无效输入,请重新输入:"<<endl; choose_look_or_fight(); } return 0; }
int num1; // 对提取的数字降序排序 std::sort(every_b_l, every_b_l + 5, std::greater<int>()); num1 = every_b_l[0]; // 最大的数字 // 步骤3:拼接成百分数(比如num1=9, num2=5 → 95% → 0.95) double percentage = (num1) / 100.0; *player_date-=percentage*enemy.at_power[bianhao]; cout<<"-"<<percentage*enemy.at_power[bianhao]<<endl; }};
int main(){ display screen; //screen.start_screen();//不知道为啥,把注释解了就会出事 cin.ignore(numeric_limits<streamsize>::max(),'\n'); screen.choose_look_or_fight(); // operate fight; // fight.generate(); // fight.select(1);//只有一个角色 return 0;}
```
### 更新细则1. 多端适应2. 更新的交互3. 一堆bug### 画饼- [x] 第一个角色- [x] 角色技能- [x] 战斗- [x] 查看角色技能- [x] 更好的显示- [x] 更好的交互- [x] 敌人行动- [ ] 养成- [ ] ...### bug修复- [x] 受攻击后血量异常变化or不扣血注释:现在的你终于可以被打死了- [x] 敌人第一次攻击时会打你两轮注释:你终于不怕在开局被打个半死了- [ ] ...