05-28-2006, 09:31 AM
it probably could be cleaned up!
or made better!
but it works! and has many possibilities!
or made better!
but it works! and has many possibilities!
Code:
randomize timer
dim shared halls(0 to 15)as string
'-----------MAZE SIZE---------------
MazeX=89
MazeY=89
dim shared maze(0 to MazeX,0 to MazeY)
'-----------------------------------
screen 20,32
screenres 1024,768,32,,1
'---------Defines ASCII code----------
halls(0)=chr$(205)
halls(1)=chr$(186)
halls(2)=chr$(201)
halls(3)=chr$(187)
halls(4)=chr$(200)
halls(5)=chr$(188)
halls(6)=chr$(203)
halls(7)=chr$(185)
halls(8)=chr$(202)
halls(9)=chr$(204)
halls(10)=chr$(206)
halls(11)=chr$(210)
halls(12)=chr$(181)
halls(13)=chr$(208)
halls(14)=chr$(198)
halls(15)=" "
for i=0 to MazeX
for ii=0 to MazeY
maze(i,ii)=15
next ii
next i
'------------------------------------
'-------------STARTS MAZE LOOP-------
do:
f=6
count=count+1
g=0
i=0:ii=0
'------------------Figures Start Point and adjusts the Maze-------
do:
if maze(i,ii)=15 and g=0 then
if i=0 and ii=0 then f=1:g=1:x=i:y=ii
if g=0 and ii>0 and maze(i,ii-1)=0 then maze(i,ii-1)=6:f=2:x=i:y=ii:g=1
if g=0 and ii>0 and maze(i,ii-1)=4 then maze(i,ii-1)=9:f=2:x=i:y=ii:g=1
if g=0 and ii>0 and maze(i,ii-1)=5 then maze(i,ii-1)=7:f=2:x=i:y=ii:g=1
if g=0 and ii>0 and maze(i,ii-1)=8 then maze(i,ii-1)=10:f=2:x=i:y=ii:g=1
if g=0 and ii>0 and maze(i,ii-1)=12 then maze(i,ii-1)=3:f=2:x=i:y=ii:g=1
if g=0 and ii>0 and maze(i,ii-1)=14 then maze(i,ii-1)=2:f=2:x=i:y=ii:g=1
if g=0 and ii>0 and maze(i,ii-1)=13 then maze(i,ii-1)=1:f=2:x=i:y=ii:g=1
if g=0 and ii<MazeY and maze(i,ii+1)=0 then maze(i,ii+1)=8:f=0:x=i:y=ii:g=1
if g=0 and ii<MazeY and maze(i,ii+1)=2 then maze(i,ii+1)=9:f=0:x=i:y=ii:g=1
if g=0 and ii<MazeY and maze(i,ii+1)=3 then maze(i,ii+1)=7:f=0:x=i:y=ii:g=1
if g=0 and ii<MazeY and maze(i,ii+1)=6 then maze(i,ii+1)=10:f=0:x=i:y=ii:g=1
if g=0 and ii<MazeY and maze(i,ii+1)=11 then maze(i,ii+1)=1:f=0:x=i:y=ii:g=1
if g=0 and ii<MazeY and maze(i,ii+1)=12 then maze(i,ii+1)=5:f=0:x=i:y=ii:g=1
if g=0 and ii<MazeY and maze(i,ii+1)=14 then maze(i,ii+1)=4:f=0:x=i:y=ii:g=1
if g=0 and i>0 and maze(i-1,ii)=1 then maze(i-1,ii)=9:f=1:x=i:y=ii:g=1
if g=0 and i>0 and maze(i-1,ii)=3 then maze(i-1,ii)=6:f=1:x=i:y=ii:g=1
if g=0 and i>0 and maze(i-1,ii)=5 then maze(i-1,ii)=8:f=1:x=i:y=ii:g=1
if g=0 and i>0 and maze(i-1,ii)=7 then maze(i-1,ii)=10:f=1:x=i:y=ii:g=1
if g=0 and i>0 and maze(i-1,ii)=11 then maze(i-1,ii)=2:f=1:x=i:y=ii:g=1
if g=0 and i>0 and maze(i-1,ii)=12 then maze(i-1,ii)=0:f=1:x=i:y=ii:g=1
if g=0 and i>0 and maze(i-1,ii)=13 then maze(i-1,ii)=4:f=1:x=i:y=ii:g=1
if g=0 and i<MazeX and maze(i+1,ii)=1 then maze(i+1,ii)=7:f=1:x=i:y=ii:g=1
if g=0 and i<MazeX and maze(i+1,ii)=2 then maze(i+1,ii)=6:f=1:x=i:y=ii:g=1
if g=0 and i<MazeX and maze(i+1,ii)=4 then maze(i+1,ii)=8:f=1:x=i:y=ii:g=1
if g=0 and i<MazeX and maze(i+1,ii)=9 then maze(i+1,ii)=10:f=1:x=i:y=ii:g=1
if g=0 and i<MazeX and maze(i+1,ii)=11 then maze(i+1,ii)=3:f=1:x=i:y=ii:g=1
if g=0 and i<MazeX and maze(i+1,ii)=13 then maze(i+1,ii)=5:f=1:x=i:y=ii:g=1
if g=0 and i<MazeX and maze(i+1,ii)=14 then maze(i+1,ii)=0:f=1:x=i:y=ii:g=1
end if
i=i+1
if i=MazeX+1 Then i=0:ii=ii+1
loop until ii=MazeY+1 or g=1
'----------------------Figures next spot in the maze-------------
do:
if f=1 then
o=int(rnd*5)
if o=0 then if x+1=MazeX+1 or maze(x+1,y)<>15 then maze(x,y)=12 else maze(x,y)=0:f=1:x=x+1
if o=1 then if y+1=MazeY+1 or maze(x,y+1)<>15 then maze(x,y)=12 else maze(x,y)=3:f=2:y=y+1
if o=2 then if y-1=-1 or maze(x,y-1)<>15 then maze(x,y)=12 else maze(x,y)=5:f=0:y=y-1
if o=3 then if x+1=MazeX+1 or maze(x+1,y)<>15 then maze(x,y)=12 else maze(x,y)=0:f=1:x=x+1
if o=4 then if y+1=MazeY+1 or maze(x,y+1)<>15 then maze(x,y)=12 else maze(x,y)=3:f=2:y=y+1
if maze(x,y)=12 then
g=0 'trys to find
if maze(x+1,y)=15 and x<MazeX then maze(x,y)=0:f=1:x=x+1:g=1 'an alternate
if g=0 and y>0 and maze(x,y-1)=15 then maze(x,y)=5:f=0:y=y-1:g=1 'route instead
if g=0 and y<MazeY and maze(x,y+1)=15 then maze(x,y)=3:f=2:y=y+1:g=1 'of a random
if g=0 then f=5:x=0:y=0 'dead end
end if
end if
if f=2 then
o=int(rnd*5)
if o=0 then if y+1=MazeY+1 or maze(x,y+1)<>15 then maze(x,y)=13 else maze(x,y)=1:f=2:y=y+1
if o=1 then if x+1=MazeX+1 or maze(x+1,y)<>15 then maze(x,y)=13 else maze(x,y)=4:f=1:x=x+1
if o=2 then if x-1=-1 or maze(x-1,y)<>15 then maze(x,y)=13 else maze(x,y)=5:f=3:x=x-1
if o=3 then if x-1=-1 or maze(x-1,y)<>15 then maze(x,y)=13 else maze(x,y)=5:f=3:x=x-1
if o=4 then if x+1=MazeX+1 or maze(x+1,y)<>15 then maze(x,y)=13 else maze(x,y)=4:f=1:x=x+1
if maze(x,y)=13 then
g=0
if maze(x+1,y)=15 and x<MazeX then maze(x,y)=4:f=1:x=x+1:g=1
if g=0 and x>0 and maze(x-1,y)=15 then maze(x,y)=5:f=3:x=x-1:g=1
if g=0 and y>0 and maze(x,y-1)=15 then maze(x,y)=1:f=2:y=y-1:g=1
if g=0 then f=5:x=0:y=0
end if
end if
if f=3 then
o=int(rnd*5)
if o=0 then if x-1=-1 or maze(x-1,y)<>15 then maze(x,y)=14 else maze(x,y)=0:f=3:x=x-1
if o=1 then if y+1=MazeY+1 or maze(x,y+1)<>15 then maze(x,y)=14 else maze(x,y)=2:f=2:y=y+1
if o=2 then if y-1=-1 or maze(x,y-1)<>15 then maze(x,y)=14 else maze(x,y)=4:f=0:y=y-1
if o=3 then if x-1=-1 or maze(x-1,y)<>15 then maze(x,y)=14 else maze(x,y)=0:f=3:x=x-1
if o=4 then if y+1=MazeY+1 or maze(x,y+1)<>15 then maze(x,y)=14 else maze(x,y)=2:f=2:y=y+1
if maze(x,y)=14 then
g=0
if maze(x-1,y)=15 and x>0 then maze(x,y)=0:f=3:x=x-1:g=1
if g=0 and y>0 and maze(x,y-1)=15 then maze(x,y)=4:f=0:y=y-1:g=1
if g=0 and y<MazeY and maze(x,y+1)=15 then maze(x,y)=2:f=2:y=y+1:g=1
if g=0 then f=5:x=0:y=0
end if
end if
if f=0 then
o=int(rnd*5)
if o=0 then if y-1=-1 or maze(x,y-1)<>15 then maze(x,y)=11 else maze(x,y)=1:f=0:y=y-1
if o=1 then if x+1=MazeX+1 or maze(x+1,y)<>15 then maze(x,y)=11 else maze(x,y)=2:f=1:x=x+1
if o=2 then if x-1=-1 or maze(x-1,y)<>15 then maze(x,y)=11 else maze(x,y)=3:f=3:x=x-1
if o=0 then if y-1=-1 or maze(x,y-1)<>15 then maze(x,y)=11 else maze(x,y)=1:f=0:y=y-1
if o=4 then if x+1=MazeX+1 or maze(x+1,y)<>15 then maze(x,y)=11 else maze(x,y)=2:f=1:x=x+1
if maze(x,y)=11 then
g=0
if maze(x+1,y)=15 and x<MazeX then maze(x,y)=2:f=1:x=x+1:g=1
if g=0 and y>0 and maze(x,y-1)=15 then maze(x,y)=1:f=0:y=y-1:g=1
if g=0 and x>0 and maze(x-1,y)=15 then maze(x,y)=3:f=3:x=x-1:g=1
if g=0 then f=5:x=0:y=0
end if
end if
loop until f=5 or f=6
locate 10,40:?"LOADING"
loop until f=6
'-----------ADJUSTS THE LAST BLOCK FOR THE END---------
if maze(MazeX,MazeY)=5 then maze(MazeX,MazeY)=8
if maze(MazeX,MazeY)=12 then maze(MazeX,MazeY)=0
if maze(MazeX,MazeY)=13 then maze(MazeX,MazeY)=4
locate 10,40:?" "
'----SHOWS THE MAZE------------------------------------
Border_Color=rgb(200,100,100)
Maze_Color=rgb(100,200,100)
color Border_Color
for i=1 to MazeY+3
for ii=1 to MazeX+3
if (i=1 or i=MazeY+3) or (ii=1 or ii=MazeX+3) then locate i,ii:? chr$(178)
next ii
next i
color Maze_Color
locate 2,1:? halls(0)
locate MazeY+2,MazeX+3:? halls(0)
for i=0 to MazeX
for ii=0 to MazeY
if maze(i,ii)<> 15 then locate ii+2,i+2 :? halls(maze(i,ii))
next ii
next i
do:loop until inkey$<>""