MazeConnect v1.4 - puzzle prototype (iPad only)

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

MazeConnect v1.4 - puzzle prototype (iPad only)

Post by Dav »

This is a prototype of a maze puzzle game. Don't know how to describe it well. What you try to do is rotate the pieces by touching them, trying to make a maze all connect. THe top left maze piece will always be colored. When the other pieces connect to that one, then they will become colored too. When you make the whole maze connect and become colorized you win.

There are two programs posted here. 'MazeConnect.txt' is the game. 'MazeDesign.txt' is the maze designer you can use if you want to make your own mazes for the game.

- Dav

MazeConnect.txt v1.4 is below... (The game)
New for v1.4: Game board now only updates buttons that have been changed, greatly increasing screen updates on large grids and slower devices.

Code: Select all

'MazeConnect.txt v1.4 (ipad only)
'A Maze puzzle game prototype.
'Coded by Dav, OCT/2017

'You touch pieces to rotate them and connect them.
'Object is to make maze all connected and colorized.
'Top left is the first color one. Build from there.

'New for v1.4: New method of updating board pieces.
'              Only redraws buttons that have been
'              changed, not the whole board. This
'              makes gmae play MUCH faster on large
'              grids and on older devices.


if lowstr$(device_type$())<>"ipad" then
  print "Sorry, game for iPad only."
  end
end if


option base 1

graphics
graphics clear .3,.3,.3
set orientation top
set toolbar off

get screen size sw,sh

top:

grid=6'default to grid 6 (its level 1)
maxgrid=15 'last grid level so far (10 levels)

gosub titlemenu

'angle characters, right up, left up, etc
LD=9491!LU=9499!RD=9487!RU=9495!HZ=9473!VT=9475!BM=9724

'goto newlevel 'testing...
'load previous state if file exists
loaded=0 ! fil$="mazeconnect.dat"

if file_exists(fil$) then
  loaded=1
  file fil$ setpos 0
  file fil$ readline gr$
  grid=val(gr$)
end if

newlevel:

dim bv(grid*grid),bx(grid*grid),by(grid*grid),bc(grid*grid)
dim bc2(grid*grid)
size=sw/grid
mov =0

drawbackground
shadow on
draw color .8,.8,.8
t$="level="&(grid-5)
draw text t$ at sw/2-(text_width(t$)/2),sh/2-text_height(t$)
shadow off
pause 2

set buttons custom
set buttons font size size/2 'just for these buttons
draw color 0,0,0
fill color 1,.5,.5
button "quit" text "Quit" at 1,1
button "menu" text "Menu" at 1+text_width("Menu")-20,1
button "restart" text "Redo" at text_width("Redo")*2+20,1

set buttons font size size-2

'set button values, and x/y values...
bb=1
for r= 1 to grid
   for c = 1 to grid
     x=(r*size) ! y=(c*size)
     if rnd(grid*2)=grid then br =0
     bx(bb)=x-size!by(bb)=y
     if loaded=1 then
        file fil$ readline z$
        bv(bb)=val(z$)
     else
        bv(bb)=RD
     end if
     bc(bb)=0
     bc2(bb)=0
     bb=bb+1
   next c
next r

bc(1)=1 'turn on top left leader button
bc2(1)=1

if loaded=0 then
   setmaze 'set maze data, it's already scrambled up
end if

loaded=0
firstdraw=1
gosub updatebuttons

do 

   for b = 1 to (grid*grid)
    if button_pressed(str$(b)) then
       b2=bv(b) 'see what button it is
       'rotate right angles buttons
       if b2=RD then bv(b)=LD
       if b2=LD then bv(b)=LU
       if b2=LU then bv(b)=RU
       if b2=RU then bv(b)=RD
       'rotate horiz/vert lines
       if b2=HZ then bv(b)=VT
       if b2=VT then bv(b)=HZ
       'just redraw this button
        'fill color 1,1,1
        'button str$(b) text chr$(bv(b)) at bx(b),by(b) size size,size
       gosub updatebuttons

'now got to handle button we rotated in main loop
if bc(b)=1 then
   fill color .1,1,.3
else
   fill color 1,1,1
