1. 程式人生 > >python 練習之炮臺

python 練習之炮臺

#建立一個炮臺類
attaction=0
class Paota:
    #初始化函式
    def __init__(self,name,attaction):
        self.name=name
        self.attaction=attaction
    def attack(self):
        print("%s建設完畢,攻擊力%d,"%(self.name,self.attaction))

    def shengji(self):
        print("%s升級完畢,攻擊力*2,當前攻擊力為%d"%(self.name,self.attaction*2
)) #單體炮塔 class singlePaota(Paota): def reducespeed(self): print("%s釋放技能減速"%self.name) def attack(self): super(singlePaota, self).attack() print("能夠對單目標進行攻擊") #群體炮塔 class crowdlePaota(Paota): def bingdong(self): print("%s釋放技能冰凍"%self.name) def attack(self): super(crowdlePaota, self).attack() print(
"能夠對群體目標進行攻擊") #主函式部分 print("歡迎進入遊戲介面".center(30,"*")) print("遊戲開始") list1=[] a=singlePaota("蘿蔔炮1號",20) a.attack() list1.append(a) a1=singlePaota("蘿蔔炮2號",20) a1.attack() list1.append(a1) b=crowdlePaota("蘑菇炮1號",10) b.attack() list1.append(b) b1=crowdlePaota("蘑菇炮2號",10) b1.attack() list1.append(b1) print(
"怪物入侵") print("%s進行單體輸出"%a.name) a.reducespeed() print("%s進行單體輸出"%a1.name) a1.reducespeed() print("%s進行群體輸出"%b.name) b.bingdong() print("%s進行群體輸出"%b1.name) b1.bingdong() print("炮塔升級") a.shengji() a1.shengji() b.shengji() b1.shengji() for i in list1: print(i)