Exemple #1
0
def order_deal(flag='order', print_order=True):
    global __skip_flag__
    __skip_flag__ = False
    while True:
        time.sleep(0.01)
        while not IoInit._order_queue.empty():
            order = IoInit.getorder()
            if CacheContorl.flowContorl['quitGame']:
                os._exit(0)
                return
            if CacheContorl.flowContorl['restartGame'] == 1:
                CacheContorl.flowContorl['restartGame'] = 0
                reset_func()
                return
            if print_order == True and order != '':
                IoInit.print('\n' + order + '\n')

            if flag == 'str':
                return order

            if flag == 'console':
                # TODO add_console_method
                exec(order)

            if flag == 'order' and order.isdigit():
                if _cmd_valid(int(order)):
                    _cmd_deal(int(order))
                    return
                else:
                    global tail_deal_cmd_func
                    tail_deal_cmd_func(int(order))
                    return
Exemple #2
0
def order_deal(flag='order', print_order=True):
    '''
    处理命令函数
    Keyword arguments:
    flag -- 类型,默认为order,如果为console,这回执行输入得到的内容
    print_order -- 是否将输入的order输出到屏幕上
    '''
    global __skip_flag__
    __skip_flag__ = False
    while True:
        time.sleep(0.01)
        while not IoInit._order_queue.empty():
            order = IoInit.getorder()
            if CacheContorl.flowContorl['quitGame']:
                os._exit(0)
            if CacheContorl.flowContorl['restartGame'] == 1:
                CacheContorl.flowContorl['restartGame'] = 0
                reset_func()
                return
            if print_order == True and order != '':
                IoInit.eraPrint('\n' + order + '\n')
            if flag == 'str':
                if order.isdigit():
                    order = str(int(order))
                return order
            if flag == 'console':
                exec(order)
            if flag == 'order' and order.isdigit():
                if _cmd_valid(int(order)):
                    _cmd_deal(int(order))
                    return
                else:
                    global tail_deal_cmd_func
                    tail_deal_cmd_func(int(order))
                    return
Exemple #3
0
def pimage(imageName:str,imagePath=''):
    '''
    图片绘制在EraPrint中的封装
    Keyword arguments:
    imageName -- 图片id
    imagePath -- 图片所在路径 (default '')
    '''
    IoInit.imageprint(imageName, imagePath)
Exemple #4
0
def cmd_clear(*number):
    set_tail_deal_cmd_func(default_tail_deal_cmd_func)
    if number:
        for num in number:
            del cmd_map[num]
            IoInit.io_clear_cmd(num)
    else:
        cmd_map.clear()
        IoInit.io_clear_cmd()
Exemple #5
0
def run(main_func: 'function'):
    '''
    执行游戏主流程
    Keyword arguments:
    main_func -- 游戏主流程
    '''
    def _init():
        init(main_func)

    IoInit.run(_init)
Exemple #6
0
def print_cmd(cmd_str,
              cmd_number,
              cmd_func=null_func,
              arg=(),
              kw={},
              normal_style='standard',
              on_style='onbutton'):
    '''arg is tuple contain args which cmd_func could be used'''
    bind_cmd(cmd_number, cmd_func, arg, kw)
    IoInit.io_print_cmd(cmd_str, cmd_number, normal_style, on_style)
    return cmd_str
Exemple #7
0
def cmd_clear(*number):
    '''
    清楚绑定命令
    Keyword arguments:
    number -- 清楚绑定命令数字
    '''
    set_tail_deal_cmd_func(default_tail_deal_cmd_func)
    if number:
        for num in number:
            del cmd_map[num]
            IoInit.io_clear_cmd(num)
    else:
        cmd_map.clear()
        IoInit.io_clear_cmd()
Exemple #8
0
def init(main_flow):
    global def_style
    IoInit.clear_screen()
    IoInit.clearorder()
    FlowHandle.cmd_clear()
    # 事件载入
    Event.load_event_file()
    # 载入按键监听
    KeyListionEvent.onWFrameListion()
    # 设置背景颜色
    IoInit.set_background(GameData.gamedata()['core_cfg']['background_color'])
    # 初始化字体
    IoInit.init_style()
    # 初始化地图数据
    CacheContorl.mapData = GameData._gamedata[GameConfig.language]['map']
    CacheContorl.sceneData = GameData.sceneData
    CacheContorl.mapData = GameData.mapData
    FlowHandle.reset_func = reset
    global _main_flow
    _main_flow = main_flow

    _have_run = False

    def run_main_flow():
        nonlocal _have_run
        while True:
            if _have_run == False:
                main_flow()
                _have_run = True
            askfor_order()
            FlowHandle.call_default_flow()
            if FlowHandle.exit_flag == True:
                break

    run_main_flow()