end if
button str$(b) text chr$(bv(b)) at bx(b),by(b) size size,size

       gosub checkforwin

    end if
   next b

   if button_pressed("quit") then
      gosub savestate
      end
   end if
   if button_pressed("menu") then
      button "quit" delete
      button "menu" delete
      button "restart" delete
      for e = 1 to grid*grid
        button str$(e) delete
      next e
      gosub savestate
      goto top
   end if
   if button_pressed("restart") then
     setmaze
     gosub updatebuttons
   end if

until 0

end

'============
updatebuttons:
'============

'first button always on
draw color 0,0,0
fill color .1,1,.3
button str$(1) text chr$(bv(1)) at bx(1),by(1) size size,size

'turn all off first,except 1st
for g=2 to grid*grid
  bc(g)=0
next g

'set leader button flow direction
if bv(1)=HZ then direction=1 'going right
if bv(1)=VT then direction=2 'going down

cur=1 'start with 1st button always

'do until can't flow anymore (direction blocked)
do 

  if direction=1 then 'heading right
    'see if already on the right edge of board
    'if so, it can't go right anymore, so end flow...
    for j=(.grid*.grid)-.grid+1 to .grid*.grid
       if cur=j then goto flowdone
    next j
    'now see if one to the right can connect with it.
    'if not connectable, end flow here.
    con=0 'default is not connectable
    nv=bv(cur+grid)
    if nv=HZ then con=1
    if nv=LU then con=1
    if nv=LD then con=1
    'if not, end flow here
    if con=0 then goto flowdone
    'looks like it is connectable, so turn it on
    bc(cur+grid)=1 'turn piece to the right on.
    'Make new pieve the new current flow position
    tc=(cur+grid)!cur=tc
    'find/set new direction based on that character
    if nv=HZ then direction=1 'right
    if nv=LU then direction=4 'up
    if nv=LD then direction=2 'down
  end if

  if direction=2 then 'heading down
    'see if this one is on the bottom edge
    for j=.grid to (.grid*.grid) step .grid
     if cur=j then goto flowdone
    next j
    'now see if new one can connect with this one.
    'if not, end flow here.
    con=0 'default is not connectable
    nv=bv(cur+1)
    if nv=VT then con=1
    if nv=LU then con=1
    if nv=RU then con=1
    'if not, end flow here
    if con=0 then goto flowdone
    'looks like it must be connectable
     bc(cur+1)=1 'turn the next piece on too
     'Make it the new current char position
     tc=(cur+1)!cur=tc
     'find/set new direction based on character
     if nv=LU then direction=3 'left
     if nv=RU then direction=1 'right
     if nv=VT then direction=2 'down
  end if

  if direction=3 then 'heading left
    'see if this one is on the bottom edge
    for j=1 to grid
     if cur=j then goto flowdone
    next j

    'now see if new one can connect with this one.
    'if not, end flow here.
    con=0 'default is not connectable
    nv=bv(cur-grid)
    if nv=HZ then con=1
    if nv=RU then con=1
    if nv=RD then con=1
    'if not, end flow here
    if con=0 then goto flowdone
    'looks like it must be connectable
     bc(cur-grid)=1 'turn the next piece on too
     'Make it the new current char position
     tc=(cur-grid)!cur=tc
     'find/set new direction based on character
     if nv=HZ then direction=3 'left
     if nv=RU then direction=4 'up
     if nv=RD then direction=2 'down
  end if

  if direction=4 then 'going up
    'see if this one is on the edge of board
    'if so, it can't go up, so end flow...
    for j = 1 to (.grid*.grid) step .grid
     if cur=j then goto flowdone
    next j
    'now see if new one can connect with this one.
    'if not, end flow here.
    con=0 'default is not connectable
    nv=bv(cur-1)
    if nv=VT then con=1
    if nv=LD then con=1
    if nv=RD then con=1
    'if not, end flow here
    if con=0 then goto flowdone
    'looks like it must be connectable
     bc(cur-1)=1 'turn the next piece on too
     'Make it the new current char position
     tc=(cur-1)!cur=tc
     'find/set new direction based on character
     if nv=VT then direction=4 'up
     if nv=LD then direction=3 'left
     if nv=RD then direction=1 'right
  end if
  
until 0

flowdone:

if firstdraw=0 then

