ColorMyHeart v1.0 - puzzle game for 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:

ColorMyHeart v1.0 - puzzle game for iPad

Post by Dav »

Hello fellow smart Basic users. Hope you all have been well. I started coding in smart Basic again last night and came up with a 'Flush' like puzzle game. Flush is a color puzzle game I was playing online and thought I'd try to make something like it. The code is not optimized, but the game is playable at least for now. There are 15 levels.

I'll try to post a screen shot later. Instructions on how to do the puzzle is in the code, which is for iPad only right now. Enjoy.

- Dav

Code: Select all

'ColorMyHeart.txt
'A 'flush' like puzzle game for ipad
'Coded by Dav April/2018

'Color all squares to proper color.
'Squares with blue hearts should be blue.
'Red hearts should be red squares, etc..
'Empty squares should be white. 

'HOW TO PLAY....

'First Select a color at the top to use.
'Then press an arrow to pur the color on
'a row or column. The color will not pass
'through another color, only on empty squares.
'Color will not go through an X square block.
'Use the erase (white) to clear a square color.
'it will only clear one square at a time.

'The Clr button is a level redo, it resets it.

'When all squares are colored or clear correctly,
'you can advance to the next level.

'There are 15 levels.

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

option base 1
set orientation top
get screen size sw,sh

level=1  '<<< set starting level here

maxlevel=15

'===
top:
'===

graphics
graphics clear .3,.3,.3

draw color 0,0,0!fill color 1,1,1

grid=6 !size=sw/grid
dim bv(grid*grid),bx(grid*grid),by(grid*grid),bv$(grid*grid)
dim fc(grid*grid) 'fill color of button

set buttons custom
set buttons font size 74

draw font size 36
draw color .5,.5,.5
draw text "Level "&level&" of "&str$(maxlevel) at sw/4,sh-62
draw color 0,0,0

'init button values, and generate x/y values...
bc=1
for r= 1 to grid
   for c = 1 to grid
     x=(r*size) ! y=(c*size)
     if bc=1 then goto skip  'dont draw corners...
     if bc=6 then goto skip
     if bc=31 then goto skip
     if bc=36 then goto skip
     'button str$(bc) text str$(bc) at x-size,y size size,size
skip:
     bx(bc)=x-size!by(bc)=y!bv(bc)=0!bv$(bc)=str$(bc)
     fc(bc)=0
     bc=bc+1
   next c
next r

fill color .5,.5,.5
for b=7 to 30 step grid
button str$(b) text chr$(8681) at bx(b), by(b) size size,size
next b

for b=2 to 5
button str$(b) text chr$(8680) at bx(b), by(b) size size,size
next b

for b=32 to 35
button str$(b) text chr$(8678) at bx(b), by(b) size size,size
next b

for b=12 to 30 step grid
button str$(b) text chr$(8679) at bx(b), by(b) size size,size
next b
fill color 1,1,1

'set icon date
xx$=chr$(9746) 'the x box
blu$=chr$(58154)!red$=chr$(57868) 'colored hearts
grn$=chr$(58155)!yel$=chr$(58156)

gosub setlevel

fclr=1 'red is default selected color

colorbuttons

do

  if button_pressed("r") then
    fclr=1!colorbuttons
  end if
  if button_pressed("g") then
    fclr=2!colorbuttons
  end if
  if button_pressed("b") then
    fclr=3!colorbuttons
  end if
  if button_pressed("y") then
    fclr=4!colorbuttons
  end if
  if button_pressed("o") then
    fclr=0!colorbuttons
  end if

  'handle 1st row down
  if button_pressed("7") then
   for s=8 to 11 ! gosub colorlogic ! next s
  end if

  'handle 1st row up
  if button_pressed("12") then
   for s=11 to 8 step -1 ! gosub colorlogic ! next s
  end if

  'handle 2nd row down
  if button_pressed("13") then
   for s=14 to 17 ! gosub colorlogic ! next s
  end if

  'handle 2nd row up
  if button_pressed("18") then
   for s=17 to 14 step -1 ! gosub colorlogic ! next s
  end if

  'handle 3rd row down
  if button_pressed("19") then
   for s=20 to 23 ! gosub colorlogic ! next s
  end if

  'handle 3rd row up
  if button_pressed("24") then
   for s=23 to 20 step -1 ! gosub colorlogic ! next s
  end if

  'handle 4th row down
  if button_pressed("25") then
   for s=26 to 29 ! gosub colorlogic ! next s
  end if

  'handle 4th row up
  if button_pressed("30") then
   for s=29 to 26 step -1 ! gosub colorlogic ! next s
  end if

  'handle 1st row going right
  if button_pressed("2") then
   for s=8 to 26 step grid ! gosub colorlogic ! next s
  end if

  'handle 1st row going left
  if button_pressed("32") then
   for s=26 to 8 step -grid ! gosub colorlogic ! next s
  end if

  'handle 2nd row going right
  if button_pressed("3") then
   for s=9 to 27 step grid ! gosub colorlogic ! next s
  end if

  'handle 2nd row going left
  if button_pressed("33") then
   for s=27 to 9 step -grid ! gosub colorlogic ! next s
  end if

  'handle 3rd row going right
  if button_pressed("4") then
   for s=10 to 28 step grid ! gosub colorlogic ! next s
  end if

  'handle 3rd row going left
  if button_pressed("34") then
   for s=28 to 10 step -grid ! gosub colorlogic ! next s
  end if

  'handle 4th row going right
  if button_pressed("5") then
   for s=11 to 29 step grid ! gosub colorlogic ! next s
  end if

  'handle 4th row going left
  if button_pressed("35") then
   for s=29 to 11 step -grid ! gosub colorlogic ! next s
  end if

  'restart level (clear)
  if button_pressed("clr") then goto top

