Floodit (BBC Micro) by David Payne
A downloadable game
Flood It
The object of this puzzle game is to change all of the blocks to the same colour in 25 moves or less.
At the start of the game all of the blocks are randomly coloured.
In each move you change the colour of the top left block, all orthogonally connected blocks of the same colour will also change to the new colour.
Keys:
1 - Red
2 - Green
3 - Yellow
4 - Blue
5 - Magenta
6 - Cyan
variables used (all variables are global)
a(29,14) - the 2d array containing the block colours
r - used to seed the pseudo random number generator
x,y - the x and y coordinates of a block
e - the maximum moves allowed (25)
c - loop counter when displaying the colour keys, also later used for old colour
m - the number of moves made
d - new colour
z - set to 4 when all blocks are the same colour, 0 if not
q - when this is set to 1 display the block instead of doing the flood fill
Program explanation (referring to the expanded version)
initialisation section
10MODE2
disable cursor
11VDU23,1,0;0;0;0;
define the graphics character for the block
12!&C00=-1
13!&C04=-1
14DIMa(29,14)
seed the pseudo random number generator
15r=RND(-TIME)
select a random colour for each block, display the blocks (2 characters per block)
16FORy=0TO29
20FORx=0TO14
21a(y,x)=RND(6)
22VDU17,a(y DIV2,x),224
23NEXT
24PRINT
25NEXT
set maximum moves allowed
26e=25
27COLOUR7
30PRINT"Moves: 0/";e
set a small text window, display the colour keys in it
31VDU28,17,2,19,0,17,0
32FORc=49TO54
33VDU17,c+80,c
34NEXT
clear text window, set colours back to default palette
35VDU26,20
initialise move counter to 0
40m=0
main game loop
41REPEAT
set old colour to top left block colour
42c=a(0,0)
get a valid key press for new colour (d) must not be same as old colour
43REPEAT
44d=GET-48
45UNTILd>0ANDd<7ANDd<>c
perform a flood fill starting at top left block, changing blocks from colour c to colour d
46x=0
47y=0
48PROCf
increment move counter
49m=m+1
display move counter
50VDU17,7,31,7+(m>9),30
51PRINT;m;
check if all blocks are now colour d
52z=4
53FORy=0TO14
54FORx=0TO14
55z=z ANDa(y,x)=d
56NEXT,
end game when all blocks have been changed to colour d or maximum number of moves have been made
60UNTILz ORm=e
display win/lose message
61PRINT"/";e;" You ";MID$("losewin!",z+1,4);
enable cursor
62VDU23,1,1;0;0;0;
end program
63END
flood fill algorithm
70DEFPROCf
set block to new colour
71a(y,x)=d
display it
72q=1
73GOSUB80
74q=0
if block to the left is colour c then continue flood fill in that direction
75IFx>0THENIFa(y,x-1)=c THENx=x-1:PROCf:x=x+1
if q then display top half of block
if block to the right is colour c then continue flood fill in that direction
80IFq THENVDU31,x,y*2,17,d,224 ELSEIFx<14THENIFa(y,x+1)=c THENx=x+1:PROCf:x=x-1
if q then display bottom half of block
if block above is colour c then continue flood fill in that direction
90IFq THENVDU8,10,224:RETURN ELSEIFy>0THENIFa(y-1,x)=c THENy=y-1:PROCf:y=y+1
if block below is colour c then continue flood fill in that direction
100IFy<14ANDa(y+1,x)=c THENy=y+1:PROCf:y=y-1:ENDPROC ELSEENDPROC
Status | Released |
Author | BASIC 10Liner |
Genre | Strategy |
Tags | 8-Bit, basic, basic10liner, bbcmicro |
Install instructions
The emulator that I used is an online one: JSBeeb - https://bbc.godbolt.org
Simply copy and paste the source code into it and then type RUN
Comments
Log in with itch.io to leave a comment.
I like it but i cannot finish the game, because i always received "No room at line 80" error. Can you help me please?
Owlet by D. Payne - YouTube