'draw/colorize board
for t=2 to (grid*grid)
   if bc(t)=1 and bc2(t)=0 then
        fill color .1,1,.3
        button str$(t) text chr$(bv(t)) at bx(t),by(t) size size,size
   end if
   if bc(t)=0 and bc2(t)=1 then
        fill color 1,1,1
        button str$(t) text chr$(bv(t)) at bx(t),by(t) size size,size
   end if
next t

else

'draw/colorize board
for t=2 to (grid*grid)
   if bc(t)=1 then
     fill color .1,1,.3
   else
     fill color 1,1,1
   end if
   button str$(t) text chr$(bv(t)) at bx(t),by(t) size size,size
   'bc2(t)=bc(t)
next t

firstdraw=0

end if


'copy current color values
for t=1 to grid*grid
  bc2(t)=bc(t)
next t


'save state to file

savestate:

fil$="mazeconnect.dat"
if file_exists(fil$) then file fil$ delete
file fil$ print
file fil$ setpos 0
file fil$ writeline str$(grid)
for h=1 to grid*grid
   file fil$ writeline str$(bv(h))
next h

return


checkforwin:

all=0
for w=1 to (grid*grid)
  if bc(w)=1 then all=all+1
  if bv(w)=BM then all=all+1 'add blocks
next w

if all=(grid*grid) then
    
    'play song
     notes set "7:s(c3eg)(e4cg3)(g4ec)(c5g4e)"
     notes play

    pause 2

    button "quit" delete
    button "restart" delete
    button "menu" delete

    drawbackground

    t$="Good Job!"
    draw color .8,.8,.8
    draw text "Good Job!" at sw/2-(text_width(t$)/2),sh/2-text_height(t$)

    for h=1 to grid*grid
       button str$(h) delete
    next h
    pause 1.5

    grid=grid+1

    if grid>maxgrid then
      grid=maxgrid
    end if

    goto newlevel
end if

return


titlemenu:

graphics clear .3,.3,.3
drawbackground
shadow on
draw color .8,.8,.8
t$="MazeConnect"
draw font size 76
draw text t$ at sw/2-(text_width(t$)/2),text_height(t$)/2
t$="A puzzle game by Dav"
draw font size 36
draw text t$ at sw/2-(text_width(t$)/2),text_height(t$)*3
shadow off

draw color 1,1,.5
t$="HOW TO PLAY:"
draw text t$ at sw/2-(text_width(t$)/2),text_height(t$)*6
draw color .8,.8,.8
t$="Touch maze pieces to rotate."
draw text t$ at sw/2-(text_width(t$)/2),text_height(t$)*7
t$="Top left piece is always on."
draw text t$ at sw/2-(text_width(t$)/2),text_height(t$)*8
t$="When others connect they will"
draw text t$ at sw/2-(text_width(t$)/2),text_height(t$)*9
t$="turn on too.  Try to get the"
draw text t$ at sw/2-(text_width(t$)/2),text_height(t$)*10
t$="whole maze on and connected."
draw text t$ at sw/2-(text_width(t$)/2),text_height(t$)*11

'show current level
fil$="mazeconnect.dat"
if file_exists(fil$) then
   file fil$ setpos 0
   file fil$ readline f$
   ff=val(f$)-5
   t$="Current level: "&ff
else
   t$="Current level: "&str$(grid-5)
end if

draw color 1,1,1
draw text t$ at sw/2-(text_width(t$)/2),text_height(t$)*13

set buttons custom
set buttons font size 50
draw color 0,0,0
fill color 1,1,0
button "start" text "Start" at sw/2-90,sh/2+100
button "quit" text "Quit" at sw/2-80,sh/2+200
fill color .5,.5,.5
draw color 1,1,1
button "reset" text "Reset Game" at sw/2-180,sh/2+400

do
  if button_pressed("reset") then
   if file_exists(fil$) then file fil$ delete
   goto titlemenu
  end if
  if button_pressed("quit") then end
until button_pressed("start")

button "start" delete
button "reset" delete
button "quit" delete

return



def setmaze

if .grid=3 then
a$="" '3x3 MazeConnect grid
a$=a$&"hzrdru"
a$=a$&"hzhzhz"
a$=a$&"ldluld"
end if

