c++ / day04

1. 整理思维导图

c++ / day04_第1张图片

2. 全局变量,int monster = 10000;定义英雄类hero,受保护的属性string name,int hp,int attck;公有的无参构造,有参构造,虚成员函数 void Atk(){blood-=0;},法师类继承自英雄类,私有属性 int ap_atk=50;重写虚成员函数void Atk(){blood-=(attck+ap_atk);};射手类继承自英雄类,私有属性 int ac_atk = 100;重写虚成员函数void Atk(){blood-=(attck+ac_atk);}实例化类对象,判断怪物何时被杀死。(能写多少写多少)

代码

#include 

using namespace std;

int blood =10000;

class Hero
{

protected:

    string name;

    int attck;

public:
    //constructor without param
    Hero(){}

    //constructor with param
    Hero(string name, int attck):name(name), attck(attck)
    {}
    virtual void atk()
    {
         cout << "Hero attck" <child
   Hero *pa = &archer; //parent point -->child
   int count_m = 0;
   int count_a = 0;

   while(1)
   {
       pm->atk();
       count_m++;
       if(blood <=0)
       {
           break;
       }
       pa->atk();
       count_a++;
       if(blood <=0)
       {
           break;
       }

   }
   cout << "Mage attck = "<

你可能感兴趣的:(c++,开发语言)