GridClear v1.1 - puzzle game (iPad only)

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

GridClear v1.1 - puzzle game (iPad only)

Post by Dav » Mon Dec 19, 2016 11:40 pm

Ive updated the GridClear puzzle game to make it fully playable with goals. It's now kind of fun, and more irritating. :D

New in this version 1.1.

- 10 playable levels.
- music and sfx to enhance the game play.
- you don't have to fully clear the board to advance levels, just clear enough.
- The board generation is better, making enough color groups to beat the level.
- added handy redraw button to restart a level quickly when you give up.
- info at bottom shows how many blocks there are and how many to clear.
- game progress is saved to a data file so you can continue later on.

Hope you enjoy this game. It's easy up to about level 6, then gets really hard. I'll try and post some screen shots. Still for iPad only, sorry about that iPhone users...

- Dav

Code: Select all

'GridClear v1.1 (ipad only)
'Coded by Dav DEC/2016
'Based on a old qbasic game

'NEW in v1.1: 10 levels. Game progress saved.

'Try to clear the board of the color blocks.
'Touch a group of colors to remove that group.
'Blocks will drop down to fill in the holes.
'Blocks move to the left when a column removed.

'Each level has a certain number of blocks.
'Ending up with no blocks or less is great.

'Only for ipad right now, but I will probably
'add rbytes cool all-device code later on.


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


'=== read data file, make new if not there
level=1 ! maxlevel=10
if file_exists("gridclear.dat") then
   file "gridclear.dat" read lev
   if lev < 1 or lev > maxlevel then goto makenew
   level=lev
else
   makenew:
   file "gridclear.dat" write level
end if

'level=10   'level cheat, override

'=== set up screen
graphics
graphics clear .2,.2,.2
set orientation top
option base 1

set buttons custom
set buttons font size 56

sw=screen_width()
sh=screen_height()


'======
newgame:
'======

gosub InitLevel

'=== update config file
file "gridclear.dat" delete
file "gridclear.dat" write level

draw color 1,1,1
fill color .2,.2,.2
button "redraw" text "Redraw level" at 215,sh-110

dim btn(rows,columns)  'buttons display

regenerate:

'generate random board colors
for r= 1 to rows
   for c = 1 to columns
     btn(r,c)=rnd(6)
   next c
next r

'make sure there's enough groups present
'to do level. without this, it's soooo hard
if NumberOfGroups<rows*5 then goto regenerate

gosub updateinfo

playboard=1 'sound flag. play sfx.

gosub updateboard

do
  'get a button press
  do
    nm=0 'button count
    for r= 1 to rows
       for c = 1 to columns
         nm=nm+1
         if button_pressed("redraw") then 
            goto newgame
         end if
         if button_pressed(str$(nm)) then 
           old=btn(r,c) 'button color

           'only do when non black touched
           if old <>6 then
             'only do if a neighbor is same
             nn=0
             if r>1 then
                if btn(r-1,c)=old then nn=1
             end if
             if r<rows then
                if btn(r+1,c)=old then nn=1
             end if
             if c>1 then
                if btn(r,c-1)=old then nn=1
             end if
             if c<columns then
                if btn(r,c+1)=old then nn=1
             end if
             'if a group of colors...
             if nn= 1 then
                notes set "127:tc7b5a6" '101
                notes play
                x=(r*size) ! y=(c*size)
                goto selected
             end if
           end if
         end if
       next c
    next r

   slowdown

  until 0


  selected:

  'fill the group...
  FloodFill(old, 6, r, c)

  'show blacked out colors
  gosub updateboard
  
  moved=0 'moving sound flag

  'drop down blocks here...
  for r= 1 to rows
     for c = columns to 2 step -1
       if btn(r,c)=6 then
         c2=c
         do
           c2=c2-1
         until btn(r,c2)<>6 or c2 = 1
         if c2 >0 then
           if btn(r,c) <> btn(r,c2) then 
              moved =1
           end if
           btn(r,c) = btn(r,c2)
           btn(r,c2)=6
         end if
       end if
      next c
   next r

  'move blocks left here...
   for r = 1 to rows -1
     if btn(r,columns)=6 then
        r2=r
        do
          r2=r2+1
        until btn(r2,columns)<>6 or r2=rows
        for c = 1 to columns
           if btn(r,c)<>btn(r2,c) then
              moved =1
           end if
           btn(r,c)=btn(r2,c)
           btn(r2,c)=6
        next c
     end if
   next r

   if moved=1 then
      'play sfx for blocks dropping
       notes set "122:sc3b2a2"
       notes play
   end if

  'redraw buttons board
  gosub updateboard

  'see if any groups presently left
  dn=NumberOfGroups

   gosub updateinfo

   'if no more groups, end...
   if NumberOfGroups=0 then
     'if passed level...
     if h<= rows then
        level=level+1
        notes set "7:s(c3eg)(e4cg3)(g4ec)(c5g4e)"
        notes play ! 'pause 1.5
        for g = 1 to 3
          graphics clear .2,1,.2 ! pause .1
          graphics clear .2,.2,.2 ! pause .1
        next g
        if level>maxlevel then goto wingame
        goto newgame
     else
        'failed level, restart
        notes set "112:s(f4b)b3(f4b)b3(fb)b4(fb)"
        notes play
        for g = 1 to 5
          graphics clear 5,.2,.2 ! pause .1
          graphics clear .2,.2,.2 ! pause .1
        next g
     end if
     goto newgame
   end if


until forever


end


'==========================================
' GOSUBS AND FUNCTIONS
'==========================================


'==========
updateboard:
'==========

