c实现简单RPG对战游戏的代码.docx
- 文档编号:5588466
- 上传时间:2022-12-28
- 格式:DOCX
- 页数:24
- 大小:18.78KB
c实现简单RPG对战游戏的代码.docx
《c实现简单RPG对战游戏的代码.docx》由会员分享,可在线阅读,更多相关《c实现简单RPG对战游戏的代码.docx(24页珍藏版)》请在冰豆网上搜索。
c实现简单RPG对战游戏的代码
#include
#include
#include
enumpropte{sw,ar,mg};
classcontainer//人物的小包裹,用来装东西的....目前只装两种物品~有兴趣的可以自己加点东西进去`嘿嘿~
{
friendclassplayer;//定义一个基类
friendclassSwordsman;//定义一个剑士
friendclassArcher;//定义一个弓剑手
friendclassMage;//定义一个魔法师,其实我们以前玩的都是这样做的~只要把这些类附给一个人物身上就行了
friendvoidShowWindows(player&p1,player&p2);//显示框框~当前状态的函数
protected:
intNumHeal;//生命回复剂
intNumMgWorter;//魔法恢复剂
public:
container();//构造函数,....目前可有可无的样子~~
boolIsNumHealEmpoty();//判断还有没有生命恢复剂
boolIsMWEmpoty();//判断还有没有魔法恢复剂
voiddisplay();//显示当前还有多少魔法恢复剂和生命恢复剂
};
container:
:
container()
{
NumHeal=0;
NumMgWorter=0;
}
boolcontainer:
:
IsNumHealEmpoty()
{
returnNumHeal==0?
true:
false;
}
boolcontainer:
:
IsMWEmpoty()
{
returnNumMgWorter==0?
true:
false;
}
voidcontainer:
:
display()
{
cout<<"还剩下回复剂(HP100)"< cout<<"还剩下魔法剂(MP80)"< } classplayer//人物的基类 { friendclassSwordsman; friendclassArcher; friendclassMage;//这些都是朋友关系~又是父与子的关系~--! 好象有点复杂的样子~ friendvoidShowWindows(player&p1,player&p2);//上面已经说过了~不再重复 protected: intHp,HpMax,Mp,MpMax,speed,Ap,Dp,EXP,LV;//最大血量和最大魔法值,当前血量,魔法值,等等~望文生意 charname[10];//人物名称 propterole;//人物职业类型 booldeath;//是否死亡函数 containerbag;//人物的小包包~~^^ public: voidIsDead();//判断人物是否死亡 boolDead();//确认人物当前死亡状态~有返回值哦~ boolUseHeal();//好累...不过还是继续打字~使用生命回复剂 boolUseMW();//....跟上面差不多~ voidGetbag(player&p);//如果电脑死亡....就拿走他的小包包里面的东西~ voidShourole();//显示当前人物的职业~....这个是额外的函数~乱写的~ voidHpMpfull();//每打完一关敌人~HP,MP全满~ virtualboolattack(player&p)=0; virtualboolTSattack(player&p)=0; virtualvoidIsLvUp()=0;//上面三个都是纯虚函数~分别代表人物的普通攻击~特殊攻击和是否升级 }; voidplayer: : HpMpfull() { Hp=HpMax; Mp=MpMax; } voidplayer: : IsDead() { if(Hp<=0) { death=1; } } boolplayer: : Dead() { returndeath==1? true: false; } boolplayer: : UseHeal() { if(! bag.IsNumHealEmpoty()) { Hp=100; bag.NumHeal--; cout< if(Hp>HpMax) { Hp=HpMax; } returntrue; } else { cout<<"没有回复剂了"< returnfalse; } } boolplayer: : UseMW() { if(! bag.IsMWEmpoty()) { Mp=80; bag.NumMgWorter--; cout< if(Mp>MpMax) { Mp=MpMax; } returntrue; } else { cout<<"没有魔法恢复剂了~"< returnfalse; } } voidplayer: : Getbag(player&p) { cout< cout<<"获得了回复剂"< cout<<"获得了魔法回复剂"< bag.NumHeal=p.bag.NumHeal; bag.NumMgWorter=p.bag.NumMgWorter; } voidplayer: : Shourole() { switch(role) { casesw: cout<<"职业: 剑士"< break; casear: cout<<"职业: 弓箭手"< break; casemg: cout<<"职业: 魔法师"< break; } } classSwordsman: publicplayer//从基类派生出的一个类,是关于剑士的~ { public: Swordsman(inti,char*chname)//构造函数~赋予当前人物的属性值 { role=sw; intj; for(j=0;j<10;j) { name[j]=chname[j]; } Hp=1508*(i-1); HpMax=1508*(i-1); Mp=803*(i-1); MpMax=803*(i-1); Ap=254*(i-1); Dp=254*(i-1); speed=252*(i-1); LV=i; death=0; EXP=0; bag.NumHeal=i*5; bag.NumMgWorter=i*5; } boolattack(player&p);//剑士的普通攻击 boolTSattack(player&p);//特殊攻击 voidIsLvUp();//判断下是否升级 voidAI(player&p);//规定了电脑只能是剑士..当然~如果要电脑是其他角色就要写多点代码~可惜我比较懒.. }; boolSwordsman: : attack(player&p) { intHphit; intEXPhit; cout< srand(time(NULL)); intj=rand()0; if(speed>=p.speed&&j<=25) { cout<<"挥着大剑向敌人砍去"< cout<<"会心一击"< Hphit=p.Hp; p.Hp=p.Hp-(Apj10-p.Dp)*22*(LV-1); cout<<"直接命中敌人脑门,顿时鲜血四溅"< cout<<"敌人损失Hp"< EXPhit=EXP; EXP=Hphit-p.Hp; cout< p.IsDead(); returntrue; } elseif(speed<=p.speed&&(j>25||j<=50)) { cout<<"拿着剑摇摇晃晃的朝敌人砍去。 。 。 "< cout<<"敌人躲避"< returntrue; } elseif(j<100&&j>50) { cout<<"挥剑向敌人砍去"< Hphit=p.Hp; p.Hp=p.Hp-(Apj5-p.Dp)2*(LV-1); cout<<"命中敌人"< cout<<"敌人损失Hp"< EXPhit=EXP; EXP=Hphit-p.Hp; cout< p.IsDead(); returntrue; } else returnfalse; } boolSwordsman: : TSattack(player&p) { srand(time(NULL)); intj=rand()0; intHphit; intEXPhit; if(Mp>=50) { cout<<"万剑诀"< Mp-=40; if(j<=49||j>=60) { cout<<"完全命中目标"< cout<<"敌人完全吸收了伤害"< Hphit=p.Hp; p.Hp=p.Hp-(Apj/1010-p.Dp)*32*(LV-1); cout<<"敌人损失Hp"< EXPhit=EXP; EXP=Hphit-p.Hp; cout<<"获得EXP"< p.IsDead(); returntrue; } else { cout<<"敌人无意中的躲避,躲开攻击"< cout<<"攻击无效"< returntrue; } } else { cout<<"魔法不足! "< returnfalse; } } voidSwordsman: : IsLvUp() { if(EXP>=LV*LV*75) { EXP-=LV*LV*75; LV; HpMax=1508*(LV-1); MpMax=803*(LV-1); Ap=3; Dp=3; speed=4; cout<<"恭喜,"< } } voidSwordsman: : AI(player&p) { intHphit; srand(time(NULL)); intj=rand()0; if(Hp<=70&&j<=90&&! bag.IsNumHealEmpoty()) { cout<<"敌人使用了回复剂,体力恢复了100点"< Hp=100; bag.NumHeal--; if(Hp>HpMax) { Hp=HpMax; } } elseif((Mp>=50&&j<=80)||(p.Hp<=75&&Mp>=50&&j<=50)) { cout<<"敌人的特殊攻击(还没想好--! )"< Mp-=40; if(speed<=p.speed&&(j>=20||j<=30)) { cout< cout< } else { cout< Hphit=p.Hp; p.Hp-=(Apj10-p.Dp)*22*(LV-1); cout< p.IsDead(); } } elseif(Mp<50&&j<=40&&! bag.IsMWEmpoty()) { cout<<"敌人使用魔法剂,魔法值恢复了80点~"< Mp=80; bag.NumMgWorter--; if(Mp>MpMax) { Mp=MpMax; } } else { cout<<"敌人的普通攻击"< if(j<=25&&speed<=p.speed) { cout< } else { cout< Hphit=p.Hp; p.Hp-=(Apj10-p.Dp)(LV-1); cout<<"损失Hp"< p.IsDead(); } } } classArcher: publicplayer//差不多拉~只是数值和绝招要改改~其他的没什么了~只是少了个AI电脑智能函数 { public: Archer(inti,char*chname) { role=ar; intj; for(j=0;j<10;j) { name[j]=chname[j]; } Hp=1508*(i-1); HpMax=1508*(i-1); Mp=803*(i-1); MpMax=803*(i-1); Ap=254*(i-1); Dp=254*(i-1); speed=252*(i-1); LV=i; death=0; EXP=LV*LV*75; bag.NumHeal=i*5; bag.NumMgWorter=i*5; } boolattack(player&p); boolTSattack(player&p); voidIsLvUp(); }; boolArcher: : attack(player&p) { intHphit; intEXPhit; cout< srand(time(NULL)); intj=rand()0; if(speed>=p.speed&&j<=25) { cout< Hphit=p.Hp; p.Hp=p.Hp-(Ap-p.Dp)*2*(LV-1); cout<<"敌人损失Hp"< EXPhit=EXP; EXP=(Ap-Dp)*2*(LV-1); cout< p.IsDead(); returntrue; } elseif(speed<=p.speed&&j>25&&j<=50) { cout<<"敌人躲避"< returntrue; } elseif(j<100&&j>50) { cout< Hphit=p.Hp; p.Hp=p.Hp-(Ap-p.Dp)*(LV-1); cout<<"敌人损失Hp"< EXPhit=EXP; EXP=(Ap-Dp)*(LV-1); cout< p.IsDead(); returntrue; } else returnfalse; } boolArcher: : TSattack(player&p) { srand(time(NULL)); intj=rand()0; intHphit; intEXPhit; if(Mp>=50) { cout< Mp-=40; if(j<=49||j>=60) { cout<<"命中目标"< Hphit=p.Hp; p.Hp=p.Hp-(Ap-p.Dp)*3*(LV-1); cout<<"敌人损失Hp"< EXPhit=EXP; EXP=(Ap-p.Dp)*2*(LV-1); cout< p.IsDead(); returntrue; } else { cout<<"目标移动"< returntrue; } } else { cout<<"魔法不足! "< returnfalse; } } voidArcher: : IsLvUp() { if(EXP>=LV*LV*75) { EXP-=LV*LV*75; LV; HpMax=1508*(LV-1); MpMax=803*(LV-1); Ap=3; Dp=3; speed=4; cout< } } classMage: publicplayer { public: Mage(inti,char*chname) { role=mg; intj; for(j=0;j<10;j) { name[j]=chname[j]; } Hp=1508*(i-1); HpMax=1508*(i-1); Mp=803*(i-1); MpMax=803*(i-1); Ap=254*(i-1); Dp=254*(i-1); speed=252*(i-1); LV=i; death=0; EXP=LV*LV*75; bag.NumHeal=i*5; bag.NumMgWorter=i*5; } boolattack(player&p); boolTSattack(player&p); voidIsLvUp(); }; boolMage: : attack(player&p) { intHphit; intEXPhit; cout< srand(time(NULL)); intj=rand()0; if(speed>=p.speed&&j<=25) { cout<<"必杀"< Hphit=p.Hp; p.Hp=p.Hp-(Ap-p.Dp)*2*(LV-1); cout<<"敌人损失Hp"< EXPhit=EXP; EXP=(Ap-Dp)*2*(LV-1); cout<<"获得EXP"< p.IsDead(); returntrue; } elseif(speed<=p.speed&&j>25&&j<=50) { cout<<"敌人躲避"< returntrue; } elseif(j<100&&j>50) { cout<<"普通攻击"< Hphit=p.Hp; p.Hp=p.Hp-(Ap-p.Dp)*(LV-1); c
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实现 简单 RPG 游戏 代码