home *** CD-ROM | disk | FTP | other *** search
- >> BTW, why would you want to use recursion for this Mines-clone. You
- >> could just check the array, could you not?
- >No, because I have to know which clear squares connect to which. I mean,
- >what do you exactly mean with checking the array. AFAIK checking the
- >array implies resorting to some form of recursive programming.
- >(I learned that term from someone who sent me an example once of the
- >core of minesweeper, and he spoke of recursive programming.)
- >
- >So, could anyone post me something similar?
-
- The core of the "step" routine would look something like this:
-
- Procedure _STEP[X,Y]
- 'W and H are the width and height of the board
- Shared W,H
-
- If BOARD(X,Y)=-1
- 'Oops, he stepped on a mine
- Else If BOARD(X,Y)>0
- 'Display the count of surrounding mines
- DISP_COUNT[X,Y]
- Else
- 'Square is clear, display it and step on surrounding squares
- DISP_CLEAR[X,Y]
- 'Loop through surrounding squares. Min() and Max() make sure we
- 'don't go off the edge.
- For Y2=Max(0,Y-1) To Min(H-1,Y+1)
- For X2=Max(0,X-1) To Min(W-1,X+1)
- If X2<>X or Y2<>Y
- 'Call _STEP recursively to step on the surrounding squares.
- _STEP[X2,Y2]
- End If
- Next X2
- Next Y2
- End If
- End Proc
-
- Anybody get the idea I've written one too? :) For that matter, I even
- did a 3-D one, if anyone's interested.
-
- --Andy Church (achurch@goober.mbhs.edu)
- WWW: http://www.mbhs.edu/~achurch/
-
-