ColorMyHeart v1.0 - puzzle game for iPad
Posted: Tue Apr 10, 2018 5:15 pm
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
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