if .grid=4 then
a$="" '4x4 MazeConnect grid
a$=a$&"vtvtruru"
a$=a$&"rdvtluhz"
a$=a$&"hzrdruhz"
a$=a$&"ldluldlu"
end if

 if .grid=5 then
   a$="" '5x5 MazeConnect grid
   a$=a$&"hzrdvtvtld"
   a$=a$&"hzhzrdrdhz"
   a$=a$&"hzhzldhzhz"
   a$=a$&"hzldvtluhz"
   a$=a$&"ldvtvtvtlu"
 end if

if .grid=6 then
a$="" '6x6 MazeConnect grid
a$=a$&"hzrdrurdvtru"
a$=a$&"hzhzhzhzrdlu"
a$=a$&"ldluhzhzldru"
a$=a$&"rdvtluhzbmhz"
a$=a$&"hzrdruldruhz"
a$=a$&"ldluldvtlulu"
end if

 if .grid=7 then
    a$=""'7x7 MazeConnect grid
    a$="vtruvtvtrurdru"
    a$=a$&"rdlurdruldluhz"
    a$=a$&"ldvtluldrurdlu"
    a$=a$&"rdvtrurdluldru"
    a$=a$&"ldruldlurdvtlu"
    a$=a$&"rdlurdruldvtru"
    a$=a$&"ldvtluldvtvtlu"
  end if

if .grid=8 then
  a$=""'8x8 MazeConnect grid
  a$=a$&"hzvtrurdrurdrubm"
  a$=a$&"hzbmldluhzhzldru"
  a$=a$&"ldvtrurdluhzrdlu"
  a$=a$&"rdvtluldvtluldru"
  a$=a$&"ldrurdvtrurdvtlu"
  a$=a$&"bmhzhzbmldlurdru"
  a$=a$&"rdluldvtvtvtluhz"
  a$=a$&"ldvtvtvtvtvtvtlu"
end if

if .grid=9 then
a$="" '9x9 MazeConnect grid
a$=a$&"hzrdvtvtrurdrurdru"
a$=a$&"hzldvtruldluldluhz"
a$=a$&"ldvtruldrubmrdvtlu"
a$=a$&"rdruldruldruldrubm"
a$=a$&"hzldruldruldruldru"
a$=a$&"ldruhzbmldruhzbmhz"
a$=a$&"rdluldvtvtluldruhz"
a$=a$&"hzrdrurdvtrurdluhz"
a$=a$&"ldluldlubmldluvtlu"
end if

if .grid=10 then
a$="" '10x10 MazeConnect grid
a$=a$&"vtvtvtrurdrurdvtrubm"
a$=a$&"hzrdvtluhzhzldruldru"
a$=a$&"hzldvtvtluldruhzrdlu"
a$=a$&"hzbmrdvtvtruldluldru"
a$=a$&"hzrdlurdruhzrdvtvtlu"
a$=a$&"hzhzrdluhzldlurdrubm"
a$=a$&"hzhzhzbmldrubmhzldru"
a$=a$&"hzldlurdruldvtlurdlu"
a$=a$&"hzrdruhzldrurdruldru"
a$=a$&"ldluldlubmldluldvtlu"
end if

if .grid=11 then
a$="" '11x11 MazeConnect grid
a$=a$&"hzvtrubmrdvtrubmrdvtru"
a$=a$&"ldruldruldruldruldruhz"
a$=a$&"bmldruldruldruldruhzhz"
a$=a$&"rdruldruldruldruldluhz"
a$=a$&"hzldruldruldruldrurdlu"
a$=a$&"ldruldruldruldruhzldru"
a$=a$&"bmldruldruldruldlurdlu"
a$=a$&"rdruldruldruldrurdlubm"
a$=a$&"hzldruldruldvtluldvtru"
a$=a$&"ldruldvtlurdrurdrurdlu"
a$=a$&"bmldvtvtvtluldluldlubm"
end if

