def get_creature_config(self, level_config): config = CreatureConfigurations(self.rng) configurators = self.get_configurators(level_config, 'init_creatures') for configurator in configurators: creatures = configurator() for creature in creatures: config.add_creature(creature) return config
def setup(self): """ Setup the test case """ self.rng = random.Random() self.level = Level((60, 40)) self.level.set_location_type((10, 10), 'room') creature_config = CreatureConfigurations(self.rng) creature_config.add_creature( CreatureConfiguration(name = 'rat', body = 4, finesse = 12, mind = 2, hp = 2, speed = 2, icons = 1, attack = 2, ai = None)) creature_config.add_creature( CreatureConfiguration(name = 'dragon', body = 4, finesse = 12, mind = 2, hp = 2, speed = 2, icons = 1, attack = 2, ai = None)) self.mock_action_factory = mock() self.model = mock() self.creature_generator = CreatureGenerator(creature_config, self.model, self.mock_action_factory, self.rng) self.configuration = CreatureAdderConfiguration(['crypt']) self.configuration.add_creature(min_amount = 3, max_amount = 4, name = 'rat') self.configuration.add_creature(min_amount = 1, max_amount = 1, name = 'dragon', location = 'room') self.creature_adder = CreatureAdder(self.creature_generator, self.configuration, self.rng) self.creature_adder.add_creatures(self.level)
def setup(self): """ Setup test case """ self.creature_config = CreatureConfigurations(Random()) self.model = mock() self.action_factory = mock() self.rng = Random() self.creature_config.add_creature( CreatureConfiguration(name = 'rat', body = 4, finesse = 12, mind = 2, hp = 2, speed = 2, icons = [100, 101], attack = 2, ai = FlockingHerbivore)) self.creature_config.add_creature( CreatureConfiguration(name = 'spider', body = 6, finesse = 12, mind = 8, hp = 6, speed = 1, icons = [102], attack = 4, ai = FlockingHerbivore, effect_handles = [EffectHandle( trigger = 'on attack hit', effect = 'minor poison', parameters = None, charges = 100)])) self.generator = CreatureGenerator(configuration = self.creature_config, model = self.model, action_factory = self.action_factory, rng = self.rng )
class TestCreatureGeneration(object): """ Tests for creature generator """ def __init__(self): """ Default constructor """ super(TestCreatureGeneration, self).__init__() self.creature_config = None self.generator = None self.model = None self.action_factory = None self.rng = None def setup(self): """ Setup test case """ self.creature_config = CreatureConfigurations(Random()) self.model = mock() self.action_factory = mock() self.rng = Random() self.creature_config.add_creature( CreatureConfiguration(name = 'rat', body = 4, finesse = 12, mind = 2, hp = 2, speed = 2, icons = [100, 101], attack = 2, ai = FlockingHerbivore)) self.creature_config.add_creature( CreatureConfiguration(name = 'spider', body = 6, finesse = 12, mind = 8, hp = 6, speed = 1, icons = [102], attack = 4, ai = FlockingHerbivore, effect_handles = [EffectHandle( trigger = 'on attack hit', effect = 'minor poison', parameters = None, charges = 100)])) self.generator = CreatureGenerator(configuration = self.creature_config, model = self.model, action_factory = self.action_factory, rng = self.rng ) def test_creating_simple_creature(self): """ Test that simple creature can be created by name """ creature = self.generator.generate_creature(name = 'rat') assert_that(creature.name, is_(equal_to('rat'))) def test_creating_creature_with_effect(self): """ Test that creature with effect can be created """ creature = self.generator.generate_creature(name = 'spider') assert_that(creature, has_effect_handle()) def test_creating_creature_with_ai(self): """ Test that creature can have AI created """ creature = self.generator.generate_creature(name = 'rat') assert_that(creature.artificial_intelligence, is_(not_none()))