Just move the 4 coloured round pieces to their respective coloured (home or goal) positions.
To slide a coloured piece : right click and drag.
A coloured piece can only move to into an empty space ( black = empty).
A home or goal square is a valid space to move into if it is empty ie you have moved the round coloured piece
from it and it now shows a black circle.
Inspiration came from this site : https://layton.fandom.com/wiki/Puzzle:Four_Balls
64 Bit only.
Code: Select all
' 64 Bit Only
' 4Balls.bas Move each round piece to the area with the same colour
screenres 480, 480, 32
const as ulongint mask = &HFFFB83C3C3C1DFFF
const as double pi = 3.1415926535897932
type board
bb as ulongint
colour as integer
end type
dim as board piece(12)
dim as integer i, j, move
data &H4000000000000, rgb(215, 40, 40) ' red goal 0
data &H20000, rgb(40, 40, 215) ' blue goal 1
data &H2000, rgb(60, 200, 60) ' green goal 2
data &H400000000000, rgb(215, 215, 40) ' yellow goal 3
data &H4000000000000, rgb(14, 243, 14) ' green circle 4
data &H20000, rgb(243, 243, 14) ' yellow circle 5
data &H2000, rgb(243, 12, 12) ' red circle 6
data &H400000000000, rgb(14, 14, 243) ' blue circle 7
data &HC0000000000, rgb(13, 243, 13) ' green piece 8
data &H300000, rgb(12, 243, 12) ' green piece 9
data &H202000000000, rgb(13, 13, 243) ' blue piece 10
data &H4040000, rgb(12, 12, 243) ' blue piece 11
data &H1818000000, rgb(243, 10, 10) ' red square piece 12
for i = 0 to 12
read piece(i).bb
read piece(i).colour
next
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
sub brick(x as integer, y as integer, x1 as integer, y1 as integer)
dim as integer temp, a = 0, b = 20
line (x, y) - (x1, y1),rgb(127, 127, 127) ,bf
line (x, y) - (x1, y1), ,b
while y < y1
line (x, y) -(x1, y)
y += 20
swap a, b
temp = x + a
while temp < x1
line (temp, y - 20) - (temp, y)
temp += 40
wend
wend
end sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
sub display(piece() as board, move as integer)
dim as integer i, j, k, c
windowtitle "Move each round piece to its coloured area : " +str(move)
screenlock()
cls
brick(0, 0, 319, 79)
brick(400, 0, 479, 319)
brick(160, 400, 479, 479)
brick(0, 160, 79, 479)
for k = 0 to 12
c = 54
for i = 0 to 7
for j = 0 to 7
if bit(piece(k).bb, c) = -1 then
select case k
case 0 to 3
line (j * 80, i * 80) - (j * 80 + 79, i * 80 + 79), piece(k).colour, bf
circle (j * 80 + 40, i * 80 + 40), 32, 0, , , , f
case 4 to 7
circle (j * 80 + 40, i * 80 + 40), 30, piece(k).colour, , , , f
case 8 to 12
line (j * 80, i * 80) - (j * 80 + 79, i * 80 + 79), piece(k).colour, bf
end select
end if
c -= 1
next
next
next
screenunlock()
end sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function getmove( piece() as board) as integer
dim as integer x, y, buttons, res, i ,j, oldx, oldy, r, c, target, z
dim as uinteger dum
dim as ulongint all,temp
for i = 4 to 12
all or= piece(i).bb
next
do
res=getmouse(x,y,,buttons)
if inkey = chr(255,107) then end
if res = 0 then
oldx = x
oldy = y
end if
res=getmouse(x,y,,buttons)
if res = 0 then
if (buttons and 1) then
z=1
dum = point(x, y)
end if
end if
loop while z = 0
do
getmouse(x,y,,buttons)
loop while (buttons and 1)
r=x-oldx
c=y-oldy
select case dum
case rgb(14, 243, 14)
target = 4
case rgb(243, 243, 14)
target = 5
case rgb(243, 12, 12)
target = 6
case rgb(14, 14, 243)
target = 7
case rgb(13, 243, 13)
target = 8
case rgb(12, 243, 12)
target = 9
case rgb(13, 13, 243)
target = 10
case rgb(12, 12, 243)
target = 11
case rgb(243, 10, 10)
target = 12
case else
return 0
end select
temp = 0
if r<> 0 or c<> 0 then
if abs(r) > abs(c) then
if r > 0 then temp = (piece(target).bb shr 1)
if r < 0 then temp = (piece(target).bb shl 1)
end if
if abs(r) < abs(c) then
if c > 0 then temp = (piece(target).bb shr 8)
if c < 0 then temp = (piece(target).bb shl 8)
end if
if (temp and mask) = 0 then
if ((all xor piece(target).bb) and temp) = 0 then
piece(target).bb = temp
return 1
end if
else
return 0
end if
end if
return 0
end function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
function wincheck(piece() as board) as integer
dim as integer i, j, x(3), y(3)
if piece(6).bb = piece(0).bb and piece(7).bb = piece(1).bb and piece(4).bb = piece(2).bb and piece(5).bb = piece(3).bb then
x(0) = 360 : y(0) = 40
x(1) = 440 : y(1) = 360
x(2) = 120 : y(2) = 440
x(3) = 40 : y(3) = 120
for i = 0 to 3
circle (x(i) - 10, y(i) - 5), 5, rgb(0, 0, 0), , , , f
circle (x(i) + 10, y(i) - 5), 5, rgb(0, 0, 0), , , , f
for j = 1 to 30 step 2
circle (x(i), y(i) + 8), 15, rgb(0, 0, 0), pi , 2 * pi, 0.54 + (j * .005)
next
next
sleep 2000
for i = 0 to 3
circle (x(i) + 10, y(i) - 5), 5 , point(x(i), y(i)), , , , f
circle (x(i) + 10, y(i) - 5), 5, rgb(0, 0, 0), pi, 2 * pi, .75, f
next
sleep 500
for i = 0 to 3
circle (x(i) + 10, y(i) - 5), 5, rgb(0, 0, 0), , , , f
next
return 1
end if
return 0
end function
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' main
display(piece(), move)
do
while getmove(piece()) = 0
wend
move += 1
display(piece(), move)
sleep 50
loop while wincheck(piece()) = 0
sleep