示例#1
0
def test_get_tile():
    level = Level(100, 100)
    coordinates = (10, 10)
    tile = Tile
    level.add_tile(coordinates, tile)

    assert isinstance(level.get_tile(coordinates), tile)
示例#2
0
def test_add_tile():
    level = Level(100, 100)
    coordinates = (10, 10)
    tile = Tile
    level.add_tile(coordinates, tile)

    assert isinstance(level.tiles[coordinates], tile)
示例#3
0
def test_add_object_with_location():
    level = Level(100, 100)
    coordinates = (10, 10)
    game_object = GameObject(name="Loc")
    game_object.register_component(components.Location())
    game_object.location.set_local_coords(coordinates)
    level.add_object(game_object)

    assert game_object in level.get_objects_by_coordinates(coordinates)
示例#4
0
def test_game_objects_property(game_objects):
    level = Level(100, 100)
    for game_object in game_objects:
        level.add_object(game_object)

    level_objects = level.game_objects

    assert level_objects
    for game_object in game_objects:
        assert game_object in level_objects
示例#5
0
def test_add_object_with_display():
    level = Level(100, 100)
    game_object = GameObject(name="Displayable")
    game_object.register_component(
        components.Display(Colors.DARK_RED,
                           Colors.BLACK,
                           '!',
                           priority=DisplayPriority.Item))
    level.add_object(game_object)

    assert game_object in level.displays[DisplayPriority.Item]
    for key, display_objects in level.displays.items():
        if key != DisplayPriority.Item:
            assert game_object not in display_objects
示例#6
0
def test_action_drop(sample_player, sample_weapon):
    backpack = ItemFactory.create_new(Backpack)
    bare_bones_equipment = components.Equipment(wear_locations=WearLocation,
                                                wield_locations=WieldLocation)
    bare_bones_equipment.wear(backpack)
    sample_player.unregister_component(sample_player.equipment)
    sample_player.register_component(bare_bones_equipment)
    level = Level(100, 100)
    level.add_object(sample_player)
    coordinates = sample_player.location.get_local_coords()
    sample_player.inventory.add(sample_weapon)
    actions.Drop.execute(sample_player, [sample_weapon])

    assert sample_weapon not in sample_player.inventory.get_all_items()
    assert sample_weapon in level.get_objects_by_coordinates(coordinates)
示例#7
0
    def generate(self):
        level = Level(self.game, 50, 50)
        for x in range(0, 50):
            for y in range(0, 50):
                level.add_tile((x, y), floors.Grass)

        self.ally_faction = Faction("Ally")
        enemy_faction = Faction("Enemy")
        self.ally_faction.add_enemy_faction(enemy_faction)
        enemy_faction.add_enemy_faction(self.ally_faction)

        self.place_allies(level, self.ally_faction)
        self.place_enemies(level, enemy_faction)
        self.place_neutrals(level)

        return level
def test_prepare_spawn_grid_use_coordinates(generator):
    new_level = Level(10, 10)
    spawn_grid = generator._prepare_spawn_grid(new_level)

    for coordinate in spawn_grid:
        x, y = coordinate
        assert isinstance(coordinate, tuple)
        assert isinstance(x, int)
        assert isinstance(y, int)
def test_fill_empty_spaces():
    class FilledGenerator(ConnectorBasedGenerator):
        filler_tile = floors.DungeonFloor

    level = Level(50, 50)
    rejected_tiles = (
        (1, 0),
        (2, 0),
        (20, 0),
        (29, 1),
        (38, 2),
    )
    FilledGenerator._fill_empty_tiles(level, rejected_tiles)

    filled_tiles = [level.get_tile(coord) for coord in rejected_tiles]
    assert len(filled_tiles) == len(rejected_tiles)
    for tile in filled_tiles:
        assert isinstance(tile, floors.DungeonFloor)
示例#10
0
def test_remove_tile():
    level = Level(100, 100)
    coordinates = (10, 10)
    tile = Tile
    level.add_tile(coordinates, tile)
    level.remove_tile(coordinates)

    assert level.get_tile(coordinates) is None
示例#11
0
def test_adjust_coordinates_for_object():
    level = Level(100, 100)
    coordinates = (10, 10)
    new_coordinates = (50, 50)
    game_object = GameObject(name="Loc")
    game_object.register_component(components.Location())
    game_object.location.set_local_coords(coordinates)
    level.add_object(game_object)
    level.adjust_coordinates_for_object(game_object, new_coordinates)

    assert game_object not in level.get_objects_by_coordinates(coordinates)
    assert game_object in level.get_objects_by_coordinates(new_coordinates)
def test_write_piece_with_no_origin(generator):
    level = Level(50, 50)
    spawn_grid = generator._prepare_spawn_grid(level)
    pointer_coordinate = (10, 20)
    unresolved_connectors = []

    generator._write_piece(level, TestPieceOneWithSpawner, spawn_grid,
                           pointer_coordinate, unresolved_connectors)

    assert len(level.rooms) == 1
    assert level.rooms[0].design_piece is TestPieceOneWithSpawner
    assert len(unresolved_connectors) == 1
    assert len(spawn_grid) == 2491
    assert len(level.game_objects) == 1
示例#13
0
    def generate(self):
        level = Level(100, 100)
        for x in range(0, 50):
            for y in range(0, 50):
                if x == 0 or y == 0 or x == 49 or y == 49:
                    level.add_tile((x, y), walls.DungeonWall)
                else:
                    level.add_tile((x, y), floors.DungeonFloor)

        self.place_monster(level)
        self.place_magic_chest(level)
        self.place_trapped_floor(level)

        return level
示例#14
0
    def generate(self):
        level = Level(self.game, 50, 50)
        super()._generate(level)
        self.place_exit_stairs_temp(self.game, level)

        return level
def test_get_center_coordinate(generator):
    level = Level(100, 100)
    x, y = generator._get_center_coordinate(level)

    assert x == 50
    assert y == 50
def test_prepare_spawn_grid_has_correct_size(generator):
    new_level = Level(10, 10)
    spawn_grid = generator._prepare_spawn_grid(new_level)

    assert len(spawn_grid) == 100