if .grid=12 then
a$="" '12x12 MazeConnect grid
a$=a$&"vtvtrubmbmrdrurdrurdvtru"
a$=a$&"bmbmhzbmrdluldluhzhzrdlu"
a$=a$&"bmrdlurdlurdrurdluhzldru"
a$=a$&"rdlurdlurdluhzhzrdlurdlu"
a$=a$&"ldruldvtlurdluhzhzbmldru"
a$=a$&"bmldvtvtruhzbmldlurdvtlu"
a$=a$&"rdvtvtvtluhzrdvtvtlurdru"
a$=a$&"ldrurdvtvtluhzrdvtvtluhz"
a$=a$&"rdluhzbmbmbmldlurdrurdlu"
a$=a$&"hzrdlurdrurdrubmhzhzhzbm"
a$=a$&"ldlurdluhzhzhzrdluhzldru"
a$=a$&"vtvtlubmldluldlubmldvtlu"
end if

if .grid=13 then
a$="" '13x13 MazeConnect grid
a$=a$&"hzvtvtvtvtvtrurdrurdrurdru"
a$=a$&"hzrdrurdvtruldluhzhzldluhz"
a$=a$&"hzhzhzhzspldvtruhzhzrdruhz"
a$=a$&"hzhzhzldrubmrdluldluhzhzhz"
a$=a$&"hzhzldvtlurdlurdvtvtluldlu"
a$=a$&"hzldrubmrdlubmldvtvtrurdru"
a$=a$&"ldruldruhzbmbmbmrdruhzhzhz"
a$=a$&"rdlurdluldrubmrdluhzldluhz"
a$=a$&"hzrdlurdruldvtlurdlubmrdlu"
a$=a$&"hzldruhzldrurdvtlurdruldru"
a$=a$&"hzrdluhzbmldlurdvtluhzrdlu"
a$=a$&"hzhzrdlurdvtruhzrdvtluldru"
a$=a$&"ldluldvtlubmldluldvtvtvtlu"
end if

if .grid=14 then
a$="" '14x14 MazeConnect grid
a$=a$&"hzrdrurdvtvtrurdrurdvtvtrubm"
a$=a$&"hzhzhzldvtruhzhzhzhzrdruhzbm"
a$=a$&"ldluhzrdruhzldluldluhzhzhzbm"
a$=a$&"rdruhzhzhzldvtvtvtruhzldlubm"
a$=a$&"hzhzhzhzhzrdrurdruhzldvtrubm"
a$=a$&"hzhzhzhzhzhzhzhzhzhzrdruldru"
a$=a$&"hzhzldluhzhzhzhzhzhzhzldvtlu"
a$=a$&"hzldvtruhzhzhzhzhzhzldrurdru"
a$=a$&"hzrdruhzldluhzhzhzhzbmldluhz"
a$=a$&"ldluhzldvtruhzhzhzhzrdrurdlu"
a$=a$&"rdruhzrdvtluhzhzldluhzhzhzbm"
a$=a$&"hzldluldvtvtluhzrdvtluhzhzbm"
a$=a$&"hzvtvtvtvtvtvtluldrurdluhzbm"
a$=a$&"ldvtvtvtvtvtvtvtvtluldvtlubm"
end if

if .grid=15 then
  a$="" '15x15 MazeConnect grid
  a$=a$&"vtvtrurdrurdrurdrubmrdvtvtvtru"
  a$=a$&"vtruldluhzhzldluldvtlurdvtruhz"
  a$=a$&"rdlubmbmhzldvtvtrurdvtlubmldlu"
  a$=a$&"ldrurdruhzbmrdruhzldrurdvtvtru"
  a$=a$&"bmhzhzldlurdluhzldruldlurdvtlu"
  a$=a$&"rdluldrurdlubmhzrdlurdruldrubm"
  a$=a$&"ldrubmldlurdruldlubmhzhzbmldru"
  a$=a$&"rdlurdvtvtluldrurdruhzhzrdvtlu"
  a$=a$&"ldvtlurdvtvtvtluhzldluhzldvtru"
  a$=a$&"rdvtvtlurdvtvtruldrurdlurdruhz"
  a$=a$&"ldvtrurdlubmrdlurdluhzrdluldlu"
  a$=a$&"rdvtluldrurdlurdlurdluhzbmrdru"
  a$=a$&"ldvtrurdluhzbmldruldruldvtluhz"
  a$=a$&"rdvtluldruhzrdruldruldvtrurdlu"
  a$=a$&"ldvtvtvtluldluldvtlubmbmldlubm"
