在这回的代码中,个人防护塔类仍是原来的样子以下ui
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; } };
可是,在水晶中我进行了更改,原来的水晶是单独一类,后来,我将水晶改成防护塔的派生类;code
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时游戏结束 } };
我以为本次任务是对上回的一些问题进行改善,并完成这回的收尾工做。
在做业中,思考该怎么将要完成的内容分红一小块一小块的,将工做量减小,花了挺多时间的 而后想类和类之间的关系也花了一部分时间。
在作这个类的过程当中,有些编译错误的点,比较晕,而后改了一些。可是有的点由于是在还没进行拼接的状况下产生的。而后这周把每一个人写的代码传上去后再进行拼接。游戏