Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
longest_string = max(all_strings, key=len)
width = min(len(longest_string), round(cfg.SCREEN_WIDTH // 3)) + padding_x * 2
if longest_string in options:
width += 4 # This accounts for the listing points (e.g. (1) <option>)
body_wrapped = dynamic_wrap(body, width - padding_x * 2) #if body != '' else []
# Calculate window height #
height = padding_y * 2 + len(body_wrapped)
if options:
height += len(options)
if body_wrapped:
height += 1 # gap between body-text and options
# Create the window #
window = tcod.console.Console(width, height)
# Print the body to the window #
y = padding_y
if body_wrapped:
for i, line in enumerate(body_wrapped):
print_string(window, padding_x, y, line)
y += 1
if line.count('\n') > 0:
y += 1
if options:
y += 1 # add a gap between body and options, if body exists
# Print options to the window #
if options:
letter_index = ord('a')
for i, option in enumerate(options):</option>
def test_console_str():
console = tcod.console.Console(10, 2)
console.print_(0, 0, "Test")
assert str(console) == ("")
def test_console_pickle():
console = tcod.console.Console(width=12, height=10)
console.ch[...] = ord('.')
console.fg[...] = (10, 20, 30)
console.bg[...] = (1, 2, 3)
console2 = pickle.loads(pickle.dumps(console))
assert (console.ch == console2.ch).all()
assert (console.fg == console2.fg).all()
assert (console.bg == console2.bg).all()
tcod.console_set_custom_font(
'terminal12x12_gs_ro.png',
tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_ASCII_INROW
)
with tcod.console_init_root(
screen_width,
screen_height,
'Roguelikedev2019',
order='F',
renderer=tcod.RENDERER_SDL2,
vsync=True
) as root_console:
con = tcod.console.Console(screen_width, screen_height, order='F')
game_map = GameMap(map_width, map_height, player)
game_map.load(make_sample_map(map_width, map_height))
#game_map.load(make_tutorial_map(map_width, map_height, max_rooms, room_min_size, room_max_size))
handler = Playing(game_map)
while True:
con.clear(fg=(255,255,255))
handler.update()
handler.render(con)
con.print(1, screen_height - 2, f'HP: {player.fighter.hp}/{player.fighter.max_hp}', (255,255,255), (0,0,0), tcod.BKGND_NONE, tcod.LEFT)
con.blit(root_console, 0, 0, 0, 0, screen_width, screen_height)
tcod.console_flush()
for event in tcod.event.wait():
handler.dispatch(event)
def initialize_window(game):
""" initializes everything relevant to game window """
# Consoles #
game.root = tcod.console_init_root(cfg.SCREEN_WIDTH, cfg.SCREEN_HEIGHT)
#game.root = tcod.console.Console(cfg.SCREEN_WIDTH, cfg.SCREEN_HEIGHT)
# game.con = tcod.console.Console(cons.SCREEN_WIDTH, cons.SCREEN_HEIGHT)
game.map_panel = tcod.console.Console(cons.MAP_SCREEN_WIDTH, cons.MAP_SCREEN_HEIGHT)
game.status_panel = tcod.console.Console(cons.BOTTOM_PANEL_WIDTH, cons.STATUS_BAR_HEIGHT)
game.top_right_panel = tcod.console.Console(cons.SIDE_PANEL_WIDTH, cons.PLAYER_PANEL_HEIGHT)
game.center_right_panel = tcod.console.Console(cons.SIDE_PANEL_WIDTH, cons.COMBAT_PANEL_HEIGHT)
game.lower_right_panel = tcod.console.Console(cons.SIDE_PANEL_WIDTH, cons.OBJECT_PANEL_HEIGHT)
game.bottom_left_panel = tcod.console.Console(cons.MSG_PANEL1_WIDTH, cons.BOTTOM_PANEL_HEIGHT)
game.bottom_center_panel = tcod.console.Console(cons.MSG_PANEL2_WIDTH, cons.BOTTOM_PANEL_HEIGHT)
def console_from_xp(filename: str) -> tcod.console.Console:
"""Return a single console from a REXPaint `.xp` file."""
return tcod.console.Console._from_cdata(
lib.TCOD_console_from_xp(filename.encode("utf-8"))
)
def initialize_window(game):
""" initializes everything relevant to game window """
# Consoles #
game.root = tcod.console_init_root(cfg.SCREEN_WIDTH, cfg.SCREEN_HEIGHT)
#game.root = tcod.console.Console(cfg.SCREEN_WIDTH, cfg.SCREEN_HEIGHT)
# game.con = tcod.console.Console(cons.SCREEN_WIDTH, cons.SCREEN_HEIGHT)
game.map_panel = tcod.console.Console(cons.MAP_SCREEN_WIDTH, cons.MAP_SCREEN_HEIGHT)
game.status_panel = tcod.console.Console(cons.BOTTOM_PANEL_WIDTH, cons.STATUS_BAR_HEIGHT)
game.top_right_panel = tcod.console.Console(cons.SIDE_PANEL_WIDTH, cons.PLAYER_PANEL_HEIGHT)
game.center_right_panel = tcod.console.Console(cons.SIDE_PANEL_WIDTH, cons.COMBAT_PANEL_HEIGHT)
game.lower_right_panel = tcod.console.Console(cons.SIDE_PANEL_WIDTH, cons.OBJECT_PANEL_HEIGHT)
game.bottom_left_panel = tcod.console.Console(cons.MSG_PANEL1_WIDTH, cons.BOTTOM_PANEL_HEIGHT)
game.bottom_center_panel = tcod.console.Console(cons.MSG_PANEL2_WIDTH, cons.BOTTOM_PANEL_HEIGHT)
def initialize_window(game):
""" initializes everything relevant to game window """
# Consoles #
game.root = tcod.console_init_root(cfg.SCREEN_WIDTH, cfg.SCREEN_HEIGHT)
#game.root = tcod.console.Console(cfg.SCREEN_WIDTH, cfg.SCREEN_HEIGHT)
# game.con = tcod.console.Console(cons.SCREEN_WIDTH, cons.SCREEN_HEIGHT)
game.map_panel = tcod.console.Console(cons.MAP_SCREEN_WIDTH, cons.MAP_SCREEN_HEIGHT)
game.status_panel = tcod.console.Console(cons.BOTTOM_PANEL_WIDTH, cons.STATUS_BAR_HEIGHT)
game.top_right_panel = tcod.console.Console(cons.SIDE_PANEL_WIDTH, cons.PLAYER_PANEL_HEIGHT)
game.center_right_panel = tcod.console.Console(cons.SIDE_PANEL_WIDTH, cons.COMBAT_PANEL_HEIGHT)
game.lower_right_panel = tcod.console.Console(cons.SIDE_PANEL_WIDTH, cons.OBJECT_PANEL_HEIGHT)
game.bottom_left_panel = tcod.console.Console(cons.MSG_PANEL1_WIDTH, cons.BOTTOM_PANEL_HEIGHT)
game.bottom_center_panel = tcod.console.Console(cons.MSG_PANEL2_WIDTH, cons.BOTTOM_PANEL_HEIGHT)
def sys_set_renderer(renderer: int) -> None:
"""Change the current rendering mode to renderer.
.. deprecated:: 2.0
RENDERER_GLSL and RENDERER_OPENGL are not currently available.
"""
_check(lib.TCOD_sys_set_renderer(renderer))
if tcod.console._root_console is not None:
tcod.console.Console._get_root()
# input handling setup
in_handle = InputHandler()
mouse_x = 0
mouse_y = 0
# set tcod font
tcod.console_set_custom_font(
"arial10x10.png",
tcod.FONT_TYPE_GREYSCALE | tcod.FONT_LAYOUT_TCOD
)
# set up ui elements
panel_ui = tcod.console.Console(constants["panel_ui_width"],
constants["panel_ui_height"])
panel_map = tcod.console.Console(constants["panel_map_width"],
constants["panel_map_height"])
main_menu_bg = tcod.image_load("menu_background1.png")
# open tcod console context
with tcod.console_init_root(
constants["screen_width"], constants["screen_height"],
constants["window_title"], fullscreen=False,
renderer=tcod.RENDERER_SDL2, vsync=False) as root_console:
while True:
if game_state == GameStates.MAIN_MENU:
in_handle.set_game_state(game_state)
main_menu(root_console, main_menu_bg,
constants["screen_width"],
constants["screen_height"])