end if

  dd=1
  for s=1 to len(a$) step 2
    b$=mid$(a$,s,2)
    if b$="vt" then rotate(dd,1)
    if b$="hz" then rotate(dd,1) 
    if b$="ld" then rotate(dd,2) 
    if b$="lu" then rotate(dd,2) 
    if b$="rd" then rotate(dd,2) 
    if b$="ru" then rotate(dd,2) 
    if b$="bm" then .bv(dd)=.BM
    if b$="sp" then .bv(dd)=32
    dd=dd+1
  next s

end def

def rotate(num,type)

  'there are only two types of rotating characters,
  'straight lines, or right angles...

  'randomly rotate straight character
  if type=1 then
    if rnd(2) =0 then
       .bv(num)=.VT
    else
       .bv(num)=.HZ
    end if
  end if
  
  'randomly rotate right angles...
  if type=2 then
    rn=int(rnd(4))+1
    if rn=1 then .bv(num)=.LD
    if rn=2 then .bv(num)=.LU
    if rn=3 then .bv(num)=.RD
    if rn=4 then .bv(num)=.RU
  end if

end def

def drawbackground

graphics clear .3,.3,.3
draw alpha .3
draw font size 100
draw color 0,0,0
'a litte background
for x=1 to .sw step 61
   for y =1 to .sh step 102
      draw text chr$(9619) at x,y
   next y
next x
draw alpha 1

end def


MazeDesign.txt v1.0 is below....Use this to design your own mazes for game. it will output code to a file called MazeDesign.output.txt. These mazes are for v1.2 of the game or higher, not older version posted.

Code: Select all

'MazeDesign.txt v1.0
'Design/Save mazes for the MazeConnect puzzle.
'Coded by Dav, SEP/2017

'NOTE: The top left piece must be a straight line,
'either horizonal or vertical piece....for now.

'HOT TO USE: Touch a piece to use for drawing, then
'touch on the board to place it there. When you 
'want to save your design, click the save button
'and the maze code will be saved to a file called:
'mazedesign.output.txt. You can copy that code to
'the mazeconnect program to use.

'===========================================
grid=8 '<<<< set the grid size you want here.
'===========================================

option base 1

graphics
graphics clear .3,.3,.3
set orientation top

get screen size sw,sh

'angle characters, right up, left up, etc
LD=9491!LU=9499!RD=9487!RU=9495!HZ=9473!VT=9475!BM=9724

dim bv(grid*grid),bx(grid*grid),by(grid*grid),bc(grid*grid)
size=sw/grid
mov =0

set buttons custom
set buttons font size size

'draw drawing buttons
draw color 0,0,0
fill color 1,.5,.5
button "hz" text chr$(hz) at 1,1 size size,size
button "vt" text chr$(vt) at 1+size,1 size size,size
button "ld" text chr$(ld) at 1+size*2,1 size size,size
button "lu" text chr$(lu) at 1+size*3,1 size size,size
button "rd" text chr$(rd) at 1+size*4,1 size size,size
button "ru" text chr$(ru) at 1+size*5,1 size size,size
button "bm" text chr$(bm) at 1+size*6,1 size size,size
button "clr" text chr$(0) at 1+size*7,1 size size,size

button "cls" text "clear" at 1, grid*size+size
button "sav" text "save" at sw/2+size,grid*size+size 

selected=1 

clear:

'set button values, and x/y values...
bb=1
for r= 1 to grid
   for c = 1 to grid
     x=(r*size) ! y=(c*size)
     if rnd(grid*2)=grid then br =0
     bx(bb)=x-size!by(bb)=y!bv(bb)=0!bc(bb)=0
     bb=bb+1
   next c
next r

gosub updatebuttons

do 

   for b = 1 to (grid*grid)
    if button_pressed(str$(b)) then

       if selected=1 then bv(b)= HZ
       if selected=2 then bv(b)= VT
       if selected=3 then bv(b)= LD
       if selected=4 then bv(b)= LU
       if selected=5 then bv(b)= RD
       if selected=6 then bv(b)= RU
       if selected=7 then bv(b)= BM
       if selected=8 then bv(b)= 32

       gosub updatebuttons
       'gosub checkforwin

    end if
   next b

   if button_pressed("hz") then selected =1
   if button_pressed("vt") then selected =2
   if button_pressed("ld") then selected =3
   if button_pressed("lu") then selected =4
   if button_pressed("rd") then selected =5
   if button_pressed("ru") then selected =6
   if button_pressed("bm") then selected =7
   if button_pressed("clr") then selected =8

   if button_pressed("cls") then goto clear
   if button_pressed("sav") then gosub save

