王者光耀作业3

这次代码的改动

在这回的代码中,我的防御塔类还是原来的样子如下

class tower {
    int life;
    int hurt;
    static count;
public:
    tower()
    {
    }
    tower(int a)
    {
        count++;
        life = a;
        if(hurt<550)//伤害值的初始化
        hurt = 470+50*count;
        else hurt = 550;
    }
    int hurtother(enermy &a)//伤害其敌方小兵或者英雄
    {
        while (1)//如果对方没死或者塔本身没被拆就继续打
        {
            if (a.life != 0 && life != 0)
                a.life -= hurt;
            else  break;
        }
        return a.life;
    }

    
};

但是,在水晶中我进行了更改,原来的水晶是单独一类,后来,我将水晶改为防御塔的派生类;

class shuijing :public tower{
public:
    shuijing(int a)
    {
        count++;
        life = a;
        if (hurt<730)//伤害值的初始化
            hurt = 630 + 50 * count;
        else hurt = 730;
    }
    int hurtother(enermy &a)//伤害其敌方小兵或者英雄
    {
        while (1)
        {
            if (a, life != 0 )
                a.life -= hurt;
            else break;
        }
        return a.life;
    }
    bool OK()
    {
        if (life == 0)
            cout << "game over" << endl;//当血值为0时游戏结束
    }
};

我觉得本次任务是对上回的一些问题进行改善,并完成这回的收尾工作。
在作业中,思考该怎么将要完成的内容分成一小块一小块的,将工作量减少,花了挺多时间的 然后想类和类之间的关系也花了一部分时间。
在做这个类的过程中,有些编译错误的点,比较晕,然后改了一些。但是有的点因为是在还没进行拼接的情况下产生的。然后这周把每个人写的代码传上去后再进行拼接。

猜你喜欢

转载自www.cnblogs.com/zhanglingxin/p/9240691.html