王者光耀2次作业

对任务的思考

在这次作业中我负责的是建筑类。按我的想法 我的想法是先建一个防御塔的类,因为防御塔的类建完后水晶的类其实是类似的。然后我再建立了一个泉水的类。
最后按照防御塔的类差不多建立了个水晶的类。

防御塔类

防御塔类中,我的想法是这个防御塔要有个生命值,然后要有个攻击敌方的值。然后还要有个攻击敌方英雄或者小兵的函数。
因此我的防御塔的类的初步代码如下:

class tower {
    int life;
    int hurt;
    static count;
public:
    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 water {
    int re;
public:
    int retur(hero &a)
    {
        while (1)//回血一直到英雄的血值上界
        {
            if (a.life != a.lifeup)
                a.life += 400;
            else
                break;
        }
    }
};//这个是泉水  英雄复活

水晶

水晶其实是和防御塔是一个性质的 因此水晶的类和防御塔的类类似.

class shuijing {
    int life;
    int hurt;
    static count;
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/9196647.html