我剛開始練習,我應該完成一個基本的「憤怒的小鳥」克隆。 我被困在我想從列表中刪除對象的地方。該列表包含遊戲中使用的所有障礙物(框)。 所以如果我想刪除一個盒子後,我必須做一個方法來做到這一點。無論我如何做,這都會失敗。找不到列表以刪除對象
class spel(object):
def __init__(self):
self.obstacles = [obstacle(50,pos=(200,90)),]
#defines all other stuff of the game
class obstacle(object):
def __init__(self,size,pos):
#defines how it looks like
def break(self):
#methode that defines what happens when the obstacles gets destroyed
spel.obstacles.remove(self)
我得到的錯誤是:
AttributeError: 'NoneType' object has no attribute 'obstacles'
最後一行之後。 請原諒我的noob級別,但重要的是,我不會再需要在此之後再次編碼,所以不需要解釋所有內容。
也不使用break作爲方法名稱,它是一個保留字 – M4rtini
謝謝。錯過了。 – andreipmbcn
謝謝! @ M4rtini我用荷蘭語寫了遊戲,所以它是'breek'。我只是很快將其翻譯爲可讀性... –