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_stair_linking(self): """ Test that stairs can be linked """ level1 = Level([20, 20], self.floor_rock, self.wall_empty) level2 = Level([20, 20], self.floor_rock, self.wall_empty) stairs1 = Portal((None, None), None) #TODO: beak link stairs1.icon = 200 level1.add_portal(stairs1, (10, 10)) stairs2 = Portal((None, None), None) level2.add_portal(stairs2, (5, 5), stairs1) assert(stairs1.level == level1) assert(stairs1.location == (10, 10)) assert(stairs1.other_end == stairs2) assert(stairs2.level == level2) assert(stairs2.location == (5, 5)) assert(stairs2.other_end == stairs1) assert(stairs1 in level1.portals) assert(stairs2 in level2.portals)
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)))
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 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())
def impl(context, portal_name): portal = Portal(icons=[100, 101], level_generator_name='empty') portal.name = portal_name context.places.append(portal)