NOTE: Updated a better version of game in this thread - You can find it HERE.
Here's another math puzzle game. In this one you have to make the numbers in the rows and columns add up to the numbers on the edges. When they do, they will turn green. Tap on the numbers to turn them on/off. Turn all edge numbers green to complete level. There are 15 levels. Hope someone will enjoy it. IPad only right now.
I set up the code so the grid size can be changed in future updates easy, but I need to figure out an algorithm to come with number data on the fly so I don't have to hard-code the level data for every level.
- Dav
Code: Select all
'RoCoLoco.txt v1.0
'Coded by Dav, May/2018
'Row & Column number adding puzzle game.
'Touch red numbers inside grid to turn them on/off.
'Each row/column of red numbers must total the number
'on the edge of the grid. When they total up correctly
'the edge numbers will turn green. Turn all the edge
'numbers green to complete the level. Don't go loco...
if lowstr$(device_type$())<>"ipad" then
print "Sorry, game for iPad only right now."
end
end if
option base 1
set orientation vertical
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=7 !size=sw/grid
dim bv(grid*grid),bx(grid*grid),by(grid*grid)
dim fc(grid*grid) 'flag if button on/off
set buttons custom
set buttons font size 74
if grid > 7 then set buttons font size 54
if grid > 9 then set buttons font size 34
draw font size 40
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=grid then goto skip
if bc=grid*grid-grid+1 then goto skip
if bc=grid*grid then goto skip
skip:
bx(bc)=x-size!by(bc)=y!bv(bc)=bc!fc(bc)=1
bc=bc+1
next c
next r
gosub setlevel
gosub drawboard
do
for t=2 to grid*grid-1
if button_pressed(str$(t)) then
'ignore outside rows
if t < grid then break
if t > (grid*grid)-grid then break
for tt=1 to grid*grid step grid
if t = tt then goto skip2
if t = tt+(grid-1) then goto skip2
next tt
notes stop
if fc(t)=1 then
fc(t)=0!notes set "120:sa7"!notes play
else
fc(t)=1!notes set "120:sa6"!notes play
end if
gosub drawboard
gosub checkforwin
end if
skip2:
next t
until 0
end
'========
drawboard:
'========
if levelnew=1 then
s$="" 'generate random notes
for o = 1 to 32
s$=s$&chr$(66+rnd(6))&str$(5+rnd(2))
next o
notes set "92:t"&s$ '23
notes play
end if
'draw inside board
for t=2 to grid*grid-1
'skip corners
if t=grid then goto skipit
if t =grid*grid-grid+1 then goto skipit
'skip outside rows
if t < grid then goto skipit
if t > (grid*grid)-grid then goto skipit
for tt=1 to grid*grid step grid
if t = tt then goto skipit
if t = tt+(grid-1) then goto skipit
next tt
if fc(t)=1 then
fill color 1,.5,.5
draw color 1,1,1
else
fill color .3,.3,.3
draw color 0,0,0
end if
button str$(t) text str$(bv(t)) at bx(t),by(t) size size,size
if levelnew=1 then pause .025
skipit:
next t
'compute and draw left/right rows
for t =2 to grid-1
c=0
for tt=1 to grid -2
if fc(t+(grid*tt))= 1 then c=c+bv(t+(grid*tt))
next tt
draw color 0,0,0
if bv(t)=c then
fill color 0,1,0
fc(t)=1!fc(t+(grid*(grid-1)))=1
else
fill color .5,.5,.5
fc(t)=0!fc(t+(grid*(grid-1)))=0
end if
button str$(t) text str$(bv(t)) at bx(t),by(t) size size,size
n=t+(grid*(grid-1))
if levelnew=1 then pause .025
button str$(n) text str$(bv(n)) at bx(n),by(n) size size,size
next t
'compute and draw top/bottom
for t=grid+1 to (grid*(grid-2)+1) step grid
c=0
for tt=1 to (grid-2)
if fc(t+tt)=1 then c=c+bv(t+tt)
next tt
if bv(t)=c then
fill color 0,1,0
fc(t)=1!fc(t+(grid-1))=1
else
fill color .5,.5,.5
fc(t)=0!fc(t+(grid-1))=0
end if
if levelnew then pause .025
button str$(t) text str$(bv(t)) at bx(t),by(t) size size,size
n=t+(grid-1)
button str$(n) text str$(bv(n)) at bx(n),by(n) size size,size
next t
notes stop
levelnew=0
return
'==========
checkforwin:
'==========
'check down
for t=2 to grid-1
if fc(t)=0 then goto nope
next t
'check across
for t=grid+1 to (grid*5+1) step grid
if fc(t)=0 then goto nope
next t
'made it here, must be completed
level=level+1
notes stop
notes set "7:s(c3eg)(e4cg3)(g4ec)(c5g4e)"
notes play
pause 1
fill color 0,1,0
for i=2 to grid*grid-1
if i=grid then goto skippp
if i=grid*grid-grid+1 then goto skippp
button str$(i) text chr$(9989) at bx(i),by(i) size size,size
pause .015
skippp:
next i
pause .5
for i=2 to grid*grid-1
button str$(i) delete
pause .015
next i
pause .5
levelnew=1
if level>maxlevel then end 'all levels done? end
goto top
nope:
return
'=======
setlevel:
'=======
if level = 1 then
'make first level data
bv(8)=15!bv(15)=7!bv(22)=17!bv(29)=12!bv(36)=9
bv(2)=3!bv(9)=3!bv(16)=1!bv(23)=8!bv(30)=5!bv(37)=5!bv(44)=3
bv(3)=25!bv(10)=2!bv(17)=3!bv(24)=8!bv(31)=9!bv(38)=6!bv(45)=25
bv(4)=7!bv(11)=4!bv(18)=9!bv(25)=2!bv(32)=1!bv(39)=3!bv(46)=7
bv(5)=9!bv(12)=2!bv(19)=4!bv(26)=2!bv(33)=7!bv(40)=3!bv(47)=9
bv(6)=16!bv(13)=6!bv(20)=3!bv(27)=5!bv(34)=2!bv(41)=5!bv(48)=16
bv(14)=15!bv(21)=7!bv(28)=17!bv(35)=12!bv(42)=9
end if
if level = 2 then
'make first level data
bv(8)=10!bv(15)=13!bv(22)=30!bv(29)=6!bv(36)=17
bv(2)=17!bv(9)=6!bv(16)=6!bv(23)=7!bv(30)=2!bv(37)=9!bv(44)=17
bv(3)=21!bv(10)=1!bv(17)=7!bv(24)=9!bv(31)=6!bv(38)=5!bv(45)=21
bv(4)=16!bv(11)=4!bv(18)=2!bv(25)=7!bv(32)=4!bv(39)=3!bv(46)=16
bv(5)=10!bv(12)=3!bv(19)=1!bv(26)=7!bv(33)=7!bv(40)=6!bv(47)=10
bv(6)=12!bv(13)=1!bv(20)=4!bv(27)=7!bv(34)=7!bv(41)=8!bv(48)=12
bv(14)=10!bv(21)=13!bv(28)=30!bv(35)=6!bv(42)=17
end if
if level = 3 then
'make first level data
bv(8)=19!bv(15)=20!bv(22)=15!bv(29)=18!bv(36)=20
bv(2)=26!bv(9)=5!bv(16)=8!bv(23)=1!bv(30)=9!bv(37)=9!bv(44)=26
bv(3)=13!bv(10)=4!bv(17)=2!bv(24)=7!bv(31)=4!bv(38)=7!bv(45)=13
bv(4)=25!bv(11)=7!bv(18)=7!bv(25)=8!bv(32)=7!bv(39)=4!bv(46)=25
bv(5)=19!bv(12)=8!bv(19)=3!bv(26)=6!bv(33)=2!bv(40)=3!bv(47)=19
bv(6)=9!bv(13)=4!bv(20)=3!bv(27)=9!bv(34)=6!bv(41)=1!bv(48)=9
bv(14)=19!bv(21)=20!bv(28)=15!bv(35)=18!bv(42)=20
end if
if level = 4 then
'make first level data
bv(8)=17!bv(15)=10!bv(22)=15!bv(29)=14!bv(36)=18
bv(2)=6!bv(9)=7!bv(16)=5!bv(23)=1!bv(30)=3!bv(37)=7!bv(44)=6
bv(3)=16!bv(10)=4!bv(17)=2!bv(24)=6!bv(31)=8!bv(38)=5!bv(45)=16
bv(4)=21!bv(11)=8!bv(18)=1!bv(25)=8!bv(32)=4!bv(39)=4!bv(46)=21
bv(5)=12!bv(12)=5!bv(19)=2!bv(26)=9!bv(33)=9!bv(40)=5!bv(47)=12
bv(6)=19!bv(13)=4!bv(20)=7!bv(27)=9!bv(34)=6!bv(41)=9!bv(48)=19
bv(14)=17!bv(21)=10!bv(28)=15!bv(35)=14!bv(42)=18
end if
if level = 5 then
'make first level data
bv(8)=12!bv(15)=7!bv(22)=13!bv(29)=17!bv(36)=18
bv(2)=14!bv(9)=7!bv(16)=1!bv(23)=7!bv(30)=5!bv(37)=1!bv(44)=14
bv(3)=19!bv(10)=8!bv(17)=2!bv(24)=7!bv(31)=3!bv(38)=9!bv(45)=19
bv(4)=10!bv(11)=2!bv(18)=6!bv(25)=4!bv(32)=2!bv(39)=6!bv(46)=10
bv(5)=8!bv(12)=9!bv(19)=3!bv(26)=8!bv(33)=7!bv(40)=1!bv(47)=8
bv(6)=16!bv(13)=3!bv(20)=8!bv(27)=6!bv(34)=9!bv(41)=7!bv(48)=16
bv(14)=12!bv(21)=7!bv(28)=13!bv(35)=17!bv(42)=18
end if
if level = 6 then
'make first level data
bv(8)=6!bv(15)=5!bv(22)=12!bv(29)=9!bv(36)=14
bv(2)=9!bv(9)=2!bv(16)=3!bv(23)=3!bv(30)=3!bv(37)=3!bv(44)=9
bv(3)=6!bv(10)=3!bv(17)=3!bv(24)=3!bv(31)=4!bv(38)=3!bv(45)=6
bv(4)=13!bv(11)=3!bv(18)=4!bv(25)=4!bv(32)=2!bv(39)=4!bv(46)=13
bv(5)=6!bv(12)=3!bv(19)=4!bv(26)=3!bv(33)=4!bv(40)=2!bv(47)=6
bv(6)=12!bv(13)=2!bv(20)=2!bv(27)=2!bv(34)=4!bv(41)=4!bv(48)=12
bv(14)=6!bv(21)=5!bv(28)=12!bv(35)=9!bv(42)=14
end if
if level = 7 then
'make first level data
bv(8)=11!bv(15)=8!bv(22)=12!bv(29)=7!bv(36)=14
bv(2)=9!bv(9)=3!bv(16)=4!bv(23)=4!bv(30)=4!bv(37)=2!bv(44)=9
bv(3)=8!bv(10)=4!bv(17)=4!bv(24)=3!bv(31)=4!bv(38)=4!bv(45)=8
bv(4)=15!bv(11)=4!bv(18)=3!bv(25)=4!bv(32)=4!bv(39)=4!bv(46)=15
bv(5)=10!bv(12)=2!bv(19)=2!bv(26)=4!bv(33)=2!bv(40)=4!bv(47)=10
bv(6)=10!bv(13)=4!bv(20)=3!bv(27)=3!bv(34)=3!bv(41)=2!bv(48)=10
bv(14)=11!bv(21)=8!bv(28)=12!bv(35)=7!bv(42)=14
end if
if level = 8 then
'make first level data
bv(8)=13!bv(15)=15!bv(22)=18!bv(29)=10!bv(36)=30
bv(2)=19!bv(9)=4!bv(16)=8!bv(23)=7!bv(30)=6!bv(37)=8!bv(44)=19
bv(3)=14!bv(10)=9!bv(17)=8!bv(24)=4!bv(31)=1!bv(38)=9!bv(45)=14
bv(4)=21!bv(11)=7!bv(18)=6!bv(25)=3!bv(32)=8!bv(39)=7!bv(46)=21
bv(5)=13!bv(12)=7!bv(19)=4!bv(26)=6!bv(33)=4!bv(40)=9!bv(47)=13
bv(6)=19!bv(13)=6!bv(20)=5!bv(27)=7!bv(34)=1!bv(41)=6!bv(48)=19
bv(14)=13!bv(21)=15!bv(28)=18!bv(35)=10!bv(42)=30
end if
if level = 9 then
'make first level data
bv(8)=9!bv(15)=6!bv(22)=14!bv(29)=9!bv(36)=6
bv(2)=13!bv(9)=4!bv(16)=3!bv(23)=4!bv(30)=2!bv(37)=3!bv(44)=13
bv(3)=5!bv(10)=4!bv(17)=2!bv(24)=3!bv(31)=2!bv(38)=4!bv(45)=5
bv(4)=4!bv(11)=2!bv(18)=2!bv(25)=3!bv(32)=2!bv(39)=2!bv(46)=4
bv(5)=11!bv(12)=3!bv(19)=2!bv(26)=3!bv(33)=3!bv(40)=3!bv(47)=11
bv(6)=11!bv(13)=4!bv(20)=4!bv(27)=4!bv(34)=3!bv(41)=3!bv(48)=11
bv(14)=9!bv(21)=6!bv(28)=14!bv(35)=9!bv(42)=6
end if
if level = 10 then
'make first level data
bv(8)=7!bv(15)=11!bv(22)=13!bv(29)=8!bv(36)=4
bv(2)=5!bv(9)=3!bv(16)=2!bv(23)=2!bv(30)=4!bv(37)=4!bv(44)=5
bv(3)=10!bv(10)=2!bv(17)=2!bv(24)=4!bv(31)=4!bv(38)=4!bv(45)=10
bv(4)=6!bv(11)=4!bv(18)=4!bv(25)=2!bv(32)=3!bv(39)=3!bv(46)=6
bv(5)=11!bv(12)=4!bv(19)=4!bv(26)=3!bv(33)=2!bv(40)=2!bv(47)=11
bv(6)=11!bv(13)=2!bv(20)=3!bv(27)=4!bv(34)=2!bv(41)=2!bv(48)=11
bv(14)=7!bv(21)=11!bv(28)=13!bv(35)=8!bv(42)=4
end if
if level = 11 then
'make first level data
bv(8)=4!bv(15)=24!bv(22)=41!bv(29)=19!bv(36)=29
bv(2)=14!bv(9)=1!bv(16)=6!bv(23)=11!bv(30)=7!bv(37)=9!bv(44)=14
bv(3)=25!bv(10)=14!bv(17)=4!bv(24)=12!bv(31)=16!bv(38)=13!bv(45)=25
bv(4)=31!bv(11)=3!bv(18)=13!bv(25)=15!bv(32)=7!bv(39)=17!bv(46)=31
bv(5)=25!bv(12)=12!bv(19)=18!bv(26)=12!bv(33)=3!bv(40)=10!bv(47)=25
bv(6)=22!bv(13)=7!bv(20)=5!bv(27)=2!bv(34)=9!bv(41)=6!bv(48)=22
bv(14)=4!bv(21)=24!bv(28)=41!bv(35)=19!bv(42)=29
end if
if level = 12 then
'make first level data
bv(8)=8!bv(15)=8!bv(22)=15!bv(29)=8!bv(36)=6
bv(2)=10!bv(9)=3!bv(16)=2!bv(23)=4!bv(30)=2!bv(37)=2!bv(44)=10
bv(3)=0!bv(10)=3!bv(17)=2!bv(24)=2!bv(31)=3!bv(38)=2!bv(45)=0
bv(4)=10!bv(11)=4!bv(18)=3!bv(25)=4!bv(32)=4!bv(39)=2!bv(46)=10
bv(5)=16!bv(12)=4!bv(19)=4!bv(26)=4!bv(33)=4!bv(40)=3!bv(47)=16
bv(6)=9!bv(13)=2!bv(20)=2!bv(27)=3!bv(34)=2!bv(41)=2!bv(48)=9
bv(14)=8!bv(21)=8!bv(28)=15!bv(35)=8!bv(42)=6
end if
if level = 13 then
'make first level data
bv(8)=27!bv(15)=26!bv(22)=25!bv(29)=31!bv(36)=15
bv(2)=19!bv(9)=2!bv(16)=7!bv(23)=11!bv(30)=10!bv(37)=12!bv(44)=19
bv(3)=20!bv(10)=6!bv(17)=16!bv(24)=13!bv(31)=7!bv(38)=19!bv(45)=20
bv(4)=26!bv(11)=6!bv(18)=5!bv(25)=12!bv(32)=3!bv(39)=8!bv(46)=26
bv(5)=20!bv(12)=5!bv(19)=4!bv(26)=6!bv(33)=11!bv(40)=4!bv(47)=20
bv(6)=39!bv(13)=14!bv(20)=10!bv(27)=2!bv(34)=12!bv(41)=15!bv(48)=39
bv(14)=27!bv(21)=26!bv(28)=25!bv(35)=31!bv(42)=15
end if
if level = 14 then
'make first level data
bv(8)=39!bv(15)=5!bv(22)=47!bv(29)=36!bv(36)=51
bv(2)=53!bv(9)=11!bv(16)=4!bv(23)=16!bv(30)=7!bv(37)=19!bv(44)=53
bv(3)=49!bv(10)=11!bv(17)=6!bv(24)=19!bv(31)=19!bv(38)=16!bv(45)=49
bv(4)=20!bv(11)=13!bv(18)=5!bv(25)=8!bv(32)=7!bv(39)=8!bv(46)=20
bv(5)=38!bv(12)=17!bv(19)=1!bv(26)=4!bv(33)=3!bv(40)=17!bv(47)=38
bv(6)=18!bv(13)=14!bv(20)=2!bv(27)=15!bv(34)=3!bv(41)=15!bv(48)=18
bv(14)=39!bv(21)=5!bv(28)=47!bv(35)=36!bv(42)=51
end if
if level = 15 then
'make first level data
bv(8)=47!bv(15)=46!bv(22)=50!bv(29)=14!bv(36)=31
bv(2)=24!bv(9)=13!bv(16)=8!bv(23)=12!bv(30)=2!bv(37)=9!bv(44)=29
bv(3)=37!bv(10)=15!bv(17)=1!bv(24)=19!bv(31)=15!bv(38)=18!bv(45)=37
bv(4)=34!bv(11)=11!bv(18)=18!bv(25)=16!bv(32)=5!bv(39)=6!bv(46)=34
bv(5)=42!bv(12)=15!bv(19)=12!bv(26)=13!bv(33)=12!bv(40)=3!bv(47)=42
bv(6)=51!bv(13)=19!bv(20)=16!bv(27)=15!bv(34)=15!bv(41)=1!bv(48)=51
bv(14)=47!bv(21)=46!bv(28)=50!bv(35)=14!bv(42)=31
end if
levelnew=1
return