class Horde(object):
    def __init__(self, factory, spr_group=None, animations=None):
        self.__group = Group() if spr_group is None else spr_group
        self.__elements = []
        self.__animations = animations
        self.__factory = factory

    def new_member(self, position, animations=None):
        animations = animations if animations is not None else self.__animations
        element = self.__factory(position, animations)
        self.add(element)
        return element

    @property
    def elements(self):
        return self.__elements

    @property
    def sprite_group(self):
        return self.__group

    def add(self, actor):
        self.__elements.append(actor)
        self.__group.add(actor)
        actor.horde = self

    def left(self, actor):
        try:
            actor_idx = self.__elements.index(actor)
            del(self.__elements[actor_idx])
        except ValueError:
            pass
        finally:
            if self.__group.has(actor):
                self.__group.remove(actor)
            actor.horde = Alone(self.__factory)
        
    def notify_state_changed(self, new_state, actor=None):
        '''actor: Actor() who change the state'''
        pass

    def handle_event(self, event):
        pass

    def draw(self, layer):
        self.__group.draw(layer)

    def update(self):
        self.__group.update()
 def __init__(self, factory, spr_group=None, animations=None):
     self.__group = Group() if spr_group is None else spr_group
     self.__elements = []
     self.__animations = animations
     self.__factory = factory