Object-oriented approach to combat - people and dogs shootout

class Animal: # define a class of animal 
DEF __init __ (Self, name, the HP, Attack):
self.name = name
self.hp = the HP
self.attack = Attack

class the Person (Animal): # inherit animal
def dg (self, dog): # create method man beat the dog
dog.hp- = self.attack

class Dog (animal): # inherit animal
def yr (self, peole): # create a method of dog bite
peole.hp- = self. Attack

Egg = the person ( 'EG', 150,20) # create a person
ha2 = dog ( 'two ha', 100,30) # create a dog
egg.dg (ha2) #egg hit the dog bit
print (ha2. hp) # dog lost 20 points of blood

Guess you like

Origin www.cnblogs.com/jmc218/p/11805915.html