생성자에서 타입이 다른데 에러가 안 나 ㅋㅋㅋㅋㅋ


그리고 궁금한게... 


class Item:

    #an item that can be picked up and used.

    def pick_up(self):

        #add to the player's inventory and remove from the map

        if len(inventory) >= 26:

            message('inventory is full, cannot pick up ' + self.owner.name + '.', libtcod.red)

        else:

            inventory.append(self.owner)

            objects.remove(self.owner)

            message('You picked up a ' + self.owner.name + '!', libtcod.green)


Item에는 분명히 owner 필드가 정의가 안 되있단 말여?


class Object:

    def __init__(self, name, x,y ,char, color, blocks = False, fighter=None, ai=None, item=None):

        self.name = name

        self.x = x

        self.y = y

        self.char = char

        self.color = color

        self.blocks = blocks

        

        self.fighter = fighter

        if self.fighter: #is not None

            self.fighter.owner = self


        self.ai = ai

        if self.ai:

            self.ai.owner = self


        self.item = item

        if self.item:

            self.item.owner = self


에엥? 근데 그냥 막 쓰네?

게다가 작동하기까지함 이거 원리가 뭐죠?


그동안 __init__에서 self.field를 초기화하면 필드가 정의 되는 뭐 그런 건 줄 알았는데

찾아보니까 ai나 fighter도 owner같은 건 초기화하지 않더라구요


어떻게 작동하는거임?



전체코드는 좀 다르긴 한데

여기

http://pastebin.com/eDmsTJB0