def __spawn_NPCs(self, population_size): for _ in range(0, population_size): NPC_type = randint(1, 4) if NPC_type == 1: # Person p = Person() self.__NPC_list.append(p) p.add_observer(self) self.__num_people += 1 elif NPC_type == 2: # Zombie z = Zombie() self.__NPC_list.append(z) z.add_observer(self) self.__num_monsters += 1 elif NPC_type == 3: # Vampire v = Vampire() self.__NPC_list.append(v) v.add_observer(self) self.__num_monsters += 1 elif NPC_type == 4: # Ghoul g = Ghoul() self.__NPC_list.append(g) g.add_observer(self) self.__num_monsters += 1 else: # Werewolf w = Werewolf() self.__NPC_list.append(w) w.add_observer(self) self.__num_monsters += 1
def __create_NPCs(self, num_NPCs): for x in range(0, num_NPCs): NPC_type = randint(0, 4) if NPC_type == 0: # Person person = Person() self.__NPCs.append(person) person.add_observer(self) self.__num_persons += 1 elif NPC_type == 1: # Zombie zombie = Zombie() self.__NPCs.append(zombie) zombie.add_observer(self) self.__num_monsters += 1 elif NPC_type == 2: # Vampire vampire = Vampire() self.__NPCs.append(vampire) vampire.add_observer(self) self.__num_monsters += 1 elif NPC_type == 3: # Ghoul ghoul = Ghoul() self.__NPCs.append(ghoul) ghoul.add_observer(self) self.__num_monsters += 1 elif NPC_type == 4: # Werewolf werewolf = Werewolf() self.__NPCs.append(werewolf) werewolf.add_observer(self) self.__num_monsters += 1
def update(self, obj_type): self.__num_monsters -= 1 self.__NPC_list.remove(obj_type) super().update_observers(obj_type) # Updating the neighborhood self.__num_people += 1 p = Person() self.__NPC_list.append(p) p.add_observer(self)
def update_observer(self, obj): # get rid of a monster, update neighborhood of change self.__num_monsters -= 1 self.__NPCs.remove(obj) super().update_observable(obj) # add a person self.__num_persons += 1 person = Person() self.__NPCs.append(person) person.add_observer(self)