飛飛(十九)简单的游戏角色设计

来源:互联网 发布:windows欢迎界面后黑屏 编辑:程序博客网 时间:2024/05/22 15:16
#include<iostream>using namespace std;class role{public:    void setrole(string m_name,int m_blood)    {        name=m_name;        blood=m_blood;    }    void show()    {        cout<<name <<" has "<< blood<<" blood"<<",";        if(blood>0)            cout<<"it is alived"<<endl;        else            cout<<"it is dead"<<endl;    }    void attack(int y)    {        blood=blood+y;    }    void beattack(int x)    {    blood=blood-x;    }    void eat (int m_blood)    {        blood+=m_blood;    }    private:    string name;    int blood;    bool life;    };    int main()    {        role tom;        tom.setrole("tom",4);        tom.show();        tom.attack(2);        tom.eat(4);        tom.beattack(2);        tom.show();        return 0;    }
<img src="http://img.blog.csdn.net/20160406173737586?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />

0 0