您的位置:首页 > 其它

带武器的游戏角色

2016-04-12 18:58 323 查看
/*
* Copyright (c) 2016,烟台大学计算机与控制工程学院
* All rights reserved.
* 文件名称:main.cpp
* 作    者:胡庆龙
* 完成日期:2016年4月8日
* 版 本 号:v1.0
*
* 问题描述:在上周的游戏角色类的基础上加上武器
*/
#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
class Role
{
public:
void setRole(string ,int);
void show();
void attack(int );
void eat(int );
void beAttack(int );
void wuqi(int l=1,int mo=100);
private:
string name;
string nam;
int blood;
int li;
int mosun;
};
void Role::wuqi(int l,int mo)     //武器建立
{
li=l;
mosun=mo;
nam="倚天剑";
}
void Role::setRole(string nam,int n)      //角色创建,名字命名,血量设置
{
name=nam;
blood=n;
}
void Role::show()               //展现角色当前状态
{
cout<<"角色名: "<<name<<" 剩余血量: "<<blood<<endl;
cout<<"武器名: "<<nam<<" 攻击力: "<<li<<" 耐久值: "<<mosun<<endl;
if(blood>0)
cout<<"alived"<<endl;
else
cout<<"dead"<<endl;
}
void Role::attack(int n)           //攻击他人
{
if(mosun<=0)
{
cout<<"武器已损坏"<<endl;
blood=blood+n;
}
else
{
blood=blood+(n+li);
mosun=mosun-li-n;
}
}
void Role::eat(int n)              //吃东西加血
{
switch(n)
{
case 0: blood=blood+1;
case 1: blood=blood+2;
case 2: blood=blood+3;
}
}
void Role::beAttack(int n)         //被人攻击失n血
{
blood=blood-n;
}
int main()
{
srand(time(0));
Role mary;
mary.setRole("Mary",20);
mary.wuqi(rand()%3,rand()%200);
mary.show();
mary.attack(rand()%2);
mary.eat(rand()%3);

mary.beAttack(rand()%5);
mary.beAttack(rand()%5);
mary.beAttack(rand()%5);
mary.beAttack(rand()%5);
mary.beAttack(rand()%5);
mary.beAttack(rand()%5);
mary.show();
return 0;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: