Game Development Reference
In-Depth Information
Case ShowFlag
'Flags get a blank
Me.Text = ""
End Select
'Placeholder for AI
End If
End If
End Sub
Run the game and right-click some revealed and concealed squares. Mark a
square that you know is safe with a flag. Watch the counters to see the number of
moves and mines remaining decrease. Next, mark a square that you know holds a
mine with a flag. Then click the flagged square that holds a mine. Two interesting
things happen, one good, one bad. The good thing is the flag on the safe square
turns into an X to show that it was incorrectly flagged. We have now tested a bit
of code we wrote earlier. The bad thing is that even though we marked the square
with a flag, the square let us click it in the first place, ending the game.
We can guard against a click on a flagged square. In the Click event, find the
following line of code:
If Not Revealed Then
Then add the following code:
If Not Revealed Then
'Safety code: if marked, ignore the click!
If Me.Text = ShowFlag Then Exit Sub
Test this code by marking a square with a flag and then clicking it. The square
does not reveal itself. If you right-click the square to remove the flag, anything
could happen the next time you click it.
Implementing the AI
We now have a complete Minesweeper game! When the thrill of playing it wears
off, you may wish to review the discussion of a rule-based AI earlier in this
chapter. We need to design the classes that we will use for the rules and for the
framework and extend the game so that the AI can ''see'' what the player sees. We
Search Nedrilad ::

Custom Search