def drawmap(playername, explorations, coords, target, xmin, xmax, ymin, ymax, colors, draworder, axescolor): image = createimage(xmax-xmin+1, ymax-ymin+1, colors["background"]["default"]) #draw explorations for (x, y) in explorations: color = None if ((x, y) in target): color = colors["background"]["ontarget"] else: color = colors["background"]["onexplore"] setpixel(image, x-xmin, y-ymin, color) #draw entities (planets, asteroids, ...) for key in draworder: if (key in coords): drawlist(coords[key], image, xmin, xmax, ymin, ymax, colors[key], explorations, target) #draw each remaining target target_copy = target.copy() for key in coords: Core.removefromlist(target_copy, coords[key]) Core.removefromlist(target_copy, explorations) color = colors["background"]["ontarget"] for (x, y) in target_copy: setpixel(image, x-xmin, y-ymin, color) drawgrid(image, axescolor, xmin, xmax, ymin, ymax) save(image, getMapFilename(playername))
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 == ""): continue Strlist = Str.split(" ") if ("help" in Strlist): printf("Vous êtes dans le mode d'édition des objectifs.") printf("Dans ce mode, les commandes disponibles sont les suivantes:") printf("- afficher ce message (tapez \"help\")") printf("- revenir au mode d'exploration: tapez l'un des mots suivants: "+printwords(commands["exit"]["words"])) printf('- tapez "x y" pour marquer le secteur aux coordonnées (x, y) comme objectif.') printf('- tapez "zone x1 y1 x2 y2" pour marquer comme objectif chaque secteur situé dans le rectangle décrit par les coordonnées (x1, y1) et (x2, y2).') printf("- entrez le nom d'une planète pour marquer chacun de ses secteurs comme objectif.") printf('- liste des planètes: '+printwords(planet_names)) printf('- dans les commandes précédentes, l\'option "d" a pour effet de supprimer un/des secteur(s) de la liste des objectifs.') printf("- vider la liste des objectifs, tapez l'un des mots suivants: "+printwords(commands["target"]["removeall"])) printf("- retirer tout secteur exploré de la liste des objectifs, tapez l'un des mots suivants: "+printwords(commands["target"]["delallexplored"])) elif (Core.oneIn(commands["target"]["removeall"], Strlist)): Data.cleartargets(playerdata) elif (Core.oneIn(commands["target"]["delallexplored"], Strlist)): Data.cleantargets(playerdata) elif (Core.oneIn(commands["exit"]["words"], Strlist)): pass #nothing to do else: (coords, explore) = parsecoords(Str, Strlist, planet_names, planets) if (explore): Data.addtarget(playerdata, coords) else: Data.deltarget(playerdata, coords) Strlist = [] #don't exit immediately after that elif (Core.oneIn(commands["set-terre"]["words"], Strlist) and not exit): printf('Entrez les coordonnées de votre terre:') while (not Core.oneIn(commands["exit"]["words"], Strlist)): Str = raw_input("==> ").strip().lower() if (Str == ""): continue Strlist = Str.split(" ") if ("help" in Strlist): printf("Vous êtes dans le mode d'édition de la terre.") printf("Dans ce mode, les commandes disponibles sont les suivantes:") printf("- afficher ce message (tapez \"help\")") printf("- revenir au mode d'exploration: tapez l'un des mots suivants: "+printwords(commands["exit"]["words"])) printf("- indiquer l'emplacement de la terre: tapez \"x y\" en remplaçant x et y par les coordonnées indiquées par la carte PID") elif (Core.oneIn(commands["exit"]["words"], Strlist)): pass #nothing to do else: (coords, explore) = parsecoords(Str, Strlist, planet_names, planets) if (len(coords) != 1): printf("Indiquez les coordonnées écrites sur la carte PID") else: planet_names = addTerre(settings, coords[0], planets) break Strlist = [] #don't exit immediately after that elif (Core.oneIn(commands["exit"]["words"], Strlist)): pass #nothing to do else: (coords, explore) = parsecoords(Str, Strlist, planet_names, planets) if (explore): Data.explore(playerdata, coords) else: Data.unexplore(playerdata, coords) except Exception as e: traceback.print_exc() except KeyboardInterrupt as e: pass except Exception as e: traceback.print_exc()