GetToTheFlag puzzle game v1.0 (ipad)

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

GetToTheFlag puzzle game v1.0 (ipad)

Post by Dav »

Continuing making games using buttons.

I made this for kids, of any age. It's a simple game where you navigate the face to the flag while covering up every empty space on the board. EAsy for most, but you can design harder levels if you wish.

- Dav

Code: Select all

'GetToTheFlag.txt v1.0
'A simple puzzle game for ipad.
'Coded by Dav, May/2018
'
'Use arrows to move the face and get it to the flag.
'You must cover all empty spaces before reaching it.
'If you leave any empty spaces the level will restart.
'There are 10 levels.  IPAD on,y right now.

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

option base 1
get orientation ort
set orientation vertical
get screen size sw,sh

level = 1
maxlevel =10

'======
restart:
'======

graphics
graphics clear .2,.2,.2
set buttons custom

'draw background texture
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

grid=9 !size=sw/grid
dim bx(grid*grid),by(grid*grid),bv$(grid*grid)

set buttons font size 36

draw color 0,0,0
fill color 1,1,.8
button "restart" text "Restart" at 1,grid

draw color 1,1,1
w$="Level "&level&" of "&maxlevel
draw font size 36
draw text w$ at grid*25, grid*2


draw text "Use arrows to move face." at 20,800
draw text "Cover all empty spaces" at 20,850
draw text "before reaching the flag." at 20,900 
draw font size 100
set buttons font size 74

x$=chr$(11035)

draw color 0,0,0
fill color .6,.6,.6

'init default button values, and generate x/y values...
bc=1
for r= 1 to grid
   for c = 1 to grid-1
     x=(r*size) ! y=(c*size)
     'button str$(bc) text x$ at x-size,y size size,size
     bx(bc)=x-size!by(bc)=y  'button x/y position
     bv$(bc)=x$ 'fill board with blocks
     bc=bc+1
   next c
next r

'draw controls
set buttons font size 40
button "L" text chr$(8592) at (6.9*size),850
button "R" text chr$(8594) at (8.1*size),850
button "U" text chr$(8593) at (7.5*size),790
button "D" text chr$(8595. ) at (7.5*size),910
set buttons font size 74

feet$=x$'chr$(9619)
face$=chr$(58370)
goal$=chr$(9971)

gosub setlevel

'draw board
for r=1 to grid*grid-grid
 button str$(r) text bv$(r) at bx(r),by(r) size size,size
next r


'===
main:
'===

'notes set "120:sg7"!notes play

do
  
  if button_pressed("D") then
     'see if piece is already on bottom row
     'if it is, skip down button action
     for t= 1 to 9
        if piece = 8*t then goto done
     next t
     'see if space below is already block
     if bv$(piece+1)=feet$ then goto done
     if bv$(piece+1)=x$ then goto done
     'all clear to move, so do the move
     bv$(piece)=feet$  'old space now block
     bv$(piece+1)=face$ 'new space now piece
     button str$(piece) text bv$(piece) at bx(piece),by(piece) size size,size
     button str$(piece+1) text bv$(piece+1) at bx(piece+1),by(piece+1) size size,size
     piece =piece +1
     notes set "120:sg7"!notes play
     gosub checkforwin
  end if

  if button_pressed("L") then
     'see if is already of left side
     if piece<9 then goto done
     'see if space left is already blocked
     if bv$(piece-8)=feet$ then goto done
     if bv$(piece-8)=x$ then goto done
     bv$(piece)=feet$
     bv$(piece-8)=face$
     button str$(piece) text bv$(piece) at bx(piece),by(piece) size size,size
     button str$(piece-8) text bv$(piece-8) at bx(piece-8),by(piece-8) size size,size
     piece =piece-8
     notes set "120:sg7"!notes play
     gosub checkforwin
  end if
  
  if button_pressed("U") then
     'see if is already on top row
     for t= 1 to grid*9 step grid-1
        if piece = t then goto done
     next t
    
     'see if space up is already blocked
     if bv$(piece-1)=feet$ then goto done
     if bv$(piece-1)=x$ then goto done
     bv$(piece)=feet$
     bv$(piece-1)=face$
     button str$(piece) text bv$(piece) at bx(piece),by(piece) size size,size
     button str$(piece-1) text bv$(piece-1) at bx(piece-1),by(piece-1) size size,size
     piece =piece-1
     notes set "120:sg7"!notes play
     gosub checkforwin
  end if

  if button_pressed("R") then
     'see if is already on right side
     if piece>64 then goto done
     'see if space right is already blocked
     if bv$(piece+8)=feet$ then goto done
     if bv$(piece+8)=x$ then goto done
     bv$(piece)=feet$
     bv$(piece+8)=face$
     button str$(piece) text bv$(piece) at bx(piece),by(piece) size size,size
     button str$(piece+8) text bv$(piece+8) at bx(piece+8),by(piece+8) size size,size
     piece =piece+8
     notes set "120:sg7"!notes play
     gosub checkforwin
  end if

  if button_pressed("restart") then goto restart

  done:

until 0



end

'==========
checkforwin:
'==========

win=1
for r=1 to grid*grid-grid
   'any open spaces left?
   if bv$(r)="" then win=0
   if bv$(r)=goal$ then win=0 'still showing
next r

if win=1 then
   level=level+1
   notes stop!pause .12
   notes set "7:s(c3eg)(e4cg3)(g4ec)(c5g4e)"
   notes play 
    button bv$(piece) text chr$(57431) at bx(piece),by(piece) size size,size
   pause 1.5
   if level > maxlevel then end
   goto restart
