第六周上机实践项目-项目2-带武器的游戏角色

/* 
问题及代码:

*文件名称:

*作者:刘涛

完成日期:2016.4.2

*

*问题描述:带武器的游戏角色

*输入描述:名字,种族,性别

程序输出:血量,等级,名字

*/
#include<iostream>
#include<string>
using namespace std;
class Rode
{
public:
    void set(int blo,int ran);
    void setRode(string n1,char s,char n2);
    void show();
    void attack();
    void eat(int medicine);
    void beAttack();
    void use_weapon_one();
    void use_weapon_two();
    void use_weapon_three();
    void be_weapon_one();
    void be_weapon_two();
    void be_weapon_three();
    void range1();

private:
    string name;
    int blood;
    bool life;
    int range;
    char sex;
    char nation;
};
void Rode::set(int blo,int ran)
{
    blood=blo;
    range=ran;
}
   void Rode::setRode(string n1,char s,char n2)
   {
       name=n1;
       sex=s;
       nation=n2;
   }
    void Rode:: show()
    {
        cout<<name<<" "<<sex<<"性"<<nation<<"族"<<" "<<" has "<<blood<<" blood"<<endl;
        cout<<name<<" "<<range<<"级"<<endl;
    }
    void Rode::attack()
    {
        blood++;
        cout<<"您增加了1滴血"<<endl;

    }
    void Rode::eat(int medicine)
    {
        blood=blood+medicine;
        cout<<"您补充了2滴血"<<endl;
    }
    void Rode::beAttack()
    {
        blood--;
        cout<<"您减少了1滴血"<<endl;
        if(blood>0)
            life=true;
        else life=false;
    }
    void Rode::use_weapon_one()
    {
        blood+=2;
        cout<<"您增加了2滴血"<<endl;
    }
    void Rode::use_weapon_two()
    {
        blood+=3;
        cout<<"您增加了3滴血"<<endl;
    }
    void Rode::use_weapon_three()
    {
        blood+=4;
        cout<<"您增加了4滴血"<<endl;
    }
    void Rode::be_weapon_one()
    {
        blood=blood-2;
        cout<<"您减少了2滴血"<<endl;
        if(blood>0)
            life=true;
        else life=false;
    }
    void Rode::be_weapon_two()
    {
        blood=blood-3;
        cout<<"您减少了3滴血"<<endl;
        if(blood>0)
            life=true;
        else life=false;
    }
    void Rode::be_weapon_three()
    {
        blood=blood-4;
        cout<<"您减少了4滴血"<<endl;
        if(blood>0)
            life=true;
        else life=false;
    }
    void Rode::range1()
    {
        if(blood>=10)
        range+=1;
    }

int main()
{
    Rode m;
    string n1;
    char s;
    char n2;
    cout<<"请输入姓名,性别,种族:";
    cin>>n1>>s>>n2;
    m.setRode(n1,s,n2);
    m.set(9,1);
    m.show();
    m.attack();
    m.eat(2);
    m.beAttack();
    m.beAttack();
    m.use_weapon_one();
    m.use_weapon_two();
    m.use_weapon_three();
    m.be_weapon_one();
    m.be_weapon_two();
    m.be_weapon_three();
    m.range1();
    m.show();
    return 0;
}
运行结果:



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值