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 init_level(rng, item_generator, creature_generator, level_size): """ Initialise upper crypt levels :returns: level configuration :rtype: LevelConfiguration """ room_generators = [SquareRoomGenerator(FLOOR_NATURAL, WALL_EMPTY, ['upper crypt']), SquareRoomGenerator(FLOOR_CONSTRUCTED, WALL_EMPTY, ['upper crypt'])] level_partitioners = [GridPartitioner(['upper crypt'], 4, 3, rng)] replacer_config = ReplacingDecoratorConfig(['upper crypt'], {FLOOR_NATURAL: FLOOR_ROCK, FLOOR_CONSTRUCTED: FLOOR_BRICK}, {WALL_NATURAL: WALL_GROUND, WALL_CONSTRUCTED: WALL_ROCK}) replacer = ReplacingDecorator(replacer_config) wallbuilder_config = WallBuilderDecoratorConfig(['upper crypt'], {WALL_NATURAL: WALL_CONSTRUCTED}, WALL_EMPTY) wallbuilder = WallBuilderDecorator(wallbuilder_config) aggregate_decorator_config = AggregateDecoratorConfig(['upper crypt'], [wallbuilder, replacer]) decorators = [AggregateDecorator(aggregate_decorator_config)] item_adder_config = ItemAdderConfiguration(['upper crypt']) item_adder_config.add_item(min_amount = 2, max_amount = 4, type = 'weapon', location = 'room') item_adder_config.add_item(min_amount = 2, max_amount = 4, type = 'potion', location = 'room') item_adder_config.add_item(min_amount = 0, max_amount = 5, type = 'food', location = 'room') item_adders = [ItemAdder(item_generator, item_adder_config, rng)] creature_adder_config = CreatureAdderConfiguration(['upper crypt']) #creature_adder_config.add_creature(min_amount = 6, # max_amount = 12, # name = 'bat') creature_adder_config.add_creature(min_amount = 4, max_amount = 8, name = 'spider') #creature_adder_config.add_creature(min_amount = 4, # max_amount = 8, # name = 'skeleton', # location = 'room') creature_adders = [CreatureAdder(creature_generator, creature_adder_config, rng)] portal_adder_configurations = [PortalAdderConfiguration( icons = (PORTAL_STAIRS_DOWN, PORTAL_STAIRS_UP), level_type = 'upper catacombs', location_type = 'room', chance = 25, new_level = 'upper crypt', unique = True)] config = (LevelConfiguration() .with_rooms(room_generators) .with_partitioners(level_partitioners) .with_decorators(decorators) .with_items(item_adders) .with_creatures(creature_adders) .with_portals(portal_adder_configurations) .with_level_size(level_size) .build()) return config
class TestCreatureAdder(): """ Tests for CreatureAdder """ def __init__(self): """ Default constructor """ self.rng = None self.level = None self.mock_action_factory = None self.creature_generator = None self.configuration = None self.creature_adder = None 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 test_adding_creatures(self): """ Test basic case of adding creatures on the level """ assert_that(self.level.creatures, has_length(greater_than(3))) assert_that(self.level.creatures, has_length(less_than(6))) assert_that(self.level, has_creature('rat', greater_than_or_equal_to(3))) assert_that(self.level, has_creature('dragon', 1)) def test_adding_to_location(self): """ Test that CreatureAdder will use location types passed to it """ dragon = [x for x in self.level.creatures if x.name == 'dragon'][0] location = dragon.location assert_that(located_in_room(dragon))