'==========
'FLIPIT.BAS v1.0
'==========
'Like the lights out color flip puzzle.
'Try to make all squares the same by flipping them.
'When you select a square, its color will flip, and
'its neighboring squares will also flip colors.
'Coded by Dav for QB64, SEP/2018
'define button grid deminsions
DIM SHARED grid: grid
= 8 ' size of grid is 8x8 DIM SHARED size: size
= 65 ' size of buttons is 65x65 DIM SHARED btns: btns
= grid
* grid
' number of buttons on grid
'define button data
DIM SHARED bx
(btns
), by
(btns
) ' top x/y cords of buttons DIM SHARED bx2
(btns
), by2
(btns
) ' bottom x/y cords of buttons
'set screen based on grid & size
'set button values
bc = 1 'counter
x = (row * size): y = (col * size)
bx(bc) = x - size: bx2(bc) = x ' generate x/y values
by(bc) = y - size: by2(bc) = y
bv(bc) = 0 'set to 0, button off
bc = bc + 1
bv
(INT(btns
/ 2)) = 1 'set one random button ON
updateboard
'==== MAIN GAME LOOP
_LIMIT 60 'to save CPU cycles - the program even starts faster on my XP virtual machine
'handle button pressed
'change the clicked button
setbv "U", t 'now change 1 up above t
setbv "D", t 'now change 1 down t
setbv "L", t 'now change the left
setbv "R", t 'now change the right
updateboard
'wait until mouse button up to continue
'==============================================
LINE (bx
(b
), by
(b
))-(bx2
(b
), by2
(b
)), _RGB(55, 55, 55), BF
LINE (bx
(b
), by
(b
))-(bx2
(b
), by2
(b
)), _RGB(88, 88, 88), B
LINE (bx
(b
), by
(b
))-(bx2
(b
), by2
(b
)), _RGB(88, 88, 88), BF
LINE (bx
(b
), by
(b
))-(bx2
(b
), by2
(b
)), _RGB(55, 55, 55), B
'==============================================
'sets new button values.
IF bv
(b
- 1) = 0 THEN bv
(b
- 1) = 1 ELSE bv
(b
- 1) = 0
IF bv
(b
+ 1) = 0 THEN bv
(b
+ 1) = 1 ELSE bv
(b
+ 1) = 0
IF bv
(b
- grid
) = 0 THEN bv
(b
- grid
) = 1 ELSE bv
(b
- grid
) = 0
FOR j
= btns
- grid
+ 1 TO btns
IF bv
(b
+ grid
) = 0 THEN bv
(b
+ grid
) = 1 ELSE bv
(b
+ grid
) = 0