Beispiel #1
0
    def test_stair_linking(self):
        """
        Test that stairs can be linked
        """
        level1 = (LevelBuilder()
                  .with_size((20, 20))
                  .with_floor_tile(self.floor_rock)
                  .with_wall_tile(self.wall_empty)
                  .build())

        level2 = (LevelBuilder()
                  .with_size((20, 20))
                  .with_floor_tile(self.floor_rock)
                  .with_wall_tile(self.wall_empty)
                  .build())

        stairs1 = Portal((None, None), None)

        stairs1.icon = 'stairs'
        add_portal(level1, (10, 10), stairs1)

        stairs2 = Portal((None, None), None)
        add_portal(level2, (5, 5), stairs2, stairs1)

        assert(stairs1.level == level1)
        assert(stairs1.location == (10, 10))
        assert(stairs1.get_other_end() == stairs2)

        assert(stairs2.level == level2)
        assert(stairs2.location == (5, 5))
        assert(stairs2.get_other_end() == stairs1)

        assert get_portal(level1, (10, 10)) == stairs1
        assert get_portal(level2, (5, 5)) == stairs2
Beispiel #2
0
    def setup(self):
        """
        Setup the test case
        """
        self.character = (CharacterBuilder()
                          .with_model(Model())
                          .build())

        self.level1 = (LevelBuilder()
                       .with_floor_tile("floor")
                       .with_wall_at((1, 0))
                       .build())

        self.level2 = (LevelBuilder()
                       .with_floor_tile("floor")
                       .build())
        self.portal1 = Portal((None, None), None)

        self.portal1.icon = 1
        self.portal2 = Portal(("stairs", "stairs"), None)
        self.portal2 = Portal(("stairs", "stairs"), None)

        add_portal(self.level1, (5, 5), self.portal1)
        add_portal(self.level2, (10, 10), self.portal2, self.portal1)

        add_character(self.level1, (5, 5), self.character)

        set_action_factory(ActionFactoryBuilder()
                           .build())
Beispiel #3
0
    def test_stair_linking(self):
        """
        Test that stairs can be linked
        """
        level1 = (LevelBuilder()
                  .with_size((20, 20))
                  .with_floor_tile(self.floor_rock)
                  .with_wall_tile(self.wall_empty)
                  .build())

        level2 = (LevelBuilder()
                  .with_size((20, 20))
                  .with_floor_tile(self.floor_rock)
                  .with_wall_tile(self.wall_empty)
                  .build())

        stairs1 = Portal((None, None), None)

        stairs1.icon = 'stairs'
        add_portal(level1, (10, 10), stairs1)

        stairs2 = Portal((None, None), None)
        add_portal(level2, (5, 5), stairs2, stairs1)

        assert(stairs1.level == level1)
        assert(stairs1.location == (10, 10))
        assert(stairs1.get_other_end() == stairs2)

        assert(stairs2.level == level2)
        assert(stairs2.location == (5, 5))
        assert(stairs2.get_other_end() == stairs1)

        assert get_portal(level1, (10, 10)) == stairs1
        assert get_portal(level2, (5, 5)) == stairs2
    def test_taking_escape_stairs_ends_game(self):
        """
        Test that player taking escape stairs will create escape
        """
        model = self.character.model
        model.player = self.character

        portal3 = Portal((None, None), None)
        portal3.exits_dungeon = True
        add_portal(self.level1, (2, 2), portal3)
        self.character.location = (2, 2)

        pyherc.vtable['\ufdd0:move'](character=self.character,
                                     direction=Direction.enter)

        assert_that(model.end_condition, is_(equal_to(ESCAPED_DUNGEON)))
Beispiel #5
0
    def add_portal(self, level):
        """
        Add given stairs to the level

        :param level: level to modify
        :type level: Level
        """
        locations = [x for x in get_locations_by_tag(level, self.location_type)
                     if safe_passage(level, x)]

        if locations:
            location = self.rng.choice(locations)
            portal = Portal(icons=self.icons,
                            level_generator_name=self.level_generator_name)
            portal.exits_dungeon = self.escape_stairs
            add_portal(level, location, portal)
Beispiel #6
0
    def test_taking_escape_stairs_ends_game(self):
        """
        Test that player taking escape stairs will create escape
        """
        model = self.character.model
        model.player = self.character
        
        portal3 = Portal((None, None), None)
        portal3.exits_dungeon = True
        add_portal(self.level1, (2, 2), portal3)
        self.character.location = (2, 2)

        pyherc.vtable['\ufdd0:move'](character=self.character,
                                     direction=Direction.enter)

        assert_that(model.end_condition, is_(equal_to(ESCAPED_DUNGEON)))
Beispiel #7
0
    def add_portal(self, level):
        """
        Add given stairs to the level

        :param level: level to modify
        :type level: Level
        """
        locations = [
            x for x in get_locations_by_tag(level, self.location_type)
            if safe_passage(level, x)
        ]

        if locations:
            location = self.rng.choice(locations)
            portal = Portal(icons=self.icons,
                            level_generator_name=self.level_generator_name)
            portal.exits_dungeon = self.escape_stairs
            add_portal(level, location, portal)
    def setup(self):
        """
        Setup the test case
        """
        self.character = (CharacterBuilder().with_model(Model()).build())

        self.level1 = (LevelBuilder().with_floor_tile("floor").with_wall_at(
            (1, 0)).build())

        self.level2 = (LevelBuilder().with_floor_tile("floor").build())
        self.portal1 = Portal((None, None), None)

        self.portal1.icon = 1
        self.portal2 = Portal(("stairs", "stairs"), None)
        self.portal2 = Portal(("stairs", "stairs"), None)

        add_portal(self.level1, (5, 5), self.portal1)
        add_portal(self.level2, (10, 10), self.portal2, self.portal1)

        add_character(self.level1, (5, 5), self.character)

        set_action_factory(ActionFactoryBuilder().build())
Beispiel #9
0
def impl(context, portal_name, location_name):
    place = get_location(context, location_name)
    portal = get_location(context, portal_name)

    add_portal(place, (2, 2), portal, None)