doneit:

gosub checkforwin

until 0

end


colorlogic:
     if bv$(s) =xx$ then goto doneit
     if fclr <> 0 then
        if fc(s) <> 0 then goto doneit
       ' if fc(s) <> fclr and fc(s) <> 0 then goto doneit
     end if
     once=fc(s)
     button str$(s) text bv$(s) at bx(s),by(s) size size,size
     fc(s)=fclr
     notes set "73:sc2"!notes play
     pause .05
     if fclr=0 and once<>0 then goto doneit
return


checkforwin:

for z=8 to 29
   if bv$(z)="" then
      if fc(z)<>0 then goto breakout
   end if
   if bv$(z)=red$ then 
      if fc(z)<>1 then goto breakout
   end if
   if bv$(z)=grn$ then
      if fc(z)<>2 then goto breakout
   end if
   if bv$(z)=blu$ then
      if fc(z)<>3 then goto breakout
   end if
   if bv$(z)=yel$ then 
      if fc(z)<>4 then goto breakout
   end if
next z

graphics clear .7,.7,.7
notes set "7:s(c3eg)(e4cg3)(g4ec)(c5g4e)"
notes play 
pause 1

fill color 1,.5,.5
for f=1 to grid*grid
  if f>7 and f <12 then
    button str$(f) text chr$(58423) at bx(f),by(f) size size,size
  end if
  if f>13 and f <18 then
    button str$(f) text chr$(58423) at bx(f),by(f) size size,size
  end if
  if f>19 and f <24 then
    button str$(f) text chr$(58423) at bx(f),by(f) size size,size
  end if  
  if f>25 and f <30 then
    button str$(f) text chr$(58423) at bx(f),by(f) size size,size
  end if
  pause .03
next f

if level = maxlevel then end
level=level +1
goto top

breakout:

return


setlevel:

if level =1 then
   bv$(8)=blu$!bv$(9)=blu$!bv$(10)=""!bv$(11)=blu$
   bv$(14)=xx$!bv$(15)=xx$!bv$(16)=yel$!bv$(17)=xx$
   bv$(20)=xx$!bv$(21)=red$!bv$(22)=xx$!bv$(23)=xx$
   bv$(26)=grn$!bv$(27)=""!bv$(28)=grn$!bv$(29)=grn$
end if
if level=2 then
   bv$(8)=xx$!bv$(9)=""!bv$(10)=grn$!bv$(11)=""
   bv$(14)=""!bv$(15)=xx$!bv$(16)=""!bv$(17)=blu$
   bv$(20)=red$!bv$(21)=""!bv$(22)=xx$!bv$(23)=""
   bv$(26)=""!bv$(27)=yel$!bv$(28)=""!bv$(29)=xx$
end if
if level=3 then
   bv$(8)=xx$!bv$(9)=xx$!bv$(10)=blu$!bv$(11)=xx$
   bv$(14)=red$!bv$(15)=yel$!bv$(16)=grn$!bv$(17)=xx$
   bv$(20)=xx$!bv$(21)=grn$!bv$(22)=yel$!bv$(23)=red$
   bv$(26)=xx$!bv$(27)=blu$!bv$(28)=xx$!bv$(29)=xx$
