当前位置: 首页>>代码示例>>Python>>正文


Python Data.loadPlanets方法代码示例

本文整理汇总了Python中Data.loadPlanets方法的典型用法代码示例。如果您正苦于以下问题:Python Data.loadPlanets方法的具体用法?Python Data.loadPlanets怎么用?Python Data.loadPlanets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Data的用法示例。


在下文中一共展示了Data.loadPlanets方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Main

# 需要导入模块: import Data [as 别名]
# 或者: from Data import loadPlanets [as 别名]
def Main():
    if (not os.path.isdir(CONFIGDIR)):
        os.mkdir(CONFIGDIR)
    if (not os.path.isdir(SAVEDIR)):
        os.mkdir(SAVEDIR)

    planets = Data.loadPlanets(CONFIGDIR+"coords_planets.txt")
    planet_names = list(planets.keys())
    reservedwords = ["zone", "d", "help"] + planet_names

    commands = Core.readconfigfile(CONFIGDIR+"words.ini")
    
    #make sure that dictionnary contains all used keys and for all keys, each required subdictionnary is given
    requiredkeys = {"map":[], "save":[], "target":["delallexplored","removeall"], "view":[], "exit":[], "set-terre":[]}
    errmsg = ""
    for key in requiredkeys:
        if (key not in commands):
            commands[key] = {"words":key}
            errmsg += "- section "+key+" non trouvée\n"
        elif ("words" not in commands[key]):
            commands[key]["words"] = key
            errmsg += "- aucun mot pour la commande "+key+"\n"
        for subkey in requiredkeys[key]:
            if (subkey not in commands[key]):
                commands[key][subkey] = subkey
                errmsg += "- paramètre manquant dans la commande "+key+": "+subkey+"\n"
    #
    #get set of words for each command (instead of space-separated string)
    #keep only non reserved words, but at least one
    for key in commands:
        for subkey in commands[key]:
            commands[key][subkey] = set(commands[key][subkey].split())
            size = len(commands[key][subkey])
            Core.removefromlist(commands[key][subkey], reservedwords)
            if (len(commands[key][subkey]) != size):
                if (subkey == "words"):
                    errmsg += "- des mots réservés ont été supprimés pour la commande "+key+"\n"
                else:
                    errmsg += "- des mots réservés ont été supprimés pour le paramètre "+subkey+" dans la commande "+key+"\n"
            if (len(commands[key][subkey]) == 0):
                if (subkey == "words"):
                    commands[key][subkey].add(key)
                    errmsg += "- aucun mot pour la commande "+key+"\n"
                else:
                    commands[key][subkey].add(subkey)
                    errmsg += "- paramètre manquant dans la commande "+key+": "+subkey+"\n"
    #
    #use some standard words to exit prompt
    exitwords_reserved = ("quit", "exit")
    for exit_word in exitwords_reserved:
        if (not exit_word in commands["exit"]["words"]):
            commands["exit"]["words"].add(exit_word)
    #
    if (len(errmsg) > 0):
        printf("Problème(s) lors de la lecture du fichier words.ini:")
        printf(errmsg)
    playername = ""
    if (len(sys.argv) >= 2):
        playername = sys.argv[1].strip().lower()
    if (Core.isforbidden(playername) or playername in exitwords_reserved):
        playername = raw_input("Entrez votre pseudo: ")
    playername = playername.strip().lower()
    if (Core.isforbidden(playername)):
        printf("Erreur: ce pseudo est interdit")
        sys.exit(0)
    elif (playername in exitwords_reserved):
        sys.exit(0)
    playerdata = Data.load(playername)
    settings = playerdata[2]
    if (playername not in settings):
        settings[playername] = {}
    settings = settings[playername]
    if ("terre" in settings):
        planet_names = addTerre(settings, settings["terre"].split(), planets)
    Str = ""
    Strlist = []
    printf('Tapez "help" pour obtenir de l\'aide')
    try:
        exit = False
        while (not exit and not Core.oneIn(commands["exit"]["words"], Strlist)):
            Str = raw_input("> ").strip().lower()
            if (Str == ""):
                continue
            Strlist = Str.split(" ")
            try:
                if (Core.oneIn(commands["exit"]["words"], Strlist)):
                    exit = True
                if ("help" in Strlist):
                    print_help(Strlist, commands, planet_names, playername)
                elif (Core.oneIn(commands["map"]["words"], Strlist)):
                    Map.makeMap(playername, playerdata, planets)
                elif (Core.oneIn(commands["save"]["words"], Strlist)):
                    Data.save(playername, playerdata)
                elif (Core.oneIn(commands["view"]["words"], Strlist)):
                    os.system(Map.getMapFilename(playername))
                elif (Core.oneIn(commands["target"]["words"], Strlist) and not exit):
                    printf('Entrez vos nouveaux objectifs:')
                    while (not Core.oneIn(commands["exit"]["words"], Strlist)):
                        Str = raw_input("==> ").strip().lower()
                        if (Str == ""):
#.........这里部分代码省略.........
开发者ID:Spirou003,项目名称:AlphaBounceMap,代码行数:103,代码来源:Main.py


注:本文中的Data.loadPlanets方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。