def test_ornamentation_rate_can_be_controlled(self):
        """
        There should be way to control how frequently walls are ornamented
        """
        wall_tile(self.level, (2, 2), self.wall)
        wall_tile(self.level, (3, 2), self.wall)
        wall_tile(self.level, (4, 2), self.wall)

        rng = mock()
        when(rng).randint(any(),
                          any()).thenReturn(0).thenReturn(100).thenReturn(0)
        when(rng).choice(any()).thenReturn(self.ornamentation)

        self.config = WallOrnamentDecoratorConfig(
            ['any level'],
            wall_tile=self.wall,
            ornamentation=[self.ornamentation],
            rng=rng,
            rate=50)
        self.decorator = WallOrnamentDecorator(self.config)

        self.decorator.decorate_level(self.level)

        candle_count = 0
        for location, tile in get_tiles(self.level):
            if self.ornamentation in tile['\ufdd0:ornamentation']:
                candle_count = candle_count + 1

        assert_that(candle_count, is_(equal_to(2)))
Exemplo n.º 2
0
    def test_ornamentation_rate_can_be_controlled(self):
        """
        There should be way to control how frequently walls are ornamented
        """
        wall_tile(self.level, (2, 2), self.wall)
        wall_tile(self.level, (3, 2), self.wall)
        wall_tile(self.level, (4, 2), self.wall)

        rng = mock()
        when(rng).randint(any(), any()).thenReturn(0).thenReturn(100).thenReturn(0)
        when(rng).choice(any()).thenReturn(self.ornamentation)

        self.config = WallOrnamentDecoratorConfig(
                                        ['any level'],
                                        wall_tile = self.wall,
                                        ornamentation = [self.ornamentation],
                                        rng = rng,
                                        rate = 50)
        self.decorator = WallOrnamentDecorator(self.config)

        self.decorator.decorate_level(self.level)

        candle_count = 0
        for location, tile in get_tiles(self.level):
            if self.ornamentation in tile['\ufdd0:ornamentation']:
                candle_count = candle_count + 1

        assert_that(candle_count, is_(equal_to(2)))
Exemplo n.º 3
0
    def decorate_level(self, level):
        """
        Decorate level

        :param level: level to decorate
        :type level: Level
        """
        wall = self.configuration.wall

        for location, tile in get_tiles(level):
            if tile['\ufdd0:wall'] == wall:
                tile['\ufdd0:wall'] = self.get_wall_tile(level, location)
Exemplo n.º 4
0
    def decorate_level(self, level):
        """
        Decorate level

        :param level: level to decorate
        :type level: Level
        """
        wall = self.configuration.wall

        for location, tile in get_tiles(level):
            if tile['\ufdd0:wall'] == wall:
                tile['\ufdd0:wall'] = self.get_wall_tile(level, location)
Exemplo n.º 5
0
    def __construct_scene(self, model, scene):
        """
        Constructs scene to display
        """
        for anim in [x for x in self.animations]:
            anim.stop()
            anim.clear()

        for adapter in self.animation_adapters:
            adapter.glyphs.clear()

        self.animations = []

        scene.clear()

        self.current_level = model.player.level

        for location, tile in get_tiles(self.current_level):
            if tile['\ufdd0:floor']:
                new_glyph = MapGlyph(self.surface_manager.get_icon(tile['\ufdd0:floor']),
                                     None,
                                     self.animation_adapters[0])
                new_glyph.setZValue(zorder_floor)
                new_glyph.setPos(location[0] * 32, location[1] * 32)
                scene.addItem(new_glyph)
            if tile['\ufdd0:wall']:
                new_glyph = MapGlyph(self.surface_manager.get_icon(tile['\ufdd0:wall']),
                                     None)
                new_glyph.setZValue(zorder_wall)
                new_glyph.setPos(location[0] * 32, location[1] * 32)
                scene.addItem(new_glyph)

            for tile_id in tile['\ufdd0:ornamentation']:
                new_glyph = MapGlyph(self.surface_manager.get_icon(tile_id),
                                     None,
                                     self.rng.choice(self.animation_adapters))
                new_glyph.setZValue(zorder_ornament)
                new_glyph.setPos(location[0] * 32, location[1] * 32)
                scene.addItem(new_glyph)
            for item in tile['\ufdd0:items']:
                self.add_glyph(item, scene, zorder_item)
            for trap in tile['\ufdd0:traps']:
                self.add_glyph(trap, scene, zorder_trap)

        for creature in get_characters(self.current_level):
            self.add_glyph(creature,
                           scene,
                           zorder_character)
Exemplo n.º 6
0
    def decorate_level(self, level):
        """
        Decorate level

        :param level: level to decorate
        :type level: Level
        """
        wall = self.configuration.wall_tile
        rate = self.configuration.rate

        for location, tile in get_tiles(level):
            if tile['\ufdd0:wall'] == wall:
                if self.configuration.rng.randint(0, 100) < rate:
                    if (self.configuration.top_only == False
                        or floor_tile(level, (location[0], location[1] + 1))):
                        self._randomize_ornament(level, location)
Exemplo n.º 7
0
    def decorate_level(self, level):
        """
        Decorate level

        :param level: level to decorate
        :type level: Level
        """
        for location, tile in get_tiles(level):
            if tile['\ufdd0:floor'] == self.floor:
                floor_tile(level, location,
                           self.get_floor_tile(level, location))

        for location in self.second_pass:
            if get_tile(level, location):
                floor_tile(level, location,
                           self.check_nook(level, location))