end if
if level=4 then
   bv$(8)=xx$!bv$(9)=xx$!bv$(10)=blu$!bv$(11)=blu$
   bv$(14)=red$!bv$(15)=""!bv$(16)=yel$!bv$(17)=red$
   bv$(20)=red$!bv$(21)=yel$!bv$(22)=""!bv$(23)=red$
   bv$(26)=blu$!bv$(27)=blu$!bv$(28)=xx$!bv$(29)=xx$
end if
if level =5 then
   bv$(8)=xx$!bv$(9)=red$!bv$(10)=red$!bv$(11)=red$
   bv$(14)=grn$!bv$(15)=grn$!bv$(16)=""!bv$(17)=xx$
   bv$(20)=xx$!bv$(21)=""!bv$(22)=blu$!bv$(23)=blu$
   bv$(26)=yel$!bv$(27)=yel$!bv$(28)=yel$!bv$(29)=xx$
end if
if level=6 then
   bv$(8)=xx$!bv$(9)=grn$!bv$(10)=red$!bv$(11)=yel$
   bv$(14)=xx$!bv$(15)=""!bv$(16)=blu$!bv$(17)=red$
   bv$(20)=""!bv$(21)=blu$!bv$(22)=""!bv$(23)=grn$
   bv$(26)=yel$!bv$(27)=""!bv$(28)=xx$!bv$(29)=xx$
end if
if level=7 then
   bv$(8)=xx$!bv$(9)=red$!bv$(10)=""!bv$(11)=grn$
   bv$(14)=blu$!bv$(15)=""!bv$(16)=xx$!bv$(17)=""
   bv$(20)=xx$!bv$(21)=grn$!bv$(22)=""!bv$(23)=red$
   bv$(26)=xx$!bv$(27)=xx$!bv$(28)=blu$!bv$(29)=xx$
end if
if level=8 then
   bv$(8)=xx$!bv$(9)=""!bv$(10)=xx$!bv$(11)=xx$
   bv$(14)=yel$!bv$(15)=""!bv$(16)=""!bv$(17)=xx$
   bv$(20)=grn$!bv$(21)=""!bv$(22)=""!bv$(23)=xx$
   bv$(26)=xx$!bv$(27)=""!bv$(28)=xx$!bv$(29)=xx$
end if
if level=9 then
   bv$(8)=""!bv$(9)=xx$!bv$(10)=blu$!bv$(11)=xx$
   bv$(14)=red$!bv$(15)=""!bv$(16)=grn$!bv$(17)=yel$
   bv$(20)=yel$!bv$(21)=grn$!bv$(22)=""!bv$(23)=red$
   bv$(26)=xx$!bv$(27)=blu$!bv$(28)=xx$!bv$(29)=""
end if
if level=10 then
   bv$(8)=xx$!bv$(9)=yel$!bv$(10)=yel$!bv$(11)=xx$
   bv$(14)=red$!bv$(15)=""!bv$(16)=""!bv$(17)=grn$
   bv$(20)=red$!bv$(21)=""!bv$(22)=""!bv$(23)=grn$
   bv$(26)=xx$!bv$(27)=blu$!bv$(28)=blu$!bv$(29)=""
end if
if level=11 then
   bv$(8)=xx$!bv$(9)=red$!bv$(10)=""!bv$(11)=xx$
   bv$(14)=red$!bv$(15)=""!bv$(16)=yel$!bv$(17)=yel$
   bv$(20)=""!bv$(21)=grn$!bv$(22)=""!bv$(23)=blu$
   bv$(26)=xx$!bv$(27)=grn$!bv$(28)=blu$!bv$(29)=""
end if
if level=12 then
   bv$(8)=xx$!bv$(9)=blu$!bv$(10)=xx$!bv$(11)=xx$
   bv$(14)=blu$!bv$(15)=grn$!bv$(16)=""!bv$(17)=yel$
   bv$(20)=xx$!bv$(21)=""!bv$(22)=grn$!bv$(23)=""
   bv$(26)=xx$!bv$(27)=yel$!bv$(28)=""!bv$(29)=grn$
end if
if level=13 then
   bv$(8)=xx$!bv$(9)=red$!bv$(10)=xx$!bv$(11)=grn$
   bv$(14)=red$!bv$(15)=""!bv$(16)=grn$!bv$(17)=""
   bv$(20)=""!bv$(21)=yel$!bv$(22)=""!bv$(23)=blu$
   bv$(26)=yel$!bv$(27)=xx$!bv$(28)=blu$!bv$(29)=xx$
