第5周项目2 游戏中角色类(扩充函数)
2016-04-02 13:15
393 查看
/* *copyright(c) 2016,烟台大学计算机学院 *All rights reserved *文件名称:test.cpp *作者:李硕 *版本:v6.0 * *问题描述:宣告主权 *输入描述: *程序输出: */ #include <iostream> using namespace std; class Role { public: void eat(int x); void attack();
void beAttack(); bool isAlived(); void setRole(string n, int b); void show(); //显示 private: string name; int blood; bool life; }; void Role::eat(int x) { if(isAlived()) blood=x+1; } void Role::attack() { if(isAlived()) blood++; } void Role::beAttack() { if(isAlived()) blood--; if(blood==0) life=false; } bool Role::isAlived() { return life; } void Role::setRole(string n, int b) { name=n; blood=b; if(blood>0) life=true; else life=false; cout<<"初始值是:"<<endl; } void Role::show() { cout<<name<<" 's "<<blood<<" blood is "; if(isAlived()) cout<<"islive."; else { cout<<"dead."<<endl; cout<<"GG"<<endl; } cout<<endl; } int main( ) { Role mary; mary.setRole("Mary", 4); mary.show(); mary.attack(); mary.eat(2); mary.beAttack(); mary.beAttack(); mary.beAttack(); mary.show(); return 0; }
<img src="http://img.blog.csdn.net/20160402131634753?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
相关文章推荐
- IP地址从头说起
- 算法总结(2)直接插入排序
- April Fools Day Contest 2016
- centos7-mysql安装
- iOS获得设备型号
- 三角形类 构造函数
- 百度地图IOS 自定义图标气泡viewForAnnotation不调用
- (Xaml) Type 'DeviceA' is not defined.
- nodejs pm2的简单应用
- BLACK PHOSPHORUS: THE NEW GRAPHENE?
- Android Http请求头与响应头的学习
- Android学习笔记---第一天---布局
- 易语言和VBS发送http请求 自动预约MZD记念馆团体票 分析第2步自动登陆预约carles抓包
- String.Join重载String.Join 方法 (String, String[], Int32, Int32)
- if-elif-else
- 【笔记】 《js权威指南》- 第6章 对象
- iOS UIView非常用方法及属性详解
- 初步实现网络socket编程
- use 163 sources
- Linux内核创建一个新进程的过程