Exemplo n.º 8
0
    def decorate_level(self, level):
        """
        Decorate level

        :param level: level to decorate
        :type level: Level
        """
        floor = self.configuration.floor
        for location, tile in get_tiles(level):
            if tile['\ufdd0:floor'] == floor:
                floor_tile(level, location,
                           self.get_floor_tile(level, location))

        for location in self.second_pass:
            if get_tile(level, location):
                floor_tile(level, location, self.check_nook(level, location))
Exemplo n.º 9
0
    def get_all_points(self, level, open_tile):
        """
        Get all open points in level

        Args:
            open: ID of tile considered open

        Returns:
            List of all open points in level
        """
        points = []

        for location, tile in get_tiles(level):
            if tile['\ufdd0:wall'] is None:
                points.append(location)

        return points
Exemplo n.º 10
0
    def get_all_points(self, level, open_tile):
        """
        Get all open points in level

        Args:
            open: ID of tile considered open

        Returns:
            List of all open points in level
        """
        points = []

        for location, tile in get_tiles(level):
            if tile['\ufdd0:wall'] is None:
                points.append(location)

        return points
Exemplo n.º 11
0
    def decorate_level(self, level):
        """
        Decorate level

        :param level: level to decorate
        :type level: Level
        """
        wall = self.configuration.wall_tile
        rate = self.configuration.rate

        for location, tile in get_tiles(level):
            if tile['\ufdd0:wall'] == wall:
                if self.configuration.rng.randint(0, 100) < rate:
                    if (self.configuration.top_only == False
                            or floor_tile(level,
                                          (location[0], location[1] + 1))):
                        self._randomize_ornament(level, location)
Exemplo n.º 12
0
    def __construct_scene(self, model, scene):
        """
        Constructs scene to display
        """
        for anim in [x for x in self.animations]:
            anim.stop()
            anim.clear()

        for adapter in self.animation_adapters:
            adapter.glyphs.clear()

        self.animations = []

        scene.clear()

        self.current_level = model.player.level

        for location, tile in get_tiles(self.current_level):
            if tile['\ufdd0:floor']:
                new_glyph = MapGlyph(
                    self.surface_manager.get_icon(tile['\ufdd0:floor']), None,
                    self.animation_adapters[0])
                new_glyph.setZValue(zorder_floor)
                new_glyph.setPos(location[0] * 32, location[1] * 32)
                scene.addItem(new_glyph)
            if tile['\ufdd0:wall']:
                new_glyph = MapGlyph(
                    self.surface_manager.get_icon(tile['\ufdd0:wall']), None)
                new_glyph.setZValue(zorder_wall)
                new_glyph.setPos(location[0] * 32, location[1] * 32)
                scene.addItem(new_glyph)

            for tile_id in tile['\ufdd0:ornamentation']:
                new_glyph = MapGlyph(self.surface_manager.get_icon(tile_id),
                                     None,
                                     self.rng.choice(self.animation_adapters))
                new_glyph.setZValue(zorder_ornament)
                new_glyph.setPos(location[0] * 32, location[1] * 32)
                scene.addItem(new_glyph)
            for item in tile['\ufdd0:items']:
                self.add_glyph(item, scene, zorder_item)
            for trap in tile['\ufdd0:traps']:
                self.add_glyph(trap, scene, zorder_trap)

        for creature in get_characters(self.current_level):
            self.add_glyph(creature, scene, zorder_character)
Exemplo n.º 13
0
    def decorate_level(self, level):
        """
        Decorate level

        :param level: level to decorate
        :type level: Level
        """
        empty_tile = self.configuration.empty_tile

        for loc, tile in list(get_tiles(level)):
            if tile['\ufdd0:wall'] == empty_tile:
                self.check_and_replace((loc[0] - 1, loc[1]), level)
                self.check_and_replace((loc[0] + 1, loc[1]), level)
                self.check_and_replace((loc[0], loc[1] - 1), level)
                self.check_and_replace((loc[0], loc[1] + 1), level)
                self.check_and_replace((loc[0] - 1, loc[1] - 1), level)
                self.check_and_replace((loc[0] - 1, loc[1] + 1), level)
                self.check_and_replace((loc[0] + 1, loc[1] - 1), level)
                self.check_and_replace((loc[0] + 1, loc[1] + 1), level)
Exemplo n.º 14
0
    def decorate_level(self, level):
        """
        Decorate level

        :param level: level to decorate
        :type level: Level
        """
        empty_tile = self.configuration.empty_tile

        for loc, tile in list(get_tiles(level)):
            if tile['\ufdd0:wall'] == empty_tile:
                self.check_and_replace((loc[0] - 1, loc[1]), level)
                self.check_and_replace((loc[0] + 1, loc[1]), level)
                self.check_and_replace((loc[0], loc[1] - 1), level)
                self.check_and_replace((loc[0], loc[1] + 1), level)
                self.check_and_replace((loc[0] - 1, loc[1] - 1), level)
                self.check_and_replace((loc[0] - 1, loc[1] + 1), level)
                self.check_and_replace((loc[0] + 1, loc[1] - 1), level)
                self.check_and_replace((loc[0] + 1, loc[1] + 1), level)