TGC Codebase Backup



2d Recursive Maze Generator by Licaon

8th Oct 2003 16:20
Summary

Should work on Classic Recursive algorith to create 2d mazes



Description

No much to say, look at the code, it's quite plain



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    Rem Project: laberinto
Rem Created: 08/10/2003 03:06:28 p.m.

Rem ***** Main Source File *****

cls
global max=100
global may=100

dim lab(max,may)

laberinto(max,may)

wait key


function Laberinto (a,b)

randomize (255)

for x=1 to a
for y=1 to b
      lab(x,y)=0
next y
next x

pather(5,5)

text 300,0,"Listo"

endfunction

Function pather (estax, estay)

   se_acabo=0

   posibles$=""

   lab(estax,estay)=1

   for x=1 to max
   for y=1 to may
      if lab(x,y)=1 then box x*2,y*2,x*2+2,y*2+2
   next y
   next x

   if estax<max-1 then if lab(estax+2,estay)=0 then posibles$=posibles$+"6"
   if estax>2 then if lab(estax-2,estay)=0 then posibles$=posibles$+"4"
   if estay<may-1 then if lab(estax,estay+2)=0 then posibles$=posibles$+"2"
   if estay>2 then if lab(estax,estay-2)=0 then posibles$=posibles$+"8"

   if posibles$=""
         se_acabo=1
         exitfunction se_acabo
   endif

   a=rnd(len(posibles$))+1
   current$=mid$(posibles$,a)

   if current$="8"
            lab(estax,estay-1)=1
            estay=estay-2
   endif

   if current$="2"
            lab(estax,estay+1)=1
            estay=estay+2
   endif

   if current$="4"
            lab(estax-1,estay)=1
            estax=estax-2
   endif

   if current$="6"
            lab(estax+1,estay)=1
            estax=estax+2
   endif

   repeat

   until pather(estax,estay)=1

endfunction se_acabo