class Person(object): """人的类""" def __init__(self, name): super(Person, self).__init__() self.name = name self.gun = None # 用来保存枪对象的引用 self.hp = 100 def anzhuang_zidan(self, dan_jia_temp, zi_dan_temp): """把子弹装到弹夹中""" # 弹夹.保存子弹(子弹) dan_jia_temp.baocun_zidan(zi_dan_temp) def anzhuang_danjia(self, gun_temp, dan_jia_temp): """把弹夹安装到枪中""" # 枪.保存弹夹(弹夹) gun_temp.baocun_danjia(dan_jia_temp) def naqiang(self, gun_temp): """拿起一把枪""" self.gun = gun_temp def __str__(self): if self.gun: return "%s的血量为:%d, 他有枪 %s" % (self.name, self.hp, |
python类例子(开枪)
最新推荐文章于 2024-05-03 03:21:12 发布