The charactor bring the weapon

<pre class="cpp" name="code">/*
 *Copyright(c)2016,烟台大学计算机与控制工程学院
 *All rights reserved
 *文件名称:123.cpp
 *作    者:隋宗涛
 *完成日期:2016年5月8日
 *版 本 号:v1.0
 *
 *问题描述:在上周的游戏角色类基础上扩充,为每个角色创建一个武器,并在攻击行为发生时,武器在其中起作用,设计一个武器类,其数据成员至少要有武器名、威力
 *输入描述:
 *程序输出:
*/
#include <iostream>
using namespace std;
class Weapon
{
public:
    Weapon(string wnam, int f);
    int getForce();
private:
    string wname;
    int force;
};
Weapon::Weapon(string wnam, int f):wname(wnam),force(f) {}
int Weapon::getForce()
{
    return force;
}
class Role
{
public:
    Role(string nam, int b, string wnam, int f);
    ~Role();
    void eat(int d);
    void attack(Role &r);
    bool isAlived();
    void show();
private:
    string name;
    int blood;
    Weapon weapon;
    bool life;
};
Role::Role(string nam, int b, string wnam, int f):name(nam),blood(b),weapon(wnam,f)
{
    if(blood>0)
        life=true;
    else
        life=false;
}
Role::~Role()
{
    cout<<name<<"退出江湖..."<<endl;
}
void Role::eat(int d)
{
    if(isAlived())
        blood+=d;
}
void Role::attack(Role &r)
{
    if(isAlived())
    {
        blood+=weapon.getForce();
        r.blood-=weapon.getForce();
        if(r.blood<=0)
            r.life=false;
    }
}
bool Role::isAlived()
{
    return life;
}
void Role::show()
{
    cout<<name<<" has "<<blood<<" blood, it is ";
    if(isAlived())
        cout<<"alived.";
    else
        cout<<"dead.";
    cout<<endl;
}
int main( )
{
    Role mary("Mary", 500, "TuLong",200);
    Role jack("Jack", 10, "YiTian", 180);
    cout<<"---begin---"<<endl;
    mary.show();
    jack.show();
    cout<<"---1st round---"<<endl;
    jack.attack(mary);
    mary.show();
    jack.show();
    cout<<"---2nd round---"<<endl;
    mary.attack(jack);
    mary.show();
    jack.show();
    cout<<"---end---"<<endl;
    return 0;
}

运行结果:

时间: 2024-10-30 01:06:18

The charactor bring the weapon的相关文章

按要求编写Java应用程序: (1)编写西游记人物类(XiYouJiRenWu) 其中属性有:身高(height),名字(name),武器(weapon) 方法有:显示名字(printName),显示武器(printWeapon) (2)在主类的main方法中创建二个对象:zhuBaJie,sunWuKong。并分别为他 们的两个属性(name,weapon)赋值,最后分别调用printName,

package com.hanqi.test; public class xiyoujirenwu { int height; String name; String weapon; xiyoujirenwu(String na,String wp ) { name=na; weapon=wp; } String printName() { return name; } String printWeapon() { return weapon; } } //主类 package com.hanq

CentOS7 Failed to start LSB: Bring up/down networking. 已解决!!!

服务器更换了主板之前配置的静态IP发现启动网卡出现异常. 执行 service network restart 出现以下错误 Restarting network (via systemctl):  Job for network.service failed. See 'systemctl status network.service' and 'journalctl -xn' for details.   尝试了好多种方法终于彻底解决掉了. 在centos7系统下执行: systemctl

CentOS7 | Failed to start LSB: Bring up/dow....

Jul 17 02:21:22 localhost.localdomain systemd[1]: network.service: control process ...1 Jul 17 02:21:22 localhost.localdomain systemd[1]: Failed to start LSB: Bring up/dow.... Jul 17 02:21:22 localhost.localdomain systemd[1]: Unit network.service ent

code=exited,status=1/failure;failed to start LSB:Bring up/down networking

环境: CentOS 7 vmware 12 操作: 复制可使用的vmware centOS 7系统至新环境 问题: 无法启动网络 查看“systemctl status network" 红色提示:”code=exited,status=1/failure“    和 ”failed to start LSB:Bring up/down networking“ 百度.google 各种方法无效,例如添加物理MAC等等 解决: vmware 12 网络设置,还原默认设置

he time that it takes to bring a block from disk into main memory

DATABASE SYSTEM CONCEPTS, SIXTH EDITION There is a trade-off that the system designer must make between access timeand space overhead. Although the decision regarding this trade-off depends onthe speci?c application, a good compromise is to have a sp

三种方法解决 Failed to start LSB: Bring up/down networking 问题

感谢朋友支持本博客.欢迎共同探讨交流.因为能力和时间有限,错误之处在所难免.欢迎指正! 假设转载.请保留作者信息. 博客地址:http://blog.csdn.net/qq_21398167 原博文地址:http://blog.csdn.net/qq_21398167/article/details/46694179 <-> 1.运行 service network restart 出现下面错误 Restarting network (via systemctl):  Job for netw

CentOS7 Failed to start LSB: Bring up/down

原文地址:http://addam.blog.51cto.com/5041993/1839518 刚刚装好的虚拟机突然不能上网了,报错很诡异,具体报错如下: /etc/init.d/network restart Restarting network (via systemctl):  Job for network.service failed because the control process exited with error code. See "systemctl status n

[Document]翻Projectile Weapon的时候发现的一些可能有用的东西

Firing Mode Definition /************************************************************************************ * Firing Mode Definition ***********************************************************************************/ /** * This enum defines the fir

[转载]解决虚拟机中Centos7出现错误:Failed to start LSB: Bring up/down networking

1.执行 service network restart 出现以下错误 Restarting network (via systemctl):  Job for network.service failed. See 'systemctl status network.service' and 'journalctl -xn' for details. 2.根据上面的提示,执行“systemctl status network.service”输出以下的类似信息: [[email protect