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)