Exemple #1
0
def play_game():
    settings.player_action = None
    settings.mouse = libtcod.Mouse()
    settings.key = libtcod.Key()
    while not libtcod.console_is_window_closed():
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS |
                                    libtcod.EVENT_MOUSE,
                                    settings.key, settings.mouse)
        render_all()
        libtcod.console_flush()
        check_level_up()

        for object in settings.objects:
            object.clear()

        settings.player_action = handle_keys()
        if settings.player_action == 'exit':
            save_game()
            break

        if settings.game_state == 'playing' and \
           settings.player_action != 'didnt-take-turn':
            for object in settings.objects:
                if object.ai:
                    object.ai.take_turn()
Exemple #2
0
def target_tile(max_range=None):
    from render_all import render_all
    while True:
        libtcod.console_flush()
        libtcod.sys_check_for_event(libtcod.EVENT_KEY_PRESS |
                                    libtcod.EVENT_MOUSE, settings.key,
                                    settings.mouse)
        render_all()

        (x, y) = (settings.mouse.cx, settings.mouse.cy)

        if settings.mouse.rbutton_pressed or \
           settings.key.vk == libtcod.KEY_ESCAPE:
            return (None, None)

        if (settings.mouse.lbutton_pressed and
            libtcod.map_is_in_fov(settings.fov_map, x, y) and
            (max_range is None or
             settings.player.distance(x, y) <= max_range)):
            return (x, y)