‘‘‘
Implementation ideas:
1. Create a turret class that contains 2 variables, one of which is the turret name, and the other is the attack.
2. Write an attack function in the turret class, and refer to the case effect to write the corresponding statement. Can not write for the time being.
3. Write an upgrade function in the turret class, let attack by 2, refer to the case effect.
4. Create a single turret class and the group turret class are inherited from the turret respectively. Rewrite the attack function separately, the output statement see the case effect.
5. The individual turret class defines a skill reduction method, see case effect.
6. The group turret class defines a skill freezing method.
7. Create 2 individual turrets and 2 crowd turrets in the main program. Store these 4 objects in a list. Iterate through the list to try to complete the case effect.
‘‘‘
#Parent class TurretclassPata:def __init__(Self,name,tak): Self.name=name Self.tak=TakPrint('%s construction completed, attack damage%d'% (Self.name, Self.tak), end=',')defGongji (self):Print('{} for monomer output'. Format (self.name))defShengji (self):Print('%s Upgrade complete, attack damage, current attack%d'% (self.name,self.tak*2))#Single TurretclassDan (Pata):def __init__(Self,name,tak): Super ().__init__(Name,tak)Print('capable of attacking a single target')defJiansu (self):Print('%s release skill deceleration'%(self.name))#crowd turretclassQun (Pata):def __init__(Self,name,tak): Super ().__init__(Name,tak)Print('ability to attack group targets')defGongji (self):Print('{} for group output'. Format (self.name))defJiansu (self):Print('%s release skill Freeze'%(self.name))#Create main program save list traversaldefMan ():Print('Game Start') D1= Dan ('Turnip Cannon No. 1th', 20) D2= Dan ('Turnip Cannon No. 2nd', 20) Q1= Qun ('Mushroom Cannon No. 1th', 10) Q2= Qun ('Mushroom Cannon No. 2nd', 10) LT=[D1,D2,Q1,Q2]Print('Monster Invasion') forIinchLt:i.gongji () I.jiansu ( )Print('Turret Upgrade') forKinchLt:k.shengji ()if __name__=='__main__': Man ()
Case List
Object-oriented turret game (inheritance, object storage to list)