Hey - I've been given a gutted version of Minesweeper, and been asked to reconstruct it. I'm taking it piece by piece, and I've got some parts working. What I'm trying to get now is the 'Zone Clearing'.

Just quickly: Zone clearing is when you click a 'blank' square, all of the blank squares touching it are revealed, as are the blank ones touching them, and so forth. I believe that some of the numbered squares are revealed too, but that can wait.

My teacher mentioned a recursive function, but I'm not sure how that would work.
My idea of how to make this work involves referencing an element of the 'Controls' array; more specifically an Image (eg.

sender.Image

)

The only way of changing such an element that I know of is the

sender

function, as shown above. If there is another way of changing the the

.Image

property, I would be grateful. If, on the other hand, there is a completely different way of clearing zones, I would be grateful if you could hint (possibly very heavily) in that direction.

I have attached my entire VB.NET project to help.

thanks,

debugger

a recursive function is a function that calls itself.

for example:

function zoneClear(square as integer)

'check each of 8 surrounding squares.
'3 possibilities. one its eligible to clear. two its already clear, 3 it has a bomb.

'do this 8 times

'calculate square + some number to get one up square

square = etc

'this is the recursive part.

if square can be cleared then

board[up-square]=0;
zoneClear(up-square);
end if

'now 7 more to go
' each square you clear will call zoneClear like it was the first square that was clicked on. it will stop eventually because the squares around the spot you call on will either already be clear or have a bomb or be at a boundary like edge of board. For example the one up square wont call itself on the one down ( this square) cause its already clear.

end function

Thanks! Could you possibly tell me what the "Return 0" part of the code does?

Thanks!!

I don't see a return 0 in my code. You dont need a return value. you can pass the square to start looking around in by value. your board or grid should be shared by all function calls so maybe its declared on a level that the whole class has access to it or its passed in the function calls by reference. I wrote it in vb scripting but it was sort of pseudo code to give idea. I'm on a vb.net project now but haven't used the vb syntax much lately.

Edited 6 Years Ago by adams161: n/a

I sort of assumed you had a board array or grid array. A typical way to design a board game is to represent the board in an array.

if your grid was 20 by 20 you could declare it as two dimensional (20)(20). then you add to your indexes ( call them w and h) to get to the square next to it or up one. you could do it all in an array 400 as well. + 20 here moves up one row. so the two indexes for 2 dimensional or one index value for one dimensional are passed recursively in my example.

You would set the board or grid spot at the right array index to some value that said it was cleared each time you cleared a square then pass that array index of the cleared square recursively. Also i guess the first step in zoneClear function is to clear the square that they first clicked on, that clearing doesn't have to call itself recursively.

Edited 6 Years Ago by adams161: n/a

This article has been dead for over six months. Start a new discussion instead.