Game Development Reference
In-Depth Information
VB initializes integer values to zero, so we do not have to explicitly set actual-
NearMines to zero.
While we are working with the Square object, we should create the routine that
lets the playing field initialize it. This routine will store the hidden value and tell
the neighbors to increment their count of the mines near them. Add the following
code to the Square class:
'Load the square with its hidden value
Public Sub Init(ByVal HV As HiddenValue, ByVal Neighbors As Collection)
contents = HV
'If that was a mine, the surrounding counts need to go up
If contents = HiddenValue.Mine Then
'Let the neighbors know
Dim Sq As Square
For Each Sq In Neighbors
Call Sq.IncrementMineCount()
Next
End If
'Debugging code to comment out later
If contents = HiddenValue.Mine Then
'Use @ to mark a mine
Me.Text = ShowMine
End If
'End debugging code
End Sub
We are calling IncrementMineCount , but we have not written it yet, so it will be
marked as an error for now. We have included debugging code so that as soon as
possible, we can fire up the application and make sure that what we have so far
works. As soon as it does, we will comment out the code because it gives away
secret data, but we will leave it in case we need it later. We need to add the
IncrementMineCount routine to the class:
'Some unknown neighbor is telling us that they have a mine
Public Sub IncrementMineCount()
'Add one to the existing count
actualNearMines += 1
'Debugging code to comment out later
'If I am not a mine, show my count
 
Search Nedrilad ::




Custom Search