Exemplo n.º 1
0
    def start(self):
        """
        start the game and initialize all game parameter
        add individuals to populations
        add food | poison | potions
        """
        self.game_objects['pop1'] = []
        self.game_objects['pop2'] = []
        self.game_objects['food'] = []
        self.game_objects['poison'] = []
        self.game_objects['health_potion'] = []
        self.game_objects['corpse'] = []
        self.game_objects['predators'] = []

        self.game_objects['pop1'] = self.breeder_pop1.initialize_population(
            self.num_individuals, self.colors['pop1'])
        self.game_objects['pop2'] = self.breeder_pop2.initialize_population(
            self.num_individuals, self.colors['pop2'])

        # for _ in range(self.num_individuals):
        #     self.game_objects['pop1'].append(Dot(self.parent, color=self.colors['pop1'][0]))
        #     self.game_objects['pop2'].append(Dot(self.parent, color=self.colors['pop2'][0]))
        for _ in range(self.num_food):
            self.game_objects['food'].append(Food(self.parent, self.border_width))
        for _ in range(self.num_poison):
            self.game_objects['poison'].append(Poison(self.parent, self.border_width))
        for _ in range(self.num_health_potions):
            self.game_objects['health_potion'].append(HealPotion(self.parent, self.border_width))
        
        self.running = True
Exemplo n.º 2
0
 def create_potion(self):
     """
     create potion on the field if there was some eaten
     """
     if (uniform(0, 1) < self.spawn_prob_potion and len(
             self.game_objects['health_potion']) < self.num_health_potions):
         self.game_objects['health_potion'].append(
             HealPotion(self.parent, self.border_width))