Example #1
0
def creer_labyrinthe_depuis_chaine(chaine):
    elements = {}
    robot = 0
    lignes = chaine.split("\n")
    for ligne in enumerate(lignes):
        for char in enumerate(ligne[1]):
            if char[1] == "X":
                robot = (ligne[0], char[0])
                elements[(ligne[0], char[0])] = char[1]
            elif char[1] == 'U':
                sortie = (ligne[0], char[0])
                elements[(ligne[0], char[0])] = char[1]
            else:
                elements[(ligne[0], char[0])] = char[1]

        elements[(ligne[0], (char[0] + 1))] = "\n"

    return Labyrinthe(robot, elements, sortie)
Example #2
0
from Carte import Carte
from Labyrinthe import Labyrinthe
#si le joueur souhaite faire plusieur partie à la fois
while 1:
    partieEnCours = False
    nbCarte = 0
    choix = " "
    aGagner = False
    # On charge les cartes existantes
    cartes = utils.getMapFromDir("cartes")
    nbCarte = len(cartes)
    # on affiche le menu
    partieEnCour, index = utils.displayMenuMap(cartes)
    # on demande a l'utilisateur de choisir
    index = utils.getIndexFromChoice(nbCarte, partieEnCour, index)
    lab = Labyrinthe(cartes[index].labyrinthe)

    chemin = os.path.join("cartes", "last_save.txt")
    #une fois que le joueur a choisi sa carte,
    #on peut commencer a jouer

    while aGagner == False:
        #on affiche la carte
        print(lab)
        #on demande au joueur les actions a faire
        choix = utils.getChoice()
        #si le jouer ne souhaite pas quitter alors on la continue
        if choix[:1].lower() not in "q":
            #si le joueur a entrer un direction + une valeur
            if len(choix) > 1:
                #on separe la direction et le nb de deplacement a faire
Example #3
0
from Labyrinthe import Labyrinthe
from Labyrinthe.Pathfinder import Pathfinder
from Labyrinthe.Traducteur import Traducteur
from sys import argv

if __name__ == "__main__":

    if len(argv) == 1:
        lab1 = Labyrinthe(10, 10)
        lab1.generate(False)
    else:
        if argv[1] == "-h":
            print("help: python3 Labyrinthe.py [-h] | [-x (number) -y (number)] | [-step] | [-solve]")
            exit(0)

        if "-x" in argv:
            try:
                tailleX = int(argv[argv.index("-x") + 1])
            except ValueError:
                tailleX = 10
        else:
            tailleX = 10

        if "-y" in argv:
            try:
                tailleY = int(argv[argv.index("-y") + 1])
            except ValueError:
                tailleY = 10
        else:
            tailleY = 10
Example #4
0
"""

import os
import fonctions
import pickle
import sys

from fonctions import calc_deplac , sauvegarde_partie
from carte import Carte
from Labyrinthe import Labyrinthe

# On charge les cartes existantes
cartes = []
noms = []
laby = Labyrinthe(0,0,1)
for nom_fichier in os.listdir("cartes"):
	if nom_fichier.endswith(".txt"):
		chemin = os.path.join("cartes", nom_fichier)
		nom_carte = nom_fichier[:-4].lower()
		if nom_carte[0:5] == 'save_':
			print('Voulez vous rejouer la partie précédente ?')
			check = input('[y/n]')
			if check == 'y':
				with open(chemin, 'r') as fichier:
					contenu = fichier.read()
					carte = Carte(nom_carte, contenu)
					laby = carte.labyrinthe
					chemin_carte_ouverte = nom_carte[5:-4]
				os.remove(chemin)
			else:
                if y == ENNEMIE:
                    self.screen.create_oval(posX + LARGEUR / 3,
                                            posY + HAUTEUR / 3,
                                            posX + 2 * LARGEUR / 3,
                                            posY + 2 * HAUTEUR / 3,
                                            fill="black")

                posX += LARGEUR
            posX = 0
            posY += HAUTEUR

    def run(self):
        self.main.mainloop()


if __name__ == "__main__":
    lab = Labyrinthe(10, 30)
    lab.generate(False)
    trad = Traducteur(lab, lab.getDepart(), lab.getArrive())

    mot = Moteur(trad.getLabTrad())

    trad.addObserver(mot)

    trad.traduire()
    pathfinder = Pathfinder(trad.getDepart(), trad.getArrivee(), trad)
    pathfinder.findGoodPath()
    pathfinder.bindPath()

    mot.run()