flood fill

hasnain_razwi

Member
Joined
Oct 21, 2003
Messages
15
Location
Melbourne, Australia
hi once again. how does a flood fill algorithm work. ive heard about it but never seen it in action. i need to use something like it in vb.net code for a minesweerper game. i have created a two dimensional array of buttons. there are a total of 81 buttons (8,8) i.e 9 columns and 9 rows. i need to check how many mines there are adjacent to the button that i click on. so i want to search for mines all around my button and then expand the search onwards. any advice on how this can be done?
many thanks.
 
For a Flood Fill algorithm, you can do it recursively where you call the Flood Fill algorithm for the four surrounding blocks if they are enabled, and just do whatever you want to do to each block from there.
Code:
Sub FloodFill(X As Integer, Y As Integer)
  Button(X, Y).Enabled = True
  Do anything else that you want to this button.
  If Button(X-1, Y).Enabled Or Button(X-1, Y).Text.Length > 0 Then
    FloodFill(X-1, Y)
  End If
  If Button(X, Y-1).Enabled Or Button(X, Y-1).Text.Length > 0 Then
    FloodFill(X, Y-1)
  End If
  etc. for the X+1,Y and X,Y+1
End Sub
:)
 
Back
Top