end if
if level=14 then
   bv$(8)=yel$!bv$(9)=grn$!bv$(10)=yel$!bv$(11)=grn$
   bv$(14)=grn$!bv$(15)=yel$!bv$(16)=grn$!bv$(17)=yel$
   bv$(20)=yel$!bv$(21)=grn$!bv$(22)=yel$!bv$(23)=grn$
   bv$(26)=grn$!bv$(27)=yel$!bv$(28)=grn$!bv$(29)=yel$
end if
if level=15 then
   bv$(8)=xx$!bv$(9)=grn$!bv$(10)=grn$!bv$(11)=xx$
   bv$(14)=xx$!bv$(15)=red$!bv$(16)=""!bv$(17)=""
   bv$(20)=""!bv$(21)=""!bv$(22)=yel$!bv$(23)=blu$
   bv$(26)=xx$!bv$(27)=grn$!bv$(28)=grn$!bv$(29)=xx$
end if
   s$="" 'generate random notes
   for o = 1 to 16
      s$=s$&chr$(66+rnd(6))&str$(5+rnd(2))
   next o
   notes set "8:t"&s$ '23
   notes play

'redraw button data
for s=8 to 11
   button str$(s) text bv$(s) at bx(s),by(s) size size,size
   pause .03
next s
for s=14 to 17
   button str$(s) text bv$(s) at bx(s),by(s) size size,size
   pause .03
next s
for s=20 to 23
   button str$(s) text bv$(s) at bx(s),by(s) size size,size
   'notes set "116:sc1"!notes play
   pause .03
next s
for s=26 to 29
   button str$(s) text bv$(s) at bx(s),by(s) size size,size
   'notes set "116:sc1"!notes play
   pause .03
next s

return


def colorbuttons()
draw color 0,0,0
k$=chr$(10004) 
if .fclr=0 then o$=k$ else o$=""
if .fclr=1 then r$=k$ else r$=""
if .fclr=2 then g$=k$ else g$=""
if .fclr=3 then b$=k$ else b$=""
if .fclr=4 then y$=k$ else y$=""
fill color 1,0,0
button "r" text r$ at 1,1 
fill color 0,1,0
button "g" text g$ at .size,1 
fill color 0,0,1
button "b" text b$ at .size*2,1 
fill color 1,1,0
button "y" text y$ at .size*3,1
fill color 1,1,1
button "o" text o$ at .size*4,1

button "clr" text "Clr" at .size*5,1

if .fclr =0 then fill color 1,1,1
if .fclr =1 then fill color 1,0,0
if .fclr =2 then fill color 0,1,0
if .fclr =3 then fill color 0,0,1
if .fclr =4 then fill color 1,1,0
notes set "120:sg7"!notes play
end def
Last edited by Dav on Thu Apr 12, 2018 11:43 am, edited 1 time in total.

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: ColorMyHeart v1.0 - puzzle game for iPad

Post by rbytes »

This a a fun game, and quite challenging as you go up the levels. Thanks for posting, Dav.
The only thing that gets me down is gravity...

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: ColorMyHeart v1.0 - puzzle game for iPad

Post by Dav »

Thanks, rbytes. I made it too easy, and didn't copy the behavior of the original game correctly. I let the same color pass through itself, making it easier to color a square on the other side. I just fixed it to prevent that, making it harder to get the board colored right.

I just changed the colorlogic routine:

if fc(s) <> 0 then goto doneit
' if fc(s) <> fclr and fc(s) <> 0 then goto doneit

The code has been updated.

- Dav

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: ColorMyHeart v1.0 - puzzle game for iPad

Post by rbytes »

Uh oh! And I thought I finally had a game I could ace. :) maybe I will keep both versions so I can continue to maintain the illusion. :lol:

It is good to see you back on the Forum, Dav. It's funny, but now that I have accepted the fact that Smart Basic may not have a future, I am just enjoying programming in it while I can.
The only thing that gets me down is gravity...

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

Re: ColorMyHeart v1.0 - puzzle game for iPad

Post by Dutchman »

Nice game. Thanks for sharing.
I changed "SET ORIENTATION TOP" to "SET ORIENTATION VERTICAL".
That gives the additional option to orientate the iPad with the lightning-cable at the top. ;)
screenshot.PNG
screenshot.PNG (83.59 KiB) Viewed 3337 times

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: ColorMyHeart v1.0 - puzzle game for iPad

Post by Dav »

Thanks, guys. It's nice being back and making something again in smart basic. I worked on another puzzle today, will post it soon.

- Dav

Post Reply