#include
#include
using namespace std;
string label[13]={
"职业"
,"力量"
,"敏捷"
,"智力"
,"生命成长"
,"攻击成长"
,"防御成长"
,"速度成长"
,"法术成长"
,"等级"
,"经验"
,"钱"
,"属性点"
};
//角色
class role{
public:
//生成函数
role(){
//空构造函数
}
role(string name,int STR,int DEX,int INT,int _hp,int _atk,int _def,int _spd,int _mp,int lv=1,int exp=0,int money=0){
this->name=name;
this->STR=STR;
this->DEX=DEX;
this->INT=INT;
this->_hp=_hp;
this->_atk=_atk;
this->_def=_def;
this->_spd=_spd;
this->_mp=_mp;
this->lv=lv;
this->exp=exp;
this->money=money;
this->pnt=0;
update();
}
//数据获取接口
string getname(){
return name;
}
int gethp(){
return hp;
}
int getatk(){
return atk;
}
int getdef(){
return def;
}
int getspd(){
return spd;
}
int getmp(){
return mp;
}
int getlv(){
return lv;
}
int getexp(){
return exp;
}
int getmoney(){
return money;
}
int getpnt(){
return pnt;
}
//数据修改接口
void modifyhp(int delta){
hp=max(0,hp+delta);
cout< } void modifymp(int delta){ mp=max(0,mp+delta); cout< } void modifydef(int delta){ def=max(0,def+delta); cout< } void modifyspd(int delta){ spd=max(0,spd+delta); cout< } void modifyatk(int delta){ atk=max(0,atk+delta); cout< } //获得经验与升级 void levelup(){ ++pnt; ++lv; cout<<"你的等级提升到了"< } bool modifyexp(int x){ if(x<0)return 0;//获取经验不能为负,否则操作失败, 返回0 cout<<"你获得了"< exp+=x; while(exp>=100){ exp-=100; levelup(); } return 1;//操作成功,返回1 } //金钱修改 bool modifymoney(int delta){ if(money+delta<0)return 0;//若金钱不足,则操作失败,返回0 money+=delta; if(delta>0)cout<<"你获得了"< if(delta<0)cout<<"你失去了"< return 1;//操作成功,返回0 } //属性点修改 bool modifySTR(int delta){ if(delta<0||delta>pnt)return 0;//不合法的操作,返回0 STR+=delta; pnt-=delta; update(); cout<<"你的力量提高了"< return 1; } bool modifyDEX(int delta){ if(delta<0||delta>pnt)return 0;//不合法的操作,返回0 DEX+=delta; pnt-=delta; update(); cout<<"你的敏捷提高了"< return 1; } bool modifyINT(int delta){ if(delta<0||delta>pnt)return 0;//不合法的操作,返回0 INT+=delta; pnt-=delta; update(); cout<<"你的智力提高了"< return 1; } virtual bool skill1(role &rhs){ cout< return 0; } virtual bool skill2(role &rhs){ cout< return 0; } virtual bool attack(role &rhs){ int tmp=min(rhs.gethp(),max(atk-rhs.getdef(),0)); cout< if(tmp)rhs.modifyhp(-tmp); return 1;//返回造成伤害的数值 } //调试函数,输出全部数据 void DEBUG_SHOW(){ cout<<"----------STATUS START----------"< cout<<"name:"< cout<<"STR:"< cout<<"DEX:"< cout<<"INT:"< cout<<"hp:"< cout<<"atk:"< cout<<"def:"< cout<<"spd:"< cout<<"mp:"< cout<<"level:"< cout<<"exp:"< cout<<"pnt:"< cout<<"money:"< cout<<"----------STATUS OVER----------"< } protected: /**//*函数部分*//**/ //更新战斗数据 virtual void update(){ atk=_atk*STR; hp=_hp*STR; spd=_spd*DEX; def=_def*DEX; mp=_mp*INT; } /**//*数据部分*//**/ //识别性数据 string name; //基本属性 int STR,DEX,INT;//力量,敏捷,智力 //属性比例 int _hp,_atk; int _def,_spd; int _mp; //战斗属性 int hp,atk;//生命值,攻击力 int def,spd;//防御值,速度 int mp; //魔法值 //等级 int lv,exp,pnt; //财富 int money; }; class warrior:public role{ public: //生成函数 warrior(string name,int STR,int DEX,int INT,int _hp,int _atk,int _def,int _spd,int _mp,int lv=1,int exp=0,int money=0): role(name,STR,DEX,INT,_hp,_atk,_def,_spd,_mp,lv,exp,money){ update(); } string getjob(){ return job; } bool skill1(role &rhs){ if(mp<10){ cout<<"mp不足无法使用。"< return 0; } cout< modifymp(-10); int delta=min(atk/2,rhs.getdef()); rhs.modifydef(-delta); return 1; } bool skill2(role &rhs){ if(mp<10){ cout<<"mp不足无法使用。"< return 0; } cout< modifymp(-10); modifydef(5); return 1; } bool attack(role &rhs){ int tmp=min(rhs.gethp(),max(atk-rhs.getdef(),0)); cout< if(tmp)rhs.modifyhp(-tmp); return 1;//返回造成伤害的数值 } private: string job="战士擅长硬刚,有着生命值+20和防御力+5的加成。但是因为肉体强韧,对魔力的亲和度极差,mp的成长性-5(不会低于0)。掌握技能:碎盾打击,固守。"; void update(){ atk=_atk*STR; hp=_hp*STR+20; spd=_spd*DEX; def=_def*DEX+5; mp=max(0,_mp-5)*INT; } }; class hunter:public role{ public: //生成函数 hunter(string name,int STR,int DEX,int INT,int _hp,int _atk,int _def,int _spd,int _mp,int lv=1,int exp=0,int money=0): role(name,STR,DEX,INT,_hp,_atk,_def,_spd,_mp,lv,exp,money){ update(); } string getjob(){ return job; } bool attack(role &rhs){ int tmp=min(rhs.gethp(),max(atk-rhs.getdef(),0)); cout< if(tmp)rhs.modifyhp(-tmp); return 1;//返回造成伤害的数值 } bool skill1(role &rhs){ if(mp<10){ cout<<"mp不足无法使用。"< return 0; } cout< modifymp(-10); int delta=min(atk+spd-rhs.getdef(),rhs.gethp()); rhs.modifyhp(-delta); return 1; } bool skill2(role &rhs){ if(mp<10){ cout<<"mp不足无法使用。"< return 0; } cout< modifymp(-10); int delta=min(5,rhs.getspd()); rhs.modifyspd(-delta); return 1; } private: string job="猎人有着高超的狩猎技巧,有着在快速运动中打击敌人的能力,速度的成长性+1,且获得额外的5点速度加成。掌握技能:强风射击,冰冻陷阱。"; void update(){ atk=_atk*STR; hp=_hp*STR; spd=(_spd+1)*DEX+5; def=_def*DEX; mp=max(0,_mp-5)*INT; } }; class wizard:public role{ public: //生成函数 wizard(string name,int STR,int DEX,int INT,int _hp,int _atk,int _def,int _spd,int _mp,int lv=1,int exp=0,int money=0): role(name,STR,DEX,INT,_hp,_atk,_def,_spd,_mp,lv,exp,money){ update(); } string getjob(){ return job; } bool attack(role &rhs){ int tmp=min(rhs.gethp(),max(atk-rhs.getdef(),0)); cout< if(tmp)rhs.modifyhp(-tmp); return 1;//返回造成伤害的数值 } bool skill1(role &rhs){ if(mp<10){ cout<<"mp不足无法使用。"< return 0; } cout< modifymp(-10); int delta=min(INT,rhs.gethp()); rhs.modifyhp(-delta); return 1; } bool skill2(role &rhs){ if(mp<50){ cout<<"mp不足无法使用。"< return 0; } cout< modifymp(-50); int delta=min(INT*5,rhs.gethp()); rhs.modifyhp(-delta); return 1; } private: string job="巫师以孱弱的身体为代价换来了对知识的掌握,mp成长性+1,但是防御力始终为0。掌握技能:火球术,大火球术。"; void update(){ atk=_atk*STR; hp=_hp*STR; spd=_spd*DEX; def=0; mp=(_mp+1)*INT; } }; class poison:public role{ public: //生成函数 poison(string name,int STR,int DEX,int INT,int _hp,int _atk,int _def,int _spd,int _mp,int lv=1,int exp=0,int money=0): role(name,STR,DEX,INT,_hp,_atk,_def,_spd,_mp,lv,exp,money){ update(); } string getjob(){ return job; } bool skill1(role &rhs){ if(mp<10){ cout<<"mp不足无法使用。"< return 0; } cout< modifymp(-10); int delta=min(atk/2,rhs.getdef()); rhs.modifydef(-delta); return 1; } bool skill2(role &rhs){ if(mp<10){ cout<<"mp不足无法使用。"< return 0; } cout< modifymp(-10); modifydef(5); return 1; } bool attack(role &rhs){ int tmp=min(rhs.gethp(),max(atk-rhs.getdef(),0)); cout< if(tmp)rhs.modifyhp(-tmp); return 1;//返回造成伤害的数值 } private: string job="毒师有着丰富的毒药储备,可使敌人属性大大减少。战斗中,防御-5,敏捷+2,mp的成长性+5。掌握技能:毒药挥洒,漫天繁星。"; void update(){ atk=_atk*STR; hp=_hp*STR+20; spd=_spd*DEX; def=_def*DEX+5; mp=max(0,_mp-5)*INT; } }; class assassin:public role{ public: //生成函数 assassin(string name,int STR,int DEX,int INT,int _hp,int _atk,int _def,int _spd,int _mp,int lv=1,int exp=0,int money=0): role(name,STR,DEX,INT,_hp,_atk,_def,_spd,_mp,lv,exp,money){ update(); } string getjob(){ return job; } bool skill1(role &rhs){ if(mp<10){ cout<<"mp不足无法使用。"< return 0; } cout< modifymp(-10); int delta=min(atk/2,rhs.getdef()); rhs.modifydef(-delta); return 1; } bool skill2(role &rhs){ if(mp<10){ cout<<"mp不足无法使用。"< return 0; } cout< modifymp(-10); modifydef(5); return 1; } bool attack(role &rhs){ int tmp=min(rhs.gethp(),max(atk-rhs.getdef(),0)); cout< if(tmp)rhs.modifyhp(-tmp); return 1;//返回造成伤害的数值 } private: string job="刺客擅于夜间行动,隐匿功能强大,身姿敏捷。近战时防御-5,敏捷+5。掌握技能:毒瞬移,刺杀。"; void update(){ atk=_atk*STR; hp=_hp*STR+20; spd=_spd*DEX; def=_def*DEX+5; mp=max(0,_mp-5)*INT; } }; class civilian:public role{ public: //生成函数 civilian(string name,int STR,int DEX,int INT,int _hp,int _atk,int _def,int _spd,int _mp,int lv=1,int exp=0,int money=0): role(name,STR,DEX,INT,_hp,_atk,_def,_spd,_mp,lv,exp,money){ update(); } string getjob(){ return job; } bool skill1(role &rhs){ if(mp<10){ cout<<"mp不足无法使用。"< return 0; } cout< modifymp(-10); int delta=min(atk/2,rhs.getdef()); rhs.modifydef(-delta); return 1; } bool skill2(role &rhs){ if(mp<10){ cout<<"mp不足无法使用。"< return 0; } cout< modifymp(-10); modifydef(5); return 1; } bool attack(role &rhs){ int tmp=min(rhs.gethp(),max(atk-rhs.getdef(),0)); cout< if(tmp)rhs.modifyhp(-tmp); return 1;//返回造成伤害的数值 } private: string job="平民学习能力高强,先天技能较薄弱。各项属性均为起始值。掌握技能:学习,暴动。"; void update(){ atk=_atk*STR; hp=_hp*STR+20; spd=_spd*DEX; def=_def*DEX+5; mp=max(0,_mp-5)*INT; } }; class pharmacist:public role{ public: //生成函数 pharmacist(string name,int STR,int DEX,int INT,int _hp,int _atk,int _def,int _spd,int _mp,int lv=1,int exp=0,int money=0): role(name,STR,DEX,INT,_hp,_atk,_def,_spd,_mp,lv,exp,money){ update(); } string getjob(){ return job; } bool skill1(role &rhs){ if(mp<10){ cout<<"mp不足无法使用。"< return 0; } cout< modifymp(-10); int delta=min(atk/2,rhs.getdef()); rhs.modifydef(-delta); return 1; } bool skill2(role &rhs){ if(mp<10){ cout<<"mp不足无法使用。"< return 0; } cout< modifymp(-10); modifydef(5); return 1; } bool attack(role &rhs){ int tmp=min(rhs.gethp(),max(atk-rhs.getdef(),0)); cout< if(tmp)rhs.modifyhp(-tmp); return 1;//返回造成伤害的数值 } private: string job="药师通过高超的制药用药技能,可迅速恢复自身生命值。由于常年在外采药,敏捷+5。掌握技能:治愈,采药。"; void update(){ atk=_atk*STR; hp=_hp*STR+20; spd=_spd*DEX; def=_def*DEX+5; mp=max(0,_mp-5)*INT; } }; class sword:public role{ public: //生成函数 sword(string name,int STR,int DEX,int INT,int _hp,int _atk,int _def,int _spd,int _mp,int lv=1,int exp=0,int money=0): role(name,STR,DEX,INT,_hp,_atk,_def,_spd,_mp,lv,exp,money){ update(); } string getjob(){ return job; } bool skill1(role &rhs){ if(mp<10){ cout<<"mp不足无法使用。"< return 0; } cout< modifymp(-10); int delta=min(atk/2,rhs.getdef()); rhs.modifydef(-delta); return 1; } bool skill2(role &rhs){ if(mp<10){ cout<<"mp不足无法使用。"< return 0; } cout< modifymp(-10); modifydef(5); return 1; } bool attack(role &rhs){ int tmp=min(rhs.gethp(),max(atk-rhs.getdef(),0)); cout< if(tmp)rhs.modifyhp(-tmp); return 1;//返回造成伤害的数值 } private: string job="剑客长年累月磨练自己的剑术,攻击力达到宗师级别。日日练功,力量+5。掌握技能:屠戮,见血封喉。"; void update(){ atk=_atk*STR; hp=_hp*STR+20; spd=_spd*DEX; def=_def*DEX+5; mp=max(0,_mp-5)*INT; } }; class trainer:public role{ public: //生成函数 trainer(string name,int STR,int DEX,int INT,int _hp,int _atk,int _def,int _spd,int _mp,int lv=1,int exp=0,int money=0): role(name,STR,DEX,INT,_hp,_atk,_def,_spd,_mp,lv,exp,money){ update(); } string getjob(){ return job; } bool skill1(role &rhs){ if(mp<10){ cout<<"mp不足无法使用。"< return 0; } cout< modifymp(-10); int delta=min(atk/2,rhs.getdef()); rhs.modifydef(-delta); return 1; } bool skill2(role &rhs){ if(mp<10){ cout<<"mp不足无法使用。"< return 0; } cout< modifymp(-10); modifydef(5); return 1; } bool attack(role &rhs){ int tmp=min(rhs.gethp(),max(atk-rhs.getdef(),0)); cout< if(tmp)rhs.modifyhp(-tmp); return 1;//返回造成伤害的数值 } private: string job="御兽师对兽类有着超高的亲和力。智力+5。掌握技能:兽潮,御兽千里。"; void update(){ atk=_atk*STR; hp=_hp*STR+20; spd=_spd*DEX; def=_def*DEX+5; mp=max(0,_mp-5)*INT; } }; class monster:public role{ public: //生成函数 monster(string name,int STR,int DEX,int INT,int _hp,int _atk,int _def,int _spd,int _mp,int lv=1,int exp=0,int money=0): role(name,STR,DEX,INT,_hp,_atk,_def,_spd,_mp,lv,exp,money){ update(); } string getjob(){ return job; } bool attack(role &rhs){ int tmp=min(rhs.gethp(),max(atk-rhs.getdef(),0)); cout< if(tmp)rhs.modifyhp(-tmp); return 1;//返回造成伤害的数值 } private: string job="野怪,顾名思义,就是用来刷钱刷经验的。"; void update(){ atk=_atk*STR; hp=_hp*STR; spd=_spd*DEX; def=_def*DEX; mp=_mp*INT; } }; int main(){ string username,keyword; Sleep(1000); cout<<"异世界调查团火热招新中。"< Sleep(1000); cout<<"首先,请您登陆您的账户。"< Sleep(1000); cout<<"您的用户名是?"< cin>>username; cout< cin>>keyword; string key; string nm; int a[13]; ifstream f(username); f>>key; if(key==keyword){ f>>nm; for(int i=0;i<13;++i)f>>a[i]; cout<<"登陆成功,"< }else if(key==""){ cout<<"用户不存在,已为您创建账户。"< Sleep(1000); cout<<"您角色的名字是?"< cin>>nm; cout< Sleep(1000); srand(time(NULL)); for(int i=1;i<=3;++i){ a[i]=rand()%10+5; cout<<"您的"<