if playboard=1 then
   s$="" 'generate random notes
   for o = 1 to rows*(rows/2)
      s$=s$&chr$(66+rnd(6))&str$(5+rnd(2))
   next o
   notes set "116:t"&s$ '23
   notes play
end if

nm=0
for r= 1 to rows
   for c = 1 to columns
     j= btn(r,c) ! nm=nm+1
     if j=0 then fill color 1,0,0
     if j=1 then fill color 0,1,0
     if j=2 then fill color 0,0,1
     if j=3 then fill color 1,1,0
     if j=4 then fill color 1,0,1
     if j=5 then fill color 1,.5,0
     if j=6 then fill color .2,.2,.2
     if j=6 then 
        draw color .2,.2,.2
     else
        draw color 0,0,0
     end if
     x=(r*size) ! y=(c*size)
     button str$(nm) text "" at x,y+15 size size,size
   next c
next r

if playboard=1 then
   notes stop
   playboard=0
end if

'pause rows*.025

return


'=========
updateinfo:
'=========

graphics clear .2,.2,.2
draw color 1,1,1
draw font size 56
draw text "Level "&level&" of 10" at 150,10
draw font size 36
f$=" Leave "&str$(rows)&" blocks or less"
draw text f$ at 110,sh-220
   'count how many blocks left
   h=0
   for r=1 to rows
       for c=1 to columns
         if btn(r,c)<>6 then h=h+1
       next c
   next r
h$=str$(h)&" blocks left"
draw font size 26
draw text "("&h$&")" at 240,sh-180
fill color 0,0,0
draw color 0,0,0

return


'========
initLevel:
'========

if level = 1 then
   rows = 4!columns = 4!size =125
end if
if level = 2 then
   rows = 5!columns = 5!size =110
end if
if level = 3 then
   rows = 6!columns = 6!size =95
end if
if level = 4 then
   rows = 7!columns = 7!size =85
end if
if level = 5 then
   rows = 8!columns = 8!size =75
end if
if level = 6 then
   rows = 9!columns = 9!size =70
end if
if level = 7 then
   rows = 10!columns = 10!size =64
end if
if level = 8 then
   rows = 11!columns = 11!size =59
end if
if level = 9 then
   rows = 12!columns = 12!size =55
end if
if level = 10 then
   rows = 13!columns = 13!size =52
end if

return


'======
wingame:
'======

'remove grid
nm=0
for r=1 to rows
   for c = 1 to columns
     nm=nm+1
     button str$(nm) delete 
   next c
next r

graphics clear .2,.2,.2
button "redraw" delete
draw font size 56
draw color 1,1,0
draw text "YOU DID IT!" at 200,125
draw text "Congratulations!" at 125,700

'draw happyface
sw=screen_width()
sh=screen_height()-100
fill color 1,1,0
fill circle sw/2,sh/2 size 200
fill color 0,0,0
fill circle sw/2-75,sh/2-75 size 50
fill circle sw/2+75,sh/2-75 size 50
fill color 1,1,1
fill circle sw/2-75,sh/2-75 size 15
fill circle sw/2+75,sh/2-75 size 15
fill color 0,0,0
fill circle sw/2,sh/2+20 size 20
draw size 25
draw color 0,0,0
draw arc sw/2,sh/2,125,3.14,0,1

'happy music
c$="46:i(c4aff3c5)(ff4a)(ca5ff4)(c7a6)(a6f)(c5c4af)"
c$=c$&"i(c4aff3c5)(ff4a)(ca5ff4)(c7a6)(a6f)(c5c4af)"
c$=c$&"i(a#gecc5)(ege4)q(a#5gc5e4)(a#5d6g4e)"
c$=c$&"i(ega#5d6)(c6a6f5)q(caf)s(c6a5)(a#g)(af)(ge)"
c$=c$&"i(c4aff3c5)(ff4a)(ca5ff4)(c7a6)(a6f)(c5c4af)"
c$=c$&"i(c4aff3c5)(ff4a)(ca5ff4)(c7a6)(a6f)(c5c4af)"
c$=c$&"i(a#gecc5)(ege4)q(a#5gc5e4)(e5ca#4gc)h(f5ca3f)"
'play song
notes set c$ ! notes play
'loop until music stops playing
do! until notes_time() => notes_length() 

text
end


'==============================

def NumberOfGroups()

  'returns how many groups left on board

  dn=0
  for r=1 to .rows
    for c=1 to .columns
        if .btn(r,c)<>6 then
          if r>1 then
             if .btn(r-1,c)=.btn(r,c) then dn=dn+1
          end if
          if r<.rows then
             if .btn(r+1,c)=.btn(r,c) then dn=dn+1
          end if
          if c>1 then
             if .btn(r,c-1)=.btn(r,c) then dn=dn+1
          end if
          if c<.columns then
             if .btn(r,c+1)=.btn(r,c) then dn=dn+1
          end if
        end if
     next c
   next r
   return dn

end def

'==============================

def FloodFill(old, clr, x, y)
	If .btn(x,y) <> old Then
		Return
	Else
		.btn(x,y) = clr
	End if
	If x > 1 Then FloodFill(old, clr, x-1, y)
	If x < .rows Then FloodFill(old, clr, x + 1, y)
	If y > 1 Then FloodFill(old, clr, x, y-1)
	If y < .columns Then FloodFill(old, clr, x, y+1)
End def

'==============================
Attachments
gridclear-1.jpg
gridclear-1.jpg (45.12 KiB) Viewed 1350 times
gridclear-2.jpg
gridclear-2.jpg (34.08 KiB) Viewed 1350 times

Post Reply