




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、#include<iostream.h>#include<time.h>#include<stdlib.h>enum propte sw,ar,mg;class container/ 人物的小包裹, 用来装东西的 目前只装两种物品有兴趣的可以自己加点东西进去、嘿嘿friend class player;/定义一个基类friend class Swordsman;/ 定义一个剑士friend class Archer;/定义一个弓剑手friend class Mage;/ 定义一个魔法师, 其实我们以前玩的都是这样做的只要把这些类附给一个人物身上就行了frie
2、nd void ShowWindows(player &p1,player &p2);/ 显示框框当前状态的函数protected:int NumHeal;/ 生命回复剂int NumMgWorter;/ 魔法恢复剂public:container ();/ 构造函数 , 目前可有可无的样子bool IsNumHealEmpoty();/ 判断还有没有生命恢复剂bool IsMWEmpoty();/ 判断还有没有魔法恢复剂void display();/ 显示当前还有多少魔法恢复剂和生命恢复剂;container:container()NumHeal = 0;NumMgWort
3、er = 0;bool container:IsNumHealEmpoty()return NumHeal = 0?true:false;bool container:IsMWEmpoty()return NumMgWorter = 0?true:false;void container:display()cout << " 还剩下回复剂( HP 100) " << NumHeal << " 个" << endl;cout << " 还剩下魔法剂 (MP 80) " <
4、< NumMgWorter << " 个 " << endl;class player/ 人物的基类friend class Swordsman;friend class Archer;friend class Mage;/ 这些都是朋友关系又是父与子的关系- -! 好象有点复杂的样子 friend void ShowWindows(player &p1,player &p2);/ 上面已经说过了不再重复protected:int Hp,HpMax,Mp,MpMax,speed,Ap,Dp,EXP,LV;/ 最大血量和最大魔法值
5、, 当前血量 , 魔法值 , 等等 望文生意char name10;/ 人物名称propte role;/ 人物职业类型bool death ;/ 是否死亡函数container bag;/人物的小包包AApublic:void IsDead();/ 判断人物是否死亡bool Dead();/ 确认人物当前死亡状态有返回值哦bool UseHeal();/ 好累 . 不过还是继续打字 使用生命回复剂bool UseMW();/ 跟上面差不多 void Getbag(player &p);/ 如果电脑死亡 就拿走他的小包包里面的东西 void Shourole();/ 显示当前人物的职业
6、 这个是额外的函数乱写的void HpMpfull();/每打完一关敌人HP,M晖满virtual bool attack(player &p) = 0;virtual bool TSattack(player &p) = 0;virtual void IsLvUp() = 0;/ 上面三个都是纯虚函数分别代表人物的普通攻击特殊攻击和是否升级;void player:HpMpfull()Hp = HpMax;Mp = MpMax;void player:IsDead()if (Hp <= 0 )death = 1;bool player:Dead()return deat
7、h = 1? true:false;bool player:UseHeal()if ( !bag.IsNumHealEmpoty() )Hp =100;bag.NumHeal -;cout << name << " 使用了恢复剂,生命值恢复了 100 点" << endl;if (Hp > HpMax)Hp = HpMax;return true;elsecout << " 没有回复剂了 " << endl;return false;bool player:UseMW()if ( !bag
8、.IsMWEmpoty() )Mp = 80;bag.NumMgWorter -;cout << name << " 使用了魔法恢复剂,魔法值恢复了80点" << endl;if (Mp > MpMax)Mp = MpMax;return true;elsecout << " 没有魔法恢复剂了 " << endl;return false;void player:Getbag(player &p)cout << name << " 获得了对方物品
9、" << endl;cout << " 获得了回复剂 " << p.bag.NumHeal << " 个 " << endl;cout << " 获得了魔法回复剂 " << p.bag.NumMgWorter << " 个" << endl;bag.NumHeal = p.bag.NumHeal;bag.NumMgWorter = p.bag.NumMgWorter;void player:Shou
10、role()switch(role)case sw:cout << " 职业:剑士 " << endl;break;case ar:cout << " 职业:弓箭手" << endl;break;case mg:cout << " 职业:魔法师" << endl;break;class Swordsman:public player/ 从基类派生出的一个类, 是关于剑士的 public:Swordsman(int i, char *chname)/ 构造函数赋予当
11、前人物的属性值role = sw;int j;for (j=0; j<10; j )namej = chnamej;Hp = 150 8 * (i - 1);HpMax = 150 8 * (i - 1);Mp = 80 3 * (i - 1);MpMax = 80 3 * (i - 1);Ap = 25 4 * (i - 1);Dp = 25 4 * (i - 1);speed = 25 2 * (i - 1);LV = i;death = 0;EXP = 0;bag.NumHeal = i * 5;bag.NumMgWorter = i * 5;bool attack(player
12、&p);/ 剑士的普通攻击bool TSattack(player &p);/ 特殊攻击void IsLvUp();/ 判断下是否升级void AI(player &p);/ 规定了电脑只能是剑士 . 当然 如果要电脑是其他角色就要写多点代码可惜我比较懒.;bool Swordsman:attack(player &p)int Hphit;int EXPhit;cout << name << " 攻击 " << endl;srand(time(NULL);int j = rand()0;if (speed
13、>= p.speed && j <= 25)cout << " 挥着大剑向敌人砍去" << endl;cout << " 会心一击 " << endl;Hphit = p.Hp;p.Hp = p.Hp - (Ap j 10 - p.Dp) * 2 2 * (LV - 1);cout << " 直接命中敌人脑门 , 顿时鲜血四溅" << endl;cout << " 敌人损失 Hp " << H
14、phit - p.Hp << endl;EXPhit = EXP;EXP = Hphit - p.Hp;cout << name <<" 获得经验 " << EXP - EXPhit << endl;p.IsDead();return true;else if(speed <= p.speed && (j >25 | j <=50) )<< endl;cout << " 拿着剑摇摇晃晃的朝敌人砍去。cout << " 敌人躲避
15、 " << endl;return true;else if(j < 100 && j > 50)cout << " 挥剑向敌人砍去" << endl;Hphit = p.Hp;p.Hp = p.Hp - (Ap j 5 - p.Dp) 2 * (LV - 1);cout << " 命中敌人 " << endl;cout << " 敌人损失 Hp " << Hphit - p.Hp << endl;EX
16、Phit = EXP;EXP = Hphit - p.Hp;cout << name << " 获得 EXP " << EXP - EXPhit << endl; p.IsDead();return true;elsereturn false;bool Swordsman:TSattack(player &p)srand( time(NULL) );int j = rand()0;int Hphit;int EXPhit;if ( Mp >= 50 )cout << " 万剑诀 "
17、 << endl;Mp -= 40;if (j <= 49 | j >= 60)cout << " 完全命中目标" << endl;cout << " 敌人完全吸收了伤害 " << endl;Hphit = p.Hp;p.Hp = p.Hp - (Ap j/10 10 - p.Dp) * 3 2 * ( LV -1);cout << " 敌人损失 Hp " << Hphit - p.Hp << endl;EXPhit = EXP
18、;EXP = Hphit - p.Hp;cout << " 获得 EXP " << EXP - EXPhit << endl;p.IsDead();return true;elsecout << " 敌人无意中的躲避, 躲开攻击 " << endl;cout << " 攻击无效 " << endl;return true;elsecout << " 魔法不足 ! " << endl;return false;
19、void Swordsman:IsLvUp()if (EXP >= LV * LV * 75)EXP -= LV * LV * 75;LV;HpMax = 150 8 * (LV -1);MpMax = 80 3 * (LV -1);Ap = 3;Dp = 3;speed = 4;cout << " 恭喜, "<< name <<" 升级了 " << " 等级为 " << LV << endl;void Swordsman:AI(player &p)
20、int Hphit;srand( time(NULL) );int j = rand()0;if (Hp <= 70 && j <=90 && !bag.IsNumHealEmpoty() )cout << " 敌人使用了回复剂 , 体力恢复了 100点 " << endl;Hp =100;bag.NumHeal -;if ( Hp > HpMax )(Hp = HpMax;)else if ( (Mp>=50 && j<=80) | (p.Hp<=75 &&
21、amp; Mp>=50 && j<=50)(cout << " 敌人的特殊攻击(还没想好-! ) " << endl;Mp -= 40;if ( speed <= p.speed && (j >= 20 | j <= 30) (cout << << "无意中的走位 "<< endl;cout << << "躲开了敌人攻击无效 "<< endl;) el
22、se(一cout << << "受至U猛烈冲击 "<< endl;Hphit = p.Hp;p.Hp -= (Ap j 10 - p.Dp) * 2 2 * (LV - 1);cout << << " 损失 Hp " << Hphit - p.Hp << endl; p.IsDead();)else if (Mp < 50 && j <=40 && !bag.IsMWEmpoty()(cout <
23、;< "敌人使用魔法剂,魔法值恢复了 80点 " << endl;Mp = 80;bag.NumMgWorter -;if (Mp > MpMax)(Mp = MpMax;) else(cout << " 敌人的普通攻击"<< endl;if ( j <= 25 && speed <= p.speed )(cout << << "躲开攻击 "<< endl;) else(cout <<
24、 <<" 受到伤害 " << endl;Hphit = p.Hp;p.Hp -= (Ap j 10 - p.Dp) (LV - 1);cout << " 损失 Hp " << Hphit - p.Hp << endl; p.IsDead(); class Archer:public player/ 差不多拉 只是数值和绝招要改改其他的没什么了只是少了个AI 电脑智能函数 public:Archer(int i, char *chname) role = ar;int j;for (j=0; j&
25、lt;10; j ) namej = chnamej;Hp = 150 8 * (i - 1);HpMax = 150 8 * (i - 1);Mp = 80 3 * (i - 1);MpMax = 80 3 * (i - 1);Ap = 25 4 * (i - 1);Dp = 25 4 * (i - 1);speed = 25 2 * (i - 1);LV = i;death = 0;EXP = LV * LV * 75;bag.NumHeal = i * 5;bag.NumMgWorter = i * 5;bool attack(player &p);bool TSattack(p
26、layer &p);void IsLvUp();bool Archer:attack(player &p) int Hphit;int EXPhit;cout << name << " 攻击 " << endl;srand(time(NULL);int j = rand()0;if (speed >= p.speed && j <= 25)cout << name << " 必杀一击 " << endl;Hphit = p.Hp;p.Hp
27、= p.Hp - (Ap - p.Dp) * 2 * (LV - 1);cout << " 敌人损失 Hp " << Hphit - p.Hp << endl;EXPhit = EXP;EXP = (Ap - Dp) * 2 * (LV - 1);cout << name << " 获得 EXP " << EXPhit - EXP << endl;p.IsDead();return true;else if(speed <= p.speed && j
28、 >25 && j <=50)cout << " 敌人躲避 " << endl;return true;else if(j < 100 && j > 50)cout << << " 普通攻击 " << endl;Hphit = p.Hp;p.Hp = p.Hp - (Ap - p.Dp) * (LV - 1);cout << " 敌人损失 Hp " << Hphit - p.Hp &
29、lt;< endl;EXPhit = EXP;EXP = (Ap - Dp) * ( LV - 1);cout << << " 获得 EXP " << EXPhit - EXP << endl;p.IsDead();return true;elsereturn false;bool Archer:TSattack(player &p)srand( time(NULL) );int j = rand()0;int Hphit;int EXPhit;if ( Mp >= 50 )cout <
30、< << " 的绝招 ." << endl;Mp -= 40;if (j <= 49 | j >= 60)cout << " 命中目标 " << endl;Hphit = p.Hp;p.Hp = p.Hp - (Ap - p.Dp) * 3 * ( LV -1);cout << " 敌人损失 Hp " << Hphit - p.Hp << endl;EXPhit = EXP;EXP = (Ap - p.Dp) * 2 *
31、 (LV -1 );cout << << " 获得经验 " << EXPhit - EXP << endl; p.IsDead();return true;elsecout << " 目标移动 " << << " 攻击无效 " << endl; return true; elsecout << " 魔法不足 ! " << endl;return false;void A
32、rcher:IsLvUp()if (EXP >= LV * LV * 75)EXP -= LV * LV * 75;LV;HpMax = 150 8 * (LV -1);MpMax = 80 3 * (LV -1);Ap = 3;Dp = 3;speed = 4;cout << name << " 升级了 , 等级为 " << LV << endl;class Mage:public playerpublic:Mage(int i, char *chname)role = mg;int j;for (j=0; j<
33、10; j )namej = chnamej;Hp = 150 8 * (i - 1);HpMax = 150 8 * (i - 1);Mp = 80 3 * (i - 1);MpMax = 80 3 * (i - 1);Ap = 25 4 * (i - 1);Dp = 25 4 * (i - 1);speed = 25 2 * (i - 1);LV = i;death = 0;EXP = LV * LV * 75;bag.NumHeal = i * 5;bag.NumMgWorter = i * 5;bool attack(player &p);bool TSattack(playe
34、r &p);void IsLvUp();bool Mage:attack(player &p)int Hphit;int EXPhit;cout << name << " 攻击 " << endl;srand(time(NULL);int j = rand()0;if (speed >= p.speed && j <= 25)cout << " 必杀 " << endl;Hphit = p.Hp;p.Hp = p.Hp - (Ap - p.Dp) *
35、2 * (LV - 1);cout << " 敌人损失 Hp " << Hphit - p.Hp << endl;EXPhit = EXP;EXP = (Ap - Dp) * 2 * (LV - 1);cout << " 获得 EXP " << EXPhit - EXP << endl;p.IsDead();return true;else if(speed <= p.speed && j >25 && j <=50)cout <
36、;< " 敌人躲避 " << endl;return true;else if(j < 100 && j > 50)cout << " 普通攻击 " << endl;Hphit = p.Hp;p.Hp = p.Hp - (Ap - p.Dp) * (LV - 1);cout << " 敌人损失 Hp " << Hphit - p.Hp << endl;EXPhit = EXP;EXP = (Ap - Dp) * ( LV - 1)
37、;cout << " 获得 EXP " << EXPhit - EXP << endl;p.IsDead();return true;elsereturn false;bool Mage:TSattack(player &p)srand( time(NULL) );int j = rand()0;int Hphit;int EXPhit;if ( Mp >= 50 )cout << " 绝招 ." << endl;Mp -= 40;if (j <= 49 | j >=
38、60)cout << " 命中目标 " << endl;Hphit = p.Hp;p.Hp = p.Hp - (Ap - p.Dp) * 3 * ( LV -1);cout << " 敌人损失 Hp " << Hphit - p.Hp << endl;EXPhit = EXP;EXP = (Ap - p.Dp) * 2 * (LV -1 );cout << " 获得经验 " << EXPhit - EXP << endl;p.IsDead(
39、);return true;elsecout << " 目标移动 , 攻击无效 " << endl;return true;elsecout << " 魔法不足 ! " << endl;return false;void Mage:IsLvUp()if (EXP >= LV * LV * 75)EXP -= LV * LV * 75;LV;HpMax = 150 8 * (LV -1);MpMax = 80 3 * (LV -1);Ap = 3;Dp = 3;speed = 4;void ShowWi
40、ndows(player &p1, player &p2)cout << << p1.Hp << " " << << p1.Mp << endl;cout << << p2.Hp << " " << << p2.Mp << endl; int main()cout << " 输入玩家名字 :" ;cha
41、r name10;cin >> name;player *human;Swordsman *sw = new Swordsman(1,name);Archer *ar = new Archer(1,name);Mage *mg = new Mage(1,name);bool success = 0;cout << " 请选择人物角色" << endl;docout << " 1 勇敢的剑士 2 精灵弓箭手3 强大的魔法师0 退出"<< endl;int j;cin >> j;swit
42、ch( j )case 0:cout << " 确定退出 ?(Y/N)" << endl;char ch;cin >> ch;if (ch = 'Y' | ch = 'y') exit(0); else success = 0; break;case 1:cout << " 选择剑士 " << endl;delete ar;delete mg;human = sw;success = 1;break;case 2:cout << " 选择弓剑手" << endl;delete sw;delete mg;human = ar;success = 1;break;case 3:cout << &qu
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 货物罚没赔款协议书
- 委托销毁协议书范本
- 外企意向协议书范本
- 离职签署保密协议书
- 解散公司协议书模板
- 签了协议书不再帮扶
- 住房指标赠与协议书
- 小区出售床位协议书
- 人员派遣学习协议书
- 民事调解协议书工伤
- 2024湖南省新华书店有限责任公司招聘10人笔试参考题库附带答案详解
- 档案管理制度培训宣贯
- 农机质量跟踪调查表
- 刑民交叉案件的司法认定
- 2025年度股权合作协议书新版:跨境电商平台股权合作协议
- GB/T 33136-2024信息技术服务数据中心服务能力成熟度模型
- 《阿尔茨海默病康复》课件
- 北京理工大学《操作系统课程设计》2021-2022学年第一学期期末试卷
- 精神病学第九版
- 《中华人民共和国药品管理法实施条例》
- DB11-T 2324-2024脚手架钢板立网防护应用技术规程
评论
0/150
提交评论