Exemple #9
0
def print_cmd(cmd_str,
              cmd_number,
              cmd_func=null_func,
              arg=(),
              kw={},
              normal_style='standard',
              on_style='onbutton'):
    '''
    输出命令数字
    Keyword arguments:
    cmd_str -- 命令对应文字
    cmd_number -- 命令数字
    cmd_func -- 命令函数
    arg -- 传给命令函数的顺序参数
    kw -- 传给命令函数的字典参数
    normal_style -- 正常状态下命令显示样式
    on_style -- 鼠标在其上的时候命令显示样式
    '''
    bind_cmd(cmd_number, cmd_func, arg, kw)
    IoInit.io_print_cmd(cmd_str, cmd_number, normal_style, on_style)
    return cmd_str
Exemple #10
0
def p(string, style='standard'):
    barlist = TextLoading.getTextData(TextLoading.barConfigPath, 'barlist')
    styleList = RichText.setRichTextPrint(string, style)
    global last_char
    if len(string) > 0:
        last_char = string[-1:]
    string = RichText.removeRichCache(string)
    for i in range(0, len(string)):
        if styleList[i] in barlist:
            styledata = TextLoading.getTextData(TextLoading.barConfigPath,
                                                styleList[i])
            truebar = styledata['truebar']
            nullbar = styledata['nullbar']
            if string[i] == '0':
                pimage(nullbar, 'bar')
            elif string[i] == '1':
                pimage(truebar, 'bar')
            else:
                IoInit.print(string[i], styleList[i])
        else:
            IoInit.print(string[i], styleList[i])
Exemple #11
0
def p(string:str, style='standard',richTextJudge=True):
    '''
    游戏基础的文本绘制实现
    Keyword arguments:
    string -- 需要绘制的文本
    style -- 文本的默认样式 (default 'standard')
    richTextJudge -- 启用富文本的开关 (default True)
    '''
    if richTextJudge:
        barlist = TextLoading.getTextData(TextLoading.barConfigPath,'barlist')
        styleList = RichText.setRichTextPrint(string, style)
        global last_char
        if len(string) > 0:
            last_char = string[-1:]
        string = RichText.removeRichCache(string)
        string = r'' + string
        for i in range(0,len(string)):
            if styleList[i] in barlist:
                styledata = TextLoading.getTextData(TextLoading.barConfigPath,styleList[i])
                truebar = styledata['truebar']
                nullbar = styledata['nullbar']
                if string[i] == '0':
                    pimage(nullbar, 'bar')
                elif string[i] == '1':
                    pimage(truebar, 'bar')
                else:
                    IoInit.eraPrint(string[i], styleList[i])
            else:
                IoInit.eraPrint(string[i], styleList[i])
    else:
        IoInit.eraPrint(string,style)
Exemple #12
0
def reset():
    '''
    重启游戏
    '''
    global _main_flow
    IoInit.io_clear_cmd()
    IoInit.clear_screen()
    IoInit.clearorder()
    init(_main_flow)
Exemple #13
0
def askfor_All(list, print_order=False):
    while True:
        order = order_deal('str', print_order)
        if order in list:
            IoInit.eraPrint(order + '\n')
            return order
        elif order == '':
            continue
        else:
            IoInit.eraPrint(order + '\n')
            IoInit.eraPrint(
                TextLoading.getTextData(TextLoading.errorPath,
                                        'noInputListError') + '\n')
            continue
Exemple #14
0
def askfor_All(list, print_order=False):
    '''
    用于请求一个位于列表中的输入,如果输入没有在列表中,则告知用户出错。
    Keyword arguments:
    list -- 用于判断的列表内容
    print_order -- 是否将输入的order输出到屏幕上
    '''
    while True:
        order = order_deal('str', print_order)
        if order in list:
            IoInit.eraPrint(order + '\n')
            return order
        elif order == '':
            continue
        else:
            IoInit.eraPrint(order + '\n')
            IoInit.eraPrint(
                TextLoading.getTextData(TextLoading.errorPath,
                                        'noInputListError') + '\n')
            continue
Exemple #15
0
def pimage(imageName, imagePath=''):
    IoInit.imageprint(imageName, imagePath)
    pass
Exemple #16
0
def run(main_func):
    def _init():
        init(main_func)

    IoInit.run(_init)