until 0

end

'============
updatebuttons:
'============

draw color 0,0,0

fill color 1,1,1
'draw/colorize board
for t=1 to (grid*grid)
   button str$(t) text chr$(bv(t)) at bx(t),by(t) size size,size
next t

return


'====
save:
'====

fil$="mazedesign.output.txt"

if file_exists(fil$) then file fil$ delete

s$=s$&"a$="&chr$(34)&chr$(34)&" '"&grid&"x"&grid
s$=s$&" MazeConnect grid"&chr$(10)
s$=s$&"a$=a$&"""

gc=1
for t = 1 to grid*grid
     if bv(t)=0 then s$=s$&"sp"
     if bv(t)=32 then s$=s$&"sp"
     if bv(t)=BM then s$=s$&"bm" 'block/bomb
     if bv(t)=HZ then s$=s$&"hz"
     if bv(t)=VT then s$=s$&"vt"
     if bv(t)=LD then s$=s$&"ld"
     if bv(t)=LU then s$=s$&"lu"
     if bv(t)=RD then s$=s$&"rd"
     if bv(t)=RU then s$=s$&"ru"
     's$=s$&chr$(bv(t))
     gc=gc+1
     if gc>grid then
        if t=grid*grid then break
        s$=s$&chr$(34)&chr$(10)
        s$=s$&"a$=a$&"""
        gc=1
     end if
next t

s$=s$&chr$(34)

'delete buttons
button "hz" delete
button "vt" delete
button "lu" delete
button "ld" delete
button "ru" delete
button "rd" delete
button "bm" delete
button "clr" delete
for t=1 to (grid*grid)
   button str$(t) delete
next t

text
print s$

file fil$ writeline s$
print
print "This maze has been saved to "&fil$

end

return
Attachments
mazedesign.jpg
mazedesign.jpg (83.04 KiB) Viewed 5672 times
MazeConnect.jpg
MazeConnect.jpg (72.94 KiB) Viewed 5754 times
Last edited by Dav on Tue Oct 10, 2017 1:32 am, edited 9 times in total.

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: MazeConnect v1.0 - puzzle prototype (iPad only)

Post by Dav »

Had a typo, fixed it. Maze now works. Reload it if you got it earlier and it didn't work.

- Dav

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: MazeConnect v1.0 - puzzle prototype (iPad only)

Post by Dutchman »

Great creative idea to use these characters for that. You are the games master :D

User avatar
Mr. Kibernetik
Site Admin
Posts: 4786
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPhone, iPad, MacBook
Location: Russia
Flag: Russia

Re: MazeConnect v1.0 - puzzle prototype (iPad only)

Post by Mr. Kibernetik »

I agree, Dav is a games master!

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: MazeConnect v1.0 - puzzle prototype (iPad only)

Post by Henko »

Yes, he is.
Dav, here's a brute force piece of code to generate a random path in a n x m grid. From it, you can deduct wich of the two tiles must be placed on each grid point. And don't forget to shuffle the rorational position of each tile.
The needed time is strongly exponential with size. 6x6 is moderate, lower is immediate, 7x7 can be 1 second, but also 20 seconds. It's a brute force method, as i said. After finding a path wich visits all points only once, it is drawn in this test program.

Code: Select all

input "number of columns ? ":ncol
input "number of rows ? ":nrow
graphics ! graphics clear ! draw color 0,0,0 ! draw size 3
option base 1 ! randomize
nturt=nrow*ncol
do
  dim p(nrow,ncol),turtle(nturt)
  curi=1 ! curj=1 ! turt=0 ! p(1,1)=1
  fail=0
  do dim fre(4)
    fail=inspect(curi,curj) ! if fail then break
    do ! td=1+rnd(4) ! until fre(td)=1
    turt+=1 ! turtle(turt)=td
    if td=1 then curj+=1 ! if td=2 then curi-=1
    if td=3 then curj-=1 ! if td=4 then curi+=1
    p(curi,curj)=1
    until fail
  until turt=nturt-1
