第五周 项目2 游戏中的角色类
来源:互联网 发布:linux怎么杀进程 编辑:程序博客网 时间:2024/05/31 00:40
/*
*Copyright (c) 2016,烟台大学计算机学院
*All rights reserved.
*文件名称:test.cpp
*作 者:刘亚
*完成日期:2016年 5月 15日
*版 本 号:1.0
*
*问题描述:游戏中的角色类?
*输入描述:
*输出描述:
*/
*Copyright (c) 2016,烟台大学计算机学院
*All rights reserved.
*文件名称:test.cpp
*作 者:刘亚
*完成日期:2016年 5月 15日
*版 本 号:1.0
*
*问题描述:游戏中的角色类?
*输入描述:
*输出描述:
*/
#include<iostream>
#include<Cmath>
#include<cstdlib>
using namespace std;
class Role
{
public:
void eat(int d); //吃东西,涨d血
void attack(); //攻击别人,涨1血
void beAttack(); //被攻击,失1血,血为0死掉
bool isAlived(); //是否活着
void setRole(string nam, int b); //设置
void show(); //显示
private:
string name;
int blood;
bool life;
};
void Role::eat(int d)
{
if(isAlived())
blood+=d;
}
void Role::attack()
{
if(isAlived())
blood++;
}
void Role::beAttack()
{
if(blood>0)
blood--;
else
life=false;
}
bool Role::isAlived()
{
return life;
}
void Role::setRole(string nam, int b)
{
name=nam;
blood=b;
if(blood>0)
life=true;
else
life=false;
}
void Role::show()
{
cout<<name<<" has "<<blood<<" blood, it is ";
if(isAlived())
cout<<"alived.";
else
cout<<"dead.";
cout<<endl;
}
int main()
{
Role mary;
mary.setRole("Mary",4);
mary.show();
mary.attack();
mary.eat(2);
mary.beAttack();
mary.beAttack();
mary.show();
return 0;
}
#include<Cmath>
#include<cstdlib>
using namespace std;
class Role
{
public:
void eat(int d); //吃东西,涨d血
void attack(); //攻击别人,涨1血
void beAttack(); //被攻击,失1血,血为0死掉
bool isAlived(); //是否活着
void setRole(string nam, int b); //设置
void show(); //显示
private:
string name;
int blood;
bool life;
};
void Role::eat(int d)
{
if(isAlived())
blood+=d;
}
void Role::attack()
{
if(isAlived())
blood++;
}
void Role::beAttack()
{
if(blood>0)
blood--;
else
life=false;
}
bool Role::isAlived()
{
return life;
}
void Role::setRole(string nam, int b)
{
name=nam;
blood=b;
if(blood>0)
life=true;
else
life=false;
}
void Role::show()
{
cout<<name<<" has "<<blood<<" blood, it is ";
if(isAlived())
cout<<"alived.";
else
cout<<"dead.";
cout<<endl;
}
int main()
{
Role mary;
mary.setRole("Mary",4);
mary.show();
mary.attack();
mary.eat(2);
mary.beAttack();
mary.beAttack();
mary.show();
return 0;
}
0 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-游戏中的角色类
- 8 DStream与RDD
- Jrebel 6.4.2破解说明
- [从头学数学] 第219节 带着计算机去高考(十一)
- ubuntu apt-get 和 aptitude
- Java之------多线程(加强篇)
- 第五周 项目2 游戏中的角色类
- Contiki协议栈:索引目录
- Linux内核配置和编译过程详解
- 清除浮动
- 第十二周项目二-Time类中的运算符重载
- poj之旅——3666
- 初识Less
- 项目1-3 定义一个定义完整的类。这样的类在(2)的基础上,扩展+、-、*、/运算符的功能,使之能与double型数据进行运算。设Complex c; d
- SparkStream文件监控和数据读取