c++:有武器的角色类



#include <iostream>


using namespace std;


class attack

{
public:
    attack(double T)
    {
        t=T;
    }


    void   show()
    {
        if(t<10)
        {
            cout<<"暴走,攻击力加倍  ";
            cout<<"攻击力为"<<2*t<<endl;
        }


        else if(t<100&&t>=10)
        {
            cout<<"屠戮,攻击力+10  ";
            cout<<"攻击力为"<<(10+t)<<endl;
        }
        else if(t>=100&&t<500)
        {
            cout<<"噬魂,攻击力+50  ";
            cout<<"攻击力为"<<(50+t)<<endl;
        }
        else if (t>=500&&t<1000)
        {
            cout<<"弑天,攻击力+200  ";
            cout<<"攻击力为"<<(200+t)<<endl;
        }


    }
private:
    double t;


};
class sword
{
public:
  sword(string name,double length,double width,attack A):
        n(name),l(length),w(width),a(A){}
    void putsword()
    {
        cout<<"剑名:"<<n<<endl;
        cout<<"剑长:"<<l<<endl;
        cout<<"剑宽:"<<w<<endl;
        a.show();
    }
private:
    string n;
    double l;
    double w;
    attack a;


};
int main()
{
    sword s("荒古遗尘长剑",10,4,600);
    s.putsword();
    sword c("别云剑——超有用",12,3,400);
    c.putsword();
    sword v("巴鲁姆克之光剑",6,2,80);
    v.putsword();
    sword h("华莱士巨剑",8,6,2);
    h.putsword();
    return 0;

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值