Searched
AS _BYTE 'has tile been matched Matched
AS _BYTE 'set when the total number of connected tiles is greater than Min_match ' used to remove matched tiles
'define the game board
DIM SHARED Board
(-1 TO 21, -1 TO 21) AS Tile_Data
'1 space boarder buffer area
'fill game board with data
Board
(X%%
, Y%%
).ID
= INT(RND * 6) + 1 Board(X%%, Y%%).Searched = 0
IF NOT Board
(X%%
, Y%%
).Searched
THEN result%%
= Check_Tiles
(X%%
, Y%%
, Board
(X%%
, Y%%
).ID
) display_board
'display the board
FUNCTION Check_Tiles%%
(StartTileX%%
, StartTileY%%
, Match%%
) 'StartTileX%%- the board X location to start the search from
'StartTileY%%- the board Y location to start the search from
'Match%%- the tile id to be looking for
'current run depth
Depth%% = Depth%% + 1
LINE (7 + 16 * StartTileX%%
, 0 + 14 * (StartTileY%%
))-STEP(7, 14), 4, B
'--------------------check tiles in 4 cardial directions------------------
'check up
IF Board
(StartTileX%%
, StartTileY%%
- 1).ID
= Match%%
THEN 'we find a match IF NOT Board
(StartTileX%%
, StartTileY%%
- 1).Searched
THEN 'this spot has not already been matched Count%% = Count%% + 1 'Total number of matches
Board(StartTileX%%, StartTileY%% - 1).Searched = TRUE 'make sure the next function run(if any) does not match this location again
LINE (7 + 16 * StartTileX%%
, 0 + 14 * (StartTileY%%
- 1))-STEP(7, 13), 12, B
result%% = Check_Tiles(StartTileX%%, StartTileY%% - 1, Match%%) 'move to the matched tile
'_DELAY .25
'check down
IF Board
(StartTileX%%
, StartTileY%%
+ 1).ID
= Match%%
THEN 'we find a match IF NOT Board
(StartTileX%%
, StartTileY%%
+ 1).Searched
THEN 'this spot has not already been matched Count%% = Count%% + 1 'Total number of matches
Board(StartTileX%%, StartTileY%% + 1).Searched = TRUE 'make sure the next function run(if any) does not match this location again
LINE (7 + 16 * StartTileX%%
, 0 + 14 * (StartTileY%%
+ 1))-STEP(7, 13), 12, B
result%% = Check_Tiles(StartTileX%%, StartTileY%% + 1, Match%%) 'move to the matched tile
'_DELAY .25
'check left
IF Board
(StartTileX%%
- 1, StartTileY%%
).ID
= Match%%
THEN 'we find a match IF NOT Board
(StartTileX%%
- 1, StartTileY%%
).Searched
THEN 'this spot has not already been matched Count%% = Count%% + 1 'Total number of matches
Board(StartTileX%% - 1, StartTileY%%).Searched = TRUE 'make sure the next function run(if any) does not match this location again
LINE (7 + 16 * (StartTileX%%
- 1), 0 + 14 * StartTileY%%
)-STEP(7, 13), 14, B
result%% = Check_Tiles(StartTileX%% - 1, StartTileY%%, Match%%) 'move to the matched tile
'check right
IF Board
(StartTileX%%
+ 1, StartTileY%%
).ID
= Match%%
THEN 'we find a match IF NOT Board
(StartTileX%%
+ 1, StartTileY%%
).Searched
THEN 'this spot has not already been matched Count%% = Count%% + 1 'Total number of matches
Board(StartTileX%% + 1, StartTileY%%).Searched = TRUE 'make sure the next function run(if any) does not match this location again
LINE (7 + 16 * (StartTileX%%
+ 1), 0 + 14 * StartTileY%%
)-STEP(7, 13), 14, B
result%% = Check_Tiles(StartTileX%% + 1, StartTileY%%, Match%%) 'move to the matched tile
'----------------------------------------------------------------------------
IF Count%%
>= Min_Match
THEN Board
(StartTileX%%
, StartTileY%%
).Matched
= TRUE
Check_Tiles = Count%% 'return how many tiles matched(only used by Main loop)
IF Depth%%
= 1 THEN Count%%
= 0: Depth%%
= 0 ELSE Depth%%
= Depth%%
- 1