/*
*copyright(c) 2014,烟台大学计算机学院
*All rights reserved
*文件名称:test.cpp
*作者:谭泽纯
*版本:v6.0
*
*问题描述:游戏角色
*输入描述:无
*程序输出:输出天数
*/
#include<iostream>
#include<string>
using namespace std;
class Role
{
private:
string name;
int blood;
int magic;
bool life;
public:
void setRole(string na,int bl,int ma)
{
cout<<"您成功建立的角色"<<endl;
name=na;
blood=bl;
magic=ma;
}
void show()
{
cout<<name<<" have "<<blood<<" blood"<<magic<<" magic"<<endl;
}
void attack()
{
cout<<"你成功攻击了对方,生命值+1"<<endl;
blood++;
}
void magicattact()
{
cout<<"你使用了魔法攻击,对方生命值-1,您的生命值+1,魔法指数-1"<<endl;
blood++;
magic--;
}
void eat(int n)
{
cout<<"你吃了"<<n<<"个面包,生命值回复"<<n<<"点"<<endl;
blood=blood+n;
}
~Role()
{
cout<<"游戏退出"<<endl;
}
void xisheng()
{
cout<<name<<"光荣牺牲了"<<endl;
}
void beAttack()
{
cout<<"你被攻击了,生命值-1"<<endl;
blood--;
if(blood==0)
{
cout<<"你已经死了"<<endl;
xisheng();
}
}
};
int main()
{
Role mary;
mary.setRole("ritian",4,4);
mary.show();
mary.eat(2);
mary.show();
mary.attack();
mary.show();
mary.magicattact();
mary.show();
mary.beAttack();
mary.show();
mary.beAttack();
mary.show();
mary.beAttack();
mary.show();
mary.beAttack();
mary.show();
mary.beAttack();
mary.show();
mary.beAttack();
mary.show();
mary.beAttack();
mary.show();
mary.beAttack();
}