今日作业
1.什么是对象?什么是类?
对象,属性和方法的结合体
类:拥有相同属性和方法的对象的集合
2.绑定方法的有什么特点
绑定方法来自类方法,是属于对象的,同一个类绑定过来的绑定方法其不同对象的绑定方法的内存地址不同
3.基于面向对象设计一个对战游戏
# 仿制英雄联盟英雄角色
class yasuo:
def __init__(self,name,aggressivity,life_value):
self.aggressivity = aggressivity
self.life_value = life_value
self.name = name
def E(self,target):
if self.life_value <= 0:
return False,f'{self.name} die '
if self.life_value:
target.life_value -= self.aggressivity
return True,(f'''
{self.name} E to {target.name}
life_value - {self.aggressivity}
re_life_value {self.life_value}
''')
class zed:
def __init__(self,name,aggressivity,life_value):
self.aggressivity = aggressivity
self.life_value = life_value
self.name = name
def R(self,target):
if self.life_value <= 0:
return False,f'{self.name} die'
if self.life_value :
target.life_value -= self.aggressivity
return True,(f'''
{self.name} R to {target.name}
life_value - {self.aggressivity}
re_life_value {self.life_value}
''')
y = yasuo('yasuo',230,2000)
z = zed('zed',180,2500)
while 1:
flag1 ,msg = y.E(z)
if not flag1 :
print(msg)
break
else:
print(msg)
flag2 ,msg= z.R(y)
if not flag2:
print(msg)
break
else:
print(msg)