'=========
'MAKE5.bas
'=========
'A board clearing puzzle game.
'Clear the board of balls, score points.
'Coded by Dav, JAN/2021
'Colored balls appear randomly on playing board.
'Move the bigger balls of same color next to each other.
'Make row/column of 5 or more balls to erase them and score.
'Three new balls will appear after every move.
'The small balls will grow into big ones on next move.
'You can place the big balls on top of the smaller ones.
'See how many points you can score before running out of space.
'=========================================================
'=== define board info
rows
= 9: cols
= 9: size
= _WIDTH / cols
DIM SHARED box.v
(rows
* cols
), box.s
(rows
* cols
) 'value, size DIM SHARED box.x
(rows
* cols
), box.y
(rows
* cols
) 'x/y's
'=======
restart:
'=======
score = 0
bc = 1 'counter
x = (r * size)
y = 50 + (c * size)
box.x(bc) = x - size
box.y(bc) = y - size
box.v(bc) = 0 'zero means no color, empty box
box.s(bc) = 1 ' 1 = small size piece
bc = bc + 1
MakeNewBalls 3, 1 'add 3 big new balls to board
MakeNewBalls 3, 2 'add 3 small balls to board
'====
main:
'====
selected = 0
UpdateBoard
second: 'Go back here when making second choice
'wait until mouse button up to continue
'highlight box when a box is selected
LINE (box.x
(t
) + 2, box.y
(t
) + 2)-(box.x
(t
) + size
- 2, box.y
(t
) + size
- 2), _RGB(RND * 255, RND * 255, RND * 255), B
LINE (box.x
(t
) + 3, box.y
(t
) + 3)-(box.x
(t
) + size
- 3, box.y
(t
) + size
- 3), _RGB(RND * 255, RND * 255, RND * 255), B
LINE (box.x
(t
) + 4, box.y
(t
) + 4)-(box.x
(t
) + size
- 4, box.y
(t
) + size
- 4), _RGB(RND * 255, RND * 255, RND * 255), B
'If user clicked mouse
'see where they clicked
'cycle through all Check blocks...
FOR t
= 1 TO (rows
* cols
)
'Block loction...
tx = box.x(t): tx2 = box.x(t) + size
ty = box.y(t): ty2 = box.y(t) + size
'if clicked on a box clicked
'if this is a first choice...
'only select boxes not empty, with big size balls
selected = 1
SOUND 3000, .1 'made a select oldt = t
oldtv = box.v(t) 'save picked box number color
GOTO second
'now get second choice
IF selected
= 1 THEN 'making second choice
'if selected an empty box or small ball
'swap 2nd box data
box.v(t) = oldtv
box.s(t) = 2
'erase 1st box data
box.v(oldt) = 0
box.s(oldt) = 1
UpdateBoard
'===============================
'Grow small balls
IF box.v
(d
) <> 0 AND box.s
(d
) = 1 THEN box.s
(d
) = 2
UpdateBoard
'check Rows for 5 or more done
CheckRow i
'Check Cols for 5 or more
CheckCol i
'See how many boxes left to use...
howmany = 0
'empty ones
IF box.v
(h
) = 0 THEN howmany
= howmany
+ 1
'If not enough spaces left, game over
LINE (200, 250)-(400, 350), _RGB(0, 0, 0), BF
LINE (200, 250)-(400, 350), _RGB(255, 255, 255), B
PPRINT
233, 285, 18, _RGB(255, 255, 255), 0, "GAME OVER"
'make 3 more random small balls
MakeNewBalls 3, 1
'if clicked on another big ball instead...
'clear previous highlighted selection
selected = 0
UpdateBoard
selected = 1
oldt = t
oldtv = box.v(t) 'save picked box number color
'space to hold box nums to clear
'found some to clear flag
rdone = 0
'set place and num
rc = 1
nums(1) = num
'step through the boxes
FOR r
= (num
+ 1) TO (num
+ 8)
'if this box is same as previous...
IF box.s
(r
) = 2 AND box.v
(r
) = box.v
(nums
(rc
)) THEN 'store this box value in nums too
nums(rc + 1) = r
'increase how many so far
rc = rc + 1
'bot same, so reset
'no more, so start over from here
rc = 1: nums(1) = r
'no more can exists on line
'if there was 5 or more found
'if group was found, clear
'step through nums values
score = score + 55 '55 points per ball
x = box.x(nums(d)): y = box.y(nums(d))
LINE (x
+ 2, y
+ 2)-(x
+ size
- 2, y
+ size
- 2), _RGB(255, 255, 255), BF
LINE (x
+ 2, y
+ 2)-(x
+ size
- 2, y
+ size
- 2), _RGB(64, 64, 64), BF
box.v(nums(d)) = 0: box.s(nums(d)) = 1
'space to hold box nums to clear
'found some to clear flag
rdone = 0
'set place and num
rc = 1
nums(1) = num
'step through the boxes
'if this box is same as previous...
IF box.s
(r
) = 2 AND box.v
(r
) = box.v
(nums
(rc
)) THEN 'store this box value in nums too
nums(rc + 1) = r
'increase how many so far
rc = rc + 1
'bot same, so reset
'no more, so start over from here
rc = 1: nums(1) = r
'no more can exists on line
'if there was 5 or more found
'if group was found, clear
'step through nums values
score = score + 55 'add to score
x = box.x(nums(d)): y = box.y(nums(d))
LINE (x
+ 2, y
+ 2)-(x
+ size
- 2, y
+ size
- 2), _RGB(255, 255, 255), BF
LINE (x
+ 2, y
+ 2)-(x
+ size
- 2, y
+ size
- 2), _RGB(64, 64, 64), BF
box.v(nums(d)) = 0: box.s(nums(d)) = 1
PPRINT
20, 14, 14, _RGB(200, 200, 200), 0, "SCORE:" + LTRIM$(STR$(score
)) IF score
>= hiscore
THEN hiscore
= score
PPRINT
475, 14, 14, _RGB(200, 200, 200), 0, "HI:" + LTRIM$(STR$(hiscore
)) PPRINT
220, 10, 20, _RGB(255, 255, 255), 0, "-=MAKE5=-"
'=== draw board based on box values
bc = 1 'counter
'=== if empty box
LINE (box.x
(bc
) + 2, box.y
(bc
) + 2)-(box.x
(bc
) + size
- 2, box.y
(bc
) + size
- 2), _RGB(64, 64, 64), BF
LINE (box.x
(bc
) + 2, box.y
(bc
) + 2)-(box.x
(bc
) + size
- 2, box.y
(bc
) + size
- 2), _RGB(64, 64, 64), BF
'=== draw color ball
x2 = box.x(bc) + (size / 2) 'find middle of box
y2 = box.y(bc) + (size / 2)
IF box.s
(bc
) = 1 THEN sz
= size
/ 4 ELSE sz
= size
/ 2 CASE IS = 1: r
= 255: g
= 64: b
= 64 'red CASE IS = 2: r
= 0: g
= 128: b
= 0 'green CASE IS = 3: r
= 64: g
= 64: b
= 255 'blue CASE IS = 4: r
= 255: g
= 255: b
= 0 'yellow CASE IS = 5: r
= 255: g
= 255: b
= 255 bc = bc + 1
SUB MakeNewBalls
(num
, ballsize
) 'Assign 3 new balls
ball = 0
c
= INT((RND * (cols
* rows
)) + 1) box.s(c) = ballsize
ball = ball + 1
SUB PPRINT
(x
, y
, size
, clr&
, trans&
, text$
) x1 = x + (t * size): x2 = x1 + size
y1 = y: y2 = y + size
_PUTIMAGE (x1
- (size
/ 2), y1
)-(x2
, y2
+ (size
/ 3)), pprintimg&