end if

if piece=goalplace then 
   notes stop!pause .12
   notes set "123:w(c1eg)"
   notes play 
   button bv$(piece) text chr$(57432) at bx(piece),by(piece) size size,size
   pause 1.5
   goto restart
end if

return

'======
setlevel:
'======

if level=1 then
  bv$(21)=face$!piece=21!bv$(29)=""!bv$(37)=""!bv$(45)=""
  bv$(53)=goal$!goalplace=53
end if

if level=2 then
  bv$(20)=""!bv$(21)=""!bv$(22)=""!bv$(23)=goal$!goalplace=23
  bv$(26)=face$!piece=26!bv$(27)=""!bv$(28)=""!bv$(29)=""
  bv$(30)=""
end if

if level=3 then
   bv$(11)=""!bv$(12)=""!bv$(14)=face$!piece=14
   bv$(18)=""!bv$(19)=""!bv$(20)=""!bv$(22)=""
   bv$(26)=""!bv$(27)=goal$!goalplace=27!bv$(28)=""!bv$(30)=""
   bv$(34)=""!bv$(35)=""!bv$(36)=""!bv$(37)=""!bv$(38)=""
   bv$(42)=""!bv$(43)=""!bv$(44)=""!bv$(45)=""!bv$(46)=""
   bv$(50)=""!bv$(51)=""!bv$(52)=""
end if

if level=4 then
   bv$(10)=face$!piece=10!bv$(12)=""!bv$(13)=goal$
   goalplace=13!bv$(14)=""!bv$(15)=""
   bv$(18)=""!bv$(19)=""!bv$(20)=""!bv$(21)=""!bv$(22)=""
   bv$(23)=""!bv$(27)=""!bv$(28)=""!bv$(30)=""!bv$(31)=""
   bv$(36)=""!bv$(37)=""!bv$(38)=""!bv$(39)=""
   bv$(45)=""!bv$(46)=""!bv$(47)=""!bv$(54)=""!bv$(55)=""
end if

if level=5 then
   bv$(5)=""!bv$(6)=""!bv$(13)=goal$!goalplace=13!bv$(14)=""
   bv$(19)=""!bv$(20)=""!bv$(21)=""!bv$(22)=""
   bv$(27)=""!bv$(28)=""!bv$(29)=""
   bv$(37)=""!bv$(38)=""
   bv$(43)=""!bv$(44)=""!bv$(45)=""!bv$(46)=""
   bv$(51)=""!bv$(53)=face$!piece=53!bv$(54)=""
   bv$(59)=""!bv$(60)=""!bv$(61)=""!bv$(62)=""
   bv$(69)=""!bv$(70)=""
end if

if level=6 then 
  bv$(10)=""!bv$(11)=""!bv$(12)=""!bv$(13)=""
  bv$(18)=""!bv$(19)=""!bv$(20)=""!bv$(21)=""
  bv$(26)=""!bv$(27)=""!bv$(28)=""!bv$(29)=""
  bv$(34)=""!bv$(35)=""!bv$(36)=""!bv$(37)=""!bv$(38)=""
  bv$(39)=""!bv$(40)=""!bv$(42)=face$!piece=42!bv$(43)=""
  bv$(44)=""!bv$(45)=""!bv$(46)=""!bv$(47)=goal$!goalplace=47
  bv$(48)=""!bv$(53)=""!bv$(54)=""!bv$(55)=""!bv$(56)=""
end if

if level=7 then
  for i=1 to 72!bv$(i)=""!next i!bv$(8)=goal$!goalplace=8
  bv$(20)=x$!bv$(23)=x$!bv$(33)=x$!bv$(38)=x$!bv$(41)=x$
  bv$(42)=x$!bv$(52)=x$!bv$(65)=x$!bv$(71)=x$!bv$(72)=face$
  piece=72
end if

if level=8 then
  for i=1 to 72!bv$(i)=""!next i!bv$(1)=x$!bv$(6)=face$
  piece=6!bv$(9)=x$!bv$(12)=x$!bv$(13)=goal$!goalplace=13
  bv$(14)=x$!bv$(17)=x$!bv$(27)=x$!bv$(36)=x$!bv$(41)=x$
  bv$(47)=x$!bv$(51)=x$!bv$(60)=x$
  
end if

if level=9 then
  for i=1 to 72!bv$(i)=""!next i!bv$(1)=x$!bv$(2)=x$
  bv$(8)=goal$!goalplace=8!bv$(14)=x$!bv$(25)=x$!bv$(37)=x$
  bv$(38)=x$!bv$(39)=x$!bv$(40)=x$!bv$(43)=face$!piece=43
  bv$(45)=x$!bv$(48)=x$!bv$(49)=x$!bv$(51)=x$!bv$(56)=x$
  bv$(64)=x$!bv$(68)=x$!bv$(69)=x$!bv$(70)=x$!bv$(71)=x$
  bv$(72)=x$
end if

if level=10 then
  for i=1 to 72!bv$(i)=""!next i!bv$(8)=x$!bv$(12)=x$
  bv$(13)=x$!bv$(14)=x$!for i=18 to 23!bv$(i)=x$!next i
  bv$(33)=x$!bv$(36)=goal$!goalplace=36!bv$(37)=face$
  piece=37!bv$(41)=x$!bv$(44)=x$!bv$(49)=x$!bv$(54)=x$
  bv$(59)=x$!bv$(47)=x$!bv$(69)=x$
end if

return


Post Reply