Forum Liberty Basic France
• Index
Coucou,
Voila le code du générateur de labyrinthe que j'ai retrouvé !!
Il est pas commenté et je suis sur qu'on peut le coder en moins de ligne, mais il permet de générer des grilles de labyrinthe et de les sauvegarder dans un fichier bmp.
Bon, la grille en elle même est super moche car les mur et les chemins ont un pixel de large seulement ^^
Code VB :
Voila le code du générateur de labyrinthe que j'ai retrouvé !!
Il est pas commenté et je suis sur qu'on peut le coder en moins de ligne, mais il permet de générer des grilles de labyrinthe et de les sauvegarder dans un fichier bmp.
Bon, la grille en elle même est super moche car les mur et les chemins ont un pixel de large seulement ^^
Code VB :
taille=128 WindowWidth = taille+50 WindowHeight = taille + 51 UpperLeftX = (DisplayWidth - WindowWidth) / 2 UpperLeftY = (DisplayHeight - WindowHeight) / 2 'nomainwin open "" for graphics_nsb as #1 #1, "trapclose [q]" #1, "down" choix = 0 indice = 0 ctn = 1 x = 1 y = 1 #1, "backcolor black; boxfilled ";taille+2;" ";taille+2;"; color white; set ";x;" ";y;"; flush" dim labyIndice(taille,taille) dim labyChoix(taille,taille) dim labyVisite(taille,taille) for i=1 to taille for j =1 to taille labyIndice(i,j) = -1 labyChoix(i,j) = -1 labyVisite(i,j) = 0 next next labyVisite(x,y) = 1 labyIndice(x,y) = indice indice = indice+1 while ctn scan choix = 0 for i=-1 to 1 for j=-1 to 1 if abs(i) <> abs(j) and x+2*i > 0 and x+2*i <= taille and y+2*j > 0 and y+2*j <= taille then if labyVisite(x+2*i, y+2*j) = 0 then choixX(choix) = x+2*i choixY(choix) = y+2*j choix = choix+1 end if end if next next labyChoix(x,y) = choix if choix <> 0 then nmChoix = int(rnd(0) * choix) labyVisite((choixX(nmChoix)+x)/2, (choixY(nmChoix)+y)/2) = 1 #1, "set ";(choixX(nmChoix)+x)/2;" ";(choixY(nmChoix)+y)/2;"; flush" x = choixX(nmChoix) y = choixY(nmChoix) #1, "set ";x;" ";y;"; flush" labyVisite(x,y) = 1 labyIndice(x,y) = indice indice = indice+1 else while labyChoix(x,y) < 2 and labyIndice(x,y) <> 0 scan choix = 0 for i = -1 to 1 for j = -1 to 1 if abs(i) <> abs(j) and x+2*i > 0 and x+2*i <= taille and y+2*j > 0 and y+2*j <= taille then if labyVisite(x+i, y+j) = 1 then choixX(choix) = x+2*i choixY(choix) = y+2*j choix = choix +1 end if end if next next x = choixX(0) y = choixY(0) for i = 1 to choix - 1 if labyIndice(x,y) > labyIndice(choixX(i), choixY(i)) then x = choixX(i) y = choixY(i) end if next wend end if if labyIndice(x,y) = 0 then ctn = 0 wend print "saving ..." #1, "getbmp laby 0 0 ";taille+1;" ";taille+1 bmpsave "laby", "laby.bmp" print "end" wait [q] close #1
• Index
1 Utilisateur en ligne : 0 Administrateur, 0 Modérateur, 0 Membre et 1 Visiteur
Utilisateur en ligne : Aucun membre connecté
Utilisateur en ligne : Aucun membre connecté
Répondre
Vous n'êtes pas autorisé à écrire dans cette catégorie