python问题请教:大佬们 AttributeError: 'int' object has no attribute 'save_bullet'
2017-10-19 00:02
991 查看
coding=utf-8
class Person(object):“”“人的类”“”
def init(self,name):
super(Person, self).init()
self.name = name
self.gun = None
self.hp = 100
def zhuang_dan(self,dan_jia,zi_dan): #dan_jia.save_bullet(zi_dan) dan_jia.save_bullet(zi_dan) def zhuang_dan_jia(self,gun,dan_jia): gun.save_dan_jia(dan_jia) def na_qiang(self,gun): self.gun = gun def fire(self,enemy): self.gun.fire_somebody(enemy) def diao_xue(self,sha_shang_li): self.hp -= sha_shang_li def __str__(self): if self.gun: return "%s的血量为%d, 有%s枪"%d(self.name,self.hp,self.gun) else: return "%s的血量为%d, 没有枪"%d(self.name,self.hp)
class Gun(object):
“”“枪的类”“”
def init(self,name):
super(Gun, self).init()
self.name = name
self.dan_jia = None
def save_dan_jia(self,dan_jia):
self.dan_jia = dan_jia
def fire_somebody(self,enemy):
shot = self.dan_jia.fire_some()
shot.hit(enemy)
def __str__(self): if self.dan_jia: return "枪的信息:%s,%s"%s(self.name,self.dan_jia) else: return "枪的信息:%s, 没有弹夹"%s(self.name)
class Dan_jia(object):
“”“弹夹类”“”
def init(self, max_bullet):
super(Dan_jia, self).init()
self.max_bullet = max_bullet
self.bullet_list = []
def save_bullet(self,zi_dan): self.bullet_list.append(zi_dan) def fire_some(self): if self.bullet_list: return self.bullet_list.pop() else: return None
class Zi_dan(object):
“”“子弹类”“”
def init(self, sha_shang_li):
super(Zi_dan, self).init()
self.sha_shang_li= sha_shang_li
def hit(self,enemy):
enemy.diao_xue(self.sha_shang_li)
def main():
”’
1.创建老王对象
2.创建枪对象
3.创建弹夹
4.创建子弹
5.弹夹装子弹
6.弹夹装枪
7.老王拿枪
8.创建敌人
9.开枪
”’
lao_wang = Person("老王") AK = Gun("AK") dan_jia_1 = (20) zi_dan = Zi_dan(10) lao_wang.zhuang_dan(dan_jia_1,zi_dan) lao_wang.zhuang_dan_jia(AK,dan_jia_1) lao_wang.na_qiang(AK) lao_song = Person("老宋") lao_wang.fire(lao_song) print(lao_wang) print(lao_wang)
if name == ‘main‘:
main()
/[b]**************************************[/b]/
报错如下:
Traceback (most recent call last):
File “lao_wang.py”, line 109, in
main()
File “lao_wang.py”, line 97, in main
lao_wang.zhuang_dan(dan_jia_1,zi_dan)
File “lao_wang.py”, line 12, in zhuang_dan
dan_jia.save_bullet(zi_dan)
AttributeError: ‘int’ object has no attribute ‘save_bullet’
Repl Closed
相关文章推荐
- Python3下AttributeError: 'dict' object has no attribute 'iteritems'的问题分析
- Python3下AttributeError: 'dict' object has no attribute 'iteritems'的问题分析
- Python问题:AttributeError: '_csv.reader' object has no attribute 'next' 以及UnicodeDecodeError: 'gbk' co
- python遇到AttributeError: 'str' object has no attribute '_getAssertEqualityFunc'问题解决过程
- python错误:AttributeError: 'module' object has no attribute 'setdefaultencoding'问题的解决方法
- python图像处理问题AttributeError: 'NoneType' object has no attribute 'shape'
- 解决python中问题AttributeError: 'collections.defaultdict' object has no attribute 'iteritems'
- python错误:AttributeError: 'module' object has no attribute 'setdefaultencoding'问题的解决方法
- python运行不了 AttributeError: module object has no attribute getdefaultlocale
- 《python核心编程》序列:字符串、列表和元组Python: Attribute Error - 'NoneType' object has no attribute
- python3 报错: AttributeError: 'module' object has no attribute 'urlopen'
- AttributeError: 'dict' object has no attribute 'items' 问题
- 关于Python的:'module' object has no attribute 'inet_pton'问题解决
- python大坑:AttributeError: 'module' object has no attribute 'Workbook'
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
- 执行Python程序时,报AttributeError: 'function' object has no attribute 'name'
- Python:AttributeError: 'function' object has no attribute '_doc_'
- 用python爬github上星级排名前列的项目报错AttributeError: 'NoneType' object has no attribute 'decode'
- [python]Django AttributeError 'tuple' object has no attribute 'regex'
- Python3.X识别混合编码,顺便解决“AttributeError: 'module' object has no attribute 'urlopen'”