第五周项目2-游戏中的角色类
来源:互联网 发布:在虚拟机上安装linux 编辑:程序博客网 时间:2024/06/05 15:53
Copyright (c) 2016,烟台大学计算机学院.
All rights reserced.
文件名称:test.cpp
作者 :秦通
完成日期:2016.4.7
版本号 :VC++6.0
程序输入:
#include<iostream>
using namespace std;
class Role
{
public:
Role(string lz,int b);
~Role();
void eat(int a);
void attack();
bool isAlived();
void beAttack();
void show();
private:
string name;
int blood;
bool life;
};
void Role::eat(int a)
{
if(isAlived())
blood=blood+a;
}
Role::Role(string lz,int b)
{
name=lz;
blood=b;
if(blood>0)
life=true;
else
life=false;
}
Role::~Role()
{
cout<<name<<"退出江湖..."<<endl;
}
void Role::attack()
{
if(blood>0)
blood++;
}
void Role::beAttack()
{
if(blood>0)
blood--;
else
life=false;
}
bool Role::isAlived()
{
return life;
}
void Role::show()
{
cout<<name<<"has "<<blood<<" blood, it is ";
if(isAlived())
cout<<"alived";
else
cout<<"dead";
cout<<endl;
}
int main( )
{
Role mary("Mary", 4);
Role jack("Jack", 0);
mary.show();
jack.show();
return 0;
}
运行结果:
- 第五周项目2-游戏中的角色类(2)
- 第五周项目2:游戏中的角色类(2)
- 第五周项目2--游戏中的角色类(2)
- 第五周【项目2-游戏中的角色类2】
- 第五周项目2-游戏中的角色类(2)
- 第五周 项目2 游戏中的角色类(2)
- 第五周项目2-游戏中的角色类(2)
- 第五周项目2-游戏中的角色类(1)
- 第五周项目2:游戏中的角色类(1)
- 第五周项目2-游戏中的角色类
- 第五周项目2游戏中的角色类
- 第五周项目二 游戏中的角色类(2)
- 第五周项目二-游戏中的角色类(2)
- 第五周项目二游戏中的角色类2
- 第五周【项目2-游戏中的角色类1】
- 第五周 项目二 游戏中的角色类 (2)
- 第五周项目2-游戏中的角色类(1)
- 第五周项目2-游戏中的角色类
- 获得 LayoutInflater 实例的三种方式和inflate方法
- 第5周项目3-时间类
- 设计模式-装饰者模式(Go语言描述)
- 递归函数求解问题
- 【poj 1724】 ROADS 最短路(dijkstra+优先队列)
- 第五周项目2-游戏中的角色类
- 第六种项目4
- Java gc垃圾回收机制
- hibernate批处理
- 还是回文----区间dp
- 深入FFM原理与实践
- iOS 微博 sdk 私信邀请指定好友
- 服务器容错技术
- 解析iOS崩溃日志