在這回的代碼中,個人防護塔類仍是原來的樣子以下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時遊戲結束 } };
我以爲本次任務是對上回的一些問題進行改善,並完成這回的收尾工做。
在做業中,思考該怎麼將要完成的內容分紅一小塊一小塊的,將工做量減小,花了挺多時間的 而後想類和類之間的關係也花了一部分時間。
在作這個類的過程當中,有些編譯錯誤的點,比較暈,而後改了一些。可是有的點由於是在還沒進行拼接的狀況下產生的。而後這周把每一個人寫的代碼傳上去後再進行拼接。遊戲