draw_path()
end

def inspect(i,j)
  fail=1
  if j<.ncol and .p(i,j+1)=0 then ! .fre(1)=1 ! fail=0 ! end if
  if i>1 and .p(i-1,j)=0 then ! .fre(2)=1 ! fail=0 ! end if
  if j>1 and .p(i,j-1)=0 then ! .fre(3)=1 ! fail=0 ! end if
  if i<.nrow and .p(i+1,j)=0 then ! .fre(4)=1 ! fail=0 ! end if
  return fail
end def

def draw_path()
x=100 ! y=100 ! xto=x ! yto=y ! ds=floor(500/max(.nrow,.ncol))
for i=1 to .nturt-1
  td=.turtle(i)
  if td=1 then xto=x+ds ! if td=2 then yto=y-ds
  if td=3 then xto=x-ds ! if td=4 then yto=y+ds
  if i=1 then draw line x,y to xto,yto else draw line to xto,yto
  x=xto ! y=yto
  next i
end def
IMG_1419.PNG
IMG_1419.PNG (1.63 MiB) Viewed 5738 times

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: MazeConnect v1.0 - puzzle prototype (iPad only)

Post by rbytes »

I have been experimenting a bit with your program, Henk. As you say, it is very fast on smaller mazes, but once they get beyond 10 x 10 in size it can take many minutes for the calculations. Is it possible you could build a series of smaller maze blocks and connect them together? You would have to allow choice of the entry point location for each block so that it could start where the last block ended.

I notice that some mazes finish dead-ended (ie. the finish point is not on the edge) Those would have to be rejected as building blocks, as there would be no way to join them to another block. That would also be true of mazes where the start and finish points are on the same edge.

Perhaps there is no speed advantage, but I thought it was worth mentioning.

A progress bar of some kind would help to reassure that the program had not frozen. :)
The only thing that gets me down is gravity...

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: MazeConnect v1.0 - puzzle prototype (iPad only)

Post by rbytes »

Great game, Dav. Are there any guidelines on how to solve, rather than trial and error? I ask this because my trials are usually errors. :lol:
The only thing that gets me down is gravity...

Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Re: MazeConnect v1.0 - puzzle prototype (iPad only)

Post by Henko »

Good thinking Richard. If it is indeed possible to break down this process in a number of likewise 'linkable' subprocesses, it would certainly dramatically shorten the needed calculation time. But there are other, more intelligent algorithms to connect the points in a grid by visiting the points only once. It is a well known 'salesman problem' in the field of operational research. I guess they can be found on internet. I just have other priorities at the moment to dig further in it.
The calculation time needed by the brute force method that i used is so agressively growing beyond 50 gridpoints, that it is not usable as an "in-line" tool in the game. It could however be used "off-line" to generate large grids for the puzzle, and convert them (with additional coding) into suitable read/data stuff to be added to the game.

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: MazeConnect v1.0 - puzzle prototype (iPad only)

Post by Dav »

Thanks everyone! On my older iPad this game is way too slow to play. I thought of another way to scan the maze, Since each piece has one way in/out when connected, im going to keep track of the direction, and just 'go with the flow' starting with the top left piece. This way I will only have to upend the board pieces that connect, and not the the entire board many times after each turn.

Henko: thanks very much for your code. I can use it to generate mazes!

Rbytes: I don't of any real strategy to solve, maybe look for the long line pipes and see what needs to connect to those?

I'm working on a new version. Hoping to have levels, maybe some blocks, others pieces like a + one that connects any direction.

-Dav

User avatar
Dav
Posts: 279
Joined: Tue Dec 30, 2014 5:12 pm
My devices: iPad Mini, iPod Touch.
Location: North Carolina, USA
Contact:

Re: MazeConnect v1.1 - puzzle prototype (iPad only)

Post by Dav »

I have re-written the board scanning/colorizing method to a directional one, that goes with the flow so to speak. The result is that board update is now MUCH faster, making it very playable even on my older devices. Now that this hurdle is jumped I can go further with game development (levels,etc).

Code is updated. Try it out of you'd like.

- Dav

Post Reply