第六周作业 武器类





#include<iostream>
#include<string>
using namespace std;
class Wuqi
{
private:
string mingzi;
int gongjili;
int huilan;
public:
Wuqi(string ming,int gongji,int huil):mingzi(ming),gongjili(gongji),huilan(huil){}
void setwuqi()
{
cin>>mingzi>>gongjili>>huilan;
}
void get_mingzi()
{
cout<<mingzi;
}
void get_gongjili()
{
cout<<gongjili;
}
void get_huilan()
{
cout<<huilan;
}
int get__gongjili()
{
return gongjili;
}
int get__huilan()
{
return huilan;
}
};
class Role
{
private:
Wuqi wuqi;
string name;
int blood;
int magic;
bool life;
int q;
public:
Role(string na=" ",int bl=0,int ma=0,string ming=" ",int gongji=0,int huilan=0):name(na),blood(bl),magic(ma),wuqi(ming,gongji,huilan){}


void setRole(string na,int bl,int ma)
{
cout<<"您成功建立的角色"<<endl;
name=na;
blood=bl;
magic=ma;
q=1;
}
void sheding()
{
cout<<"请输入你所持有的武器,攻击力和特殊能力(回蓝)"<<endl;
wuqi.setwuqi();
cout<<"您已经装备武器:"<<endl;
cout<<"武器名字:";
wuqi.get_mingzi();
cout<<endl;
cout<<"武器攻击力:";
wuqi.get_gongjili();
cout<<endl;
cout<<"武器回蓝:";
wuqi.get_huilan();
cout<<endl;
}


void show()
{
if(q==1)
cout<<name<<" have "<<blood<<" blood"<<magic<<" magic"<<endl;
   else
{
cout<<"你已经死了,不能有任何动作"<<endl;
}
}
void attack()
{
cout<<"你成功攻击了对方,生命值+";
wuqi.get_gongjili();
cout<<"魔法值+";
wuqi.get_huilan();
cout<<endl;
blood=blood+wuqi.get__gongjili();
magic=magic+wuqi.get__huilan();
}
void magicattact()
{
cout<<"你使用了魔法攻击,对方生命值-";
wuqi.get_gongjili();
cout<<"您的生命值+";
wuqi.get_gongjili();
cout<<"魔法值+";
wuqi.get_huilan();
cout<<endl;
blood=blood+wuqi.get__gongjili();
magic=magic+wuqi.get__huilan();
}
void eat(int n)
{
cout<<"你吃了"<<n<<"个面包,生命值回复"<<n<<"点"<<endl;
blood=blood+n;
}
~Role()
{
cout<<"游戏退出"<<endl;
}


void xisheng()
{
cout<<name<<"光荣牺牲了"<<endl;
q=0;
}
void beAttack()
{
cout<<"你被攻击了,生命值-1"<<endl;
blood--;
if(blood==0)
{
cout<<"你已经死了"<<endl;
            xisheng();
}


}

};
/////////////主函数有瑕疵,我打算利用for循环,通过由玩家输入1,2,3,4,5来控制行为,先提交了再说吧
int main()
{
Role mary;
mary.setRole("ritian",4,4);
mary.sheding();
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();





}

你可能感兴趣的:(第六周作业 武器类)