コード例 #1
0
def render_name():

    # parse all *.cfg files in data/namegen
    for file in os.listdir(get_data('namegen')) :
        if file.find('.cfg') > 0 :
            libtcod.namegen_parse(get_data(os.path.join('namegen',file)))
    # get the sets list
    ng_sets=libtcod.namegen_get_sets()
    test_sets = ("Rogue Dungeon Rooms", "Rogue Names")

    for test_set in test_sets:
        print ("=" * 40)
        print(test_set)
        print ("=" * 40)
        for i in range(20):
            ng_names = libtcod.namegen_generate(test_set)
            print(ng_names)

    assert False

    for ng_set in ng_sets:
        print("="*40)
        print(f"{ng_set}")
        print("=" * 40)
        for i in range(10):
            ng_names = libtcod.namegen_generate(ng_set)
            print(ng_names)
コード例 #2
0
def test_namegen_parse():
    libtcodpy.namegen_parse('libtcod/data/namegen/jice_celtic.cfg')
    assert libtcodpy.namegen_generate('Celtic female')
    assert libtcodpy.namegen_get_sets()
    libtcodpy.namegen_destroy()
コード例 #3
0
def test_namegen_parse():
    libtcodpy.namegen_parse('libtcod/data/namegen/jice_celtic.cfg')
    assert libtcodpy.namegen_generate('Celtic female')
    assert libtcodpy.namegen_get_sets()
    libtcodpy.namegen_destroy()
コード例 #4
0
ファイル: engine.py プロジェクト: fanna/bgjs-worldbuilding
def main():
    screen_width = 80
    screen_height = 80

    player = Entity(int(screen_width / 2), int(screen_height / 2), 'x', libtcod.red, libtcod.black, ' ', 1.86, 36, 'X')

    entities = get_world() + [player]

    libtcod.console_set_custom_font('data/fonts/terminal12x12_gs_ro.png', libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_CP437)

    root_console = libtcod.console_init_root(screen_width, screen_height, 'BGJS: Worldbuilding', False, libtcod.RENDERER_SDL2, order="F")

    console = libtcod.console_new(screen_width, screen_height)

    key = libtcod.Key()
    mouse = libtcod.Mouse()
    for file in os.listdir("data/namegen"):
        if file.find(".cfg") > 0:
            libtcod.namegen_parse(os.path.join("data/namegen", file))
    sets = libtcod.namegen_get_sets()
    world_name = libtcod.namegen_generate(sets[0])

    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS, key, mouse)

        render_all(console, entities, screen_width, screen_height)

        libtcod.console_flush()

        clear_all(console, entities)

        action = handle_keys(key)

        move = action.get('move')
        exit = action.get('exit')
        fullscreen = action.get('fullscreen')

        if move:
            dx, dy = move
            player.move(dx, dy)
            #FIXME: This is super inefficient but it is a product of game jam
            for entity in entities:
                if (entity.info != ' '):
                    if (player.x == entity.x and player.y == entity.y):
                        console.print_frame(64, 0, 16, 64, '', True, 13)
                        console.print(65, 2, world_name, libtcod.sepia, libtcod.black, libtcod.LEFT)
                        console.print(65, 5, entity.char, entity.fg_color, entity.bg_color, libtcod.LEFT)
                        console.print(65, 7, entity.info, libtcod.white, libtcod.black, libtcod.LEFT)
                        console.print(65, 9, 'Height: ' + str(entity.height) + 'm', libtcod.white, libtcod.black, libtcod.LEFT)

                        console.print(65, 12, 'Temp: ' + str(entity.temp) + ' C', libtcod.white, libtcod.black, libtcod.LEFT)

                        console.print(65, 15, 'Magic Source:', libtcod.white, libtcod.black, libtcod.LEFT)
                        console.print(65, 17, entity.magic, entity.fg_color, entity.bg_color, libtcod.LEFT)
                        console.print(65, 20, book, entity.fg_color, libtcod.black, libtcod.LEFT)
                        console.print(65, 45, compass, libtcod.sepia, libtcod.black, libtcod.LEFT)

        if exit:
            return True

        if fullscreen:
            libtcod.console_set_fullscreen(not libtcod.console_is_fullscreen())
コード例 #5
0
ファイル: themes.py プロジェクト: kwoolter/roguelike
    def get_random_history(theme: str) -> str:
        """
        A method for generating some random Lore based on the specified theme
        :param theme: the theme of Lore that you want to generate e.g. Room, Person
        :return: a string with the generated name
        """

        # Templates for generating different types of Lore themes
        templates = {
            "Room": (["Dungeon Rooms"], None),
            "Floor": (["Dungeon Floors"], [" of "], [
                "Historic Figure Names Male", "Historic Figure Names Female",
                "Region", "Town"
            ]),
            "Place": (["Town", "Wonders"], [" in "], ["Region"]),
            "Name": ([
                "Character Male", "Character Female", "Fantasy Male",
                "Fantasy Female"
            ], None),
            "Person":
            (["Name"], [" of "], ["Town", "Region", "Wonders", "Place"]),
            "Quest":
            (["Historic Figure Names Male", "Historic Figure Names Female"], [
                " and the battle of ", " and the Siege of ",
                " and the Quest for ", " and the journey to ",
                " and the destruction of ", " and the decimation of ",
                " and how they found ", " and how they discovered "
            ], ["Town", "Region", "Treasures", "Wonders", "Place"]),
            "PvP": ([
                "Historic Figure Names Male", "Historic Figure Names Female",
                "Person"
            ], [
                " and the murder of ", " and the death of ",
                " and the unmarriage of ", " and the betrayal of ",
                " and the hunt for ", " and the alliance with ",
                " and the usurping of ", " and the torment of ",
                ", the loyal servant of ", ", the sworn enemy of "
            ], [
                "Historic Figure Names Male", "Historic Figure Names Female",
                "Person"
            ]),
            "Treasure": (["Treasures"], [" of "], [
                "Historic Figure Names Male", "Historic Figure Names Female",
                "Region", "Town", "Wonders"
            ]),
            "Book": (["'"], [
                "The missing pages of ", "The forgotten passages of ",
                "The ancient Lore of ", "The lessons of ",
                "A cautionary tale of ", "The Tale of ", "The Saga of ",
                "An allegory of ", "The writings of ", "The story of ",
                "The book of "
            ], [
                "Quest", "Place", "Historic Figure Names Male",
                "Historic Figure Names Female", "Treasure", "PvP"
            ], ["'"], [" by "], ["Person"])
        }

        assert theme in templates, f'Cannot find {theme} in history templates'

        # See what name generate sets we have loaded
        ng_sets = libtcod.namegen_get_sets()

        # Get the name of the template that we want to expand
        template = templates.get(theme)

        text = ""

        # Loop through each segment in the template
        for aa in template:

            # If None segment keep looping to the next one
            if aa is None:
                continue
            # Otherwise...
            else:
                # Pick a random item from the segment
                a = random.choice(aa)

                # If the segment a template?  If so recursive call to expand the template
                if a in templates:
                    a_text = ThemeManager.get_random_history(a)
                # If it is in out name generation sets that we loaded then generate a name of this type
                elif a in ng_sets:
                    a_text = libtcod.namegen_generate(a).title()
                # Else just use the segment text itself!
                else:
                    a_text = a

                # Add whatever text we ended up with to our full text
                text += a_text

        # Tidy up by removing any duplicate whitespace
        return " ".join(text.split())