第7周项目3-用多文件组织角色类

来源:互联网 发布:php 编译 sass 编辑:程序博客网 时间:2024/06/08 06:52


/*
All rights reserced.
文件名称:main.cpp
作者:李鑫
完成日期:2016.4.28
问题描述:将上一周“项目2-带武器的游戏角色”用“一个项目多个文件”的方式实现,其中两个类的声明放在一个.h文件中,每个类的成员函数分别放一个文件,main()函数用一个文件。体会这样安排的优点。

*/

#ifndef GAME_H_INCLUDED#define GAME_H_INCLUDEDusing namespace std;class Weapon{public:    Weapon(string wnam, int f);    int getForce();private:    string wname;   //名称    int force;       //威力};class Role{public:    Role(string nam, int b, string wnam, int f); //构造函数    ~Role(); //析构函数    void eat(int d); //吃东西,涨d血    void attack(Role &r); //攻击别人,自己涨血,同时失血    bool isAlived(); //是否活着    void show(); //显示private:    string name;    int blood;    Weapon weapon;    bool life;};#endif // GAME_H_INCLUDED

0 0