带武器的游戏角色
2016-04-12 18:58
323 查看
/* * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名称:main.cpp * 作 者:胡庆龙 * 完成日期:2016年4月8日 * 版 本 号:v1.0 * * 问题描述:在上周的游戏角色类的基础上加上武器 */ #include<iostream> #include<ctime> #include<cstdlib> using namespace std; class Role { public: void setRole(string ,int); void show(); void attack(int ); void eat(int ); void beAttack(int ); void wuqi(int l=1,int mo=100); private: string name; string nam; int blood; int li; int mosun; }; void Role::wuqi(int l,int mo) //武器建立 { li=l; mosun=mo; nam="倚天剑"; } void Role::setRole(string nam,int n) //角色创建,名字命名,血量设置 { name=nam; blood=n; } void Role::show() //展现角色当前状态 { cout<<"角色名: "<<name<<" 剩余血量: "<<blood<<endl; cout<<"武器名: "<<nam<<" 攻击力: "<<li<<" 耐久值: "<<mosun<<endl; if(blood>0) cout<<"alived"<<endl; else cout<<"dead"<<endl; } void Role::attack(int n) //攻击他人 { if(mosun<=0) { cout<<"武器已损坏"<<endl; blood=blood+n; } else { blood=blood+(n+li); mosun=mosun-li-n; } } void Role::eat(int n) //吃东西加血 { switch(n) { case 0: blood=blood+1; case 1: blood=blood+2; case 2: blood=blood+3; } } void Role::beAttack(int n) //被人攻击失n血 { blood=blood-n; } int main() { srand(time(0)); Role mary; mary.setRole("Mary",20); mary.wuqi(rand()%3,rand()%200); mary.show(); mary.attack(rand()%2); mary.eat(rand()%3); mary.beAttack(rand()%5); mary.beAttack(rand()%5); mary.beAttack(rand()%5); mary.beAttack(rand()%5); mary.beAttack(rand()%5); mary.beAttack(rand()%5); mary.show(); return 0; }
相关文章推荐
- POJ 3468 A Simple Problem with Integers 【splay树入门题】
- android jni编译配置DEBUG or RELEASE 的方法和优先级
- 获取手机MAC地址问题
- 负能量
- [case分享]Exchange 2013 IMAP问题解决历程
- 基于二叉查找树的符号表
- 测试工程师and酒吧
- 使用CMD命令行来对MySQL数据库执行迁移、备份、恢复
- 不是回文串
- 虚方法【仅仅有虚方法或者抽象方法才干被子类方法重写】
- vs2010 Express 下载连接
- 第五周 项目3-时间类(2)
- ios修改导航栏的背景颜色
- DL经典论文
- Java之——生成短8位UUID
- 上楼梯
- 利用localStorage实现对ueditor编辑内容定时保存为草稿
- 构建之法阅读笔记02
- switch引用字符串
- 代付业务