Пример #1
0
def test_console_rexpaint_list_save_load(console, tmpdir):
    con1 = libtcodpy.console_new(8, 2)
    con2 = libtcodpy.console_new(8, 2)
    libtcodpy.console_print(con1, 0, 0, 'hello')
    libtcodpy.console_print(con2, 0, 0, 'world')
    xp_file = tmpdir.join('test.xp').strpath
    assert libtcodpy.console_list_save_xp([con1, con2], xp_file, 1)
    for a, b in zip([con1, con2], libtcodpy.console_list_load_xp(xp_file)):
        assertConsolesEqual(a, b)
        libtcodpy.console_delete(a)
        libtcodpy.console_delete(b)
Пример #2
0
def test_console_rexpaint_list_save_load(console, tmpdir):
    con1 = libtcodpy.console_new(8, 2)
    con2 = libtcodpy.console_new(8, 2)
    libtcodpy.console_print(con1, 0, 0, 'hello')
    libtcodpy.console_print(con2, 0, 0, 'world')
    xp_file = tmpdir.join('test.xp').strpath
    assert libtcodpy.console_list_save_xp([con1, con2], xp_file, 1)
    for a, b in zip([con1, con2], libtcodpy.console_list_load_xp(xp_file)):
        assertConsolesEqual(a, b)
        libtcodpy.console_delete(a)
        libtcodpy.console_delete(b)
Пример #3
0
def display_manual():
    """displays the game's manual"""

    width = cfg.SCREEN_WIDTH
    height = cfg.SCREEN_HEIGHT
    padding_x = 4
    break_point = 4  # distance to page end at which to break the page

    with open('resources/manual.txt') as manfile:
        pages = [
            dynamic_wrap(page, max_width=width - padding_x)
            for page in re.split(r'<page\s\d>', manfile.read())
            if len(page) > 0
        ]
        for page in pages:
            if page[0] == ' ':
                del page[
                    0]  # cleanup required as re.split creates an empty string for each match which translates to an empty line at the beginning of each page from the second on

    p_i = 0  # page index
    line = 0  # what line to display

    while True:
        window = draw_manual_page(pages, p_i, line, width, height, break_point)

        wait_for = [
            tcod.KEY_KP4, tcod.KEY_KP6, tcod.KEY_KP2, tcod.KEY_KP8,
            tcod.KEY_LEFT, tcod.KEY_RIGHT, tcod.KEY_UP, tcod.KEY_DOWN
        ]  # todo scrolling up/down
        choice = menu_loop(wait_for=wait_for)

        tcod.console_delete(window)  # Remove the old window on page change

        if choice is None:
            break

        if choice in [tcod.KEY_LEFT, tcod.KEY_KP4]:
            p_i -= 1
            line = 0
            if p_i < 0:
                p_i = len(pages) - 1
        elif choice in [tcod.KEY_KP6, tcod.KEY_RIGHT]:
            p_i += 1
            line = 0
            if p_i >= len(pages):
                p_i = 0
        elif choice in [tcod.KEY_DOWN, tcod.KEY_KP2]:
            if (len(pages[p_i]) - line > height - break_point):
                line += 1
        elif choice in [tcod.KEY_UP, tcod.KEY_KP8]:
            line = max(0, line - 1)
Пример #4
0
 def close(self):
     ##do not inherit
     libtcod.console_delete(self.console)
Пример #5
0
 def __exit__(self, type, value, traceback):
     if self.graphics is not None:
         tcod.console_delete(self.graphics.root_console)
Пример #6
0
def close():
    GAME = None
    T.console_delete(CON_MAP)
    T.console_delete(CON_BUFFER)
    T.console_delete(CON_STATUS)
    T.console_delete(CON_INV)
Пример #7
0
                  xp_loader.transparent_cell_back_b))

####################
# libtcod piping to actually put the console layers on screen. This will probably change quite a bit for your actual usage of libtcod
####################

draw_layers = False

while not libtcod.console_is_window_closed():

    key = libtcod.console_check_for_keypress()
    if key.vk == libtcod.KEY_ESCAPE:
        break  #exit game

    if key.c == ord('a'):
        draw_layers = not draw_layers

    libtcod.console_clear(0)
    libtcod.console_blit(layer_0_console, 0, 0,
                         xp_data['layer_data'][0]['width'],
                         xp_data['layer_data'][0]['height'], 0, 0, 0)

    if draw_layers:
        libtcod.console_blit(layer_1_console, 0, 0,
                             xp_data['layer_data'][1]['width'],
                             xp_data['layer_data'][1]['height'], 0, 0, 0)
    libtcod.console_flush()

libtcod.console_delete(layer_0_console)
libtcod.console_delete(layer_1_console)
Пример #8
0
 def __del__(self):
     if self._c:
         tcod.console_delete(self._c)
Пример #9
0
 def __del__(self):
     if self._c:
         tcod.console_delete(self._c)