Game Development Reference
In-Depth Information
'If we have an existing game, get rid of it
'Do we have a field?
If Field IsNot Nothing Then
For Each Sq In Field
'If it exists, take it off the form
If Sq IsNot Nothing Then
Sq.Parent = Nothing
End If
End If
'Copy the passed-in parameters to the globals
NumRows = nRows
NumCols = nCols
'Do some error checking
Dim sqcnt As Integer = NumRows * NumCols
If nMines > sqcnt Then
nMines = sqcnt - 1
End If
'Then do the last assignment
NumMines = nMines
'Create the tiles for the new game
'VB uses zero-based arrays
ReDim Field(NumRows - 1, NumCols - 1)
Dim row, col As Integer
For col = 0 To NumCols - 1
For row = 0 To NumRows - 1
'Create an actual object
Sq = New Square(row, col)
'Set the location
Sq.Top = row * Sq.Height
Sq.Left = col * Sq.Width
'Put it on the form
Sq.Parent = Me
'Store it in the array as well for easy access later
Field(row, col) = Sq
'Back to regular cursor
Me.Cursor = Cursors.Default
End Sub
Search Nedrilad ::

Custom Search