Game Development Reference
In-Depth Information
'Removing a flag
Public Sub IncrementMinesLeft()
MinesLeftLabel.Text = (CInt(MinesLeftLabel.Text) + 1).ToString
End Sub
Another demand that the squares will place on PlayingField is to end the game if
the player clicks on a mine. The field will do this by telling each square that the
game is over and letting the squares act appropriately. Add the following code to
the PlayingField class:
'Something bad happened and a square is calling for the game to end
Public Sub EndGame()
Dim Sq As Square
'Tell them all
For Each Sq In Field
End Sub
That dealt with PlayingField . Now onto the squares. A square needs to be able to
determine whether its contents have been revealed. It will not want to tell the AI
how many mines are near it if it has not been revealed, and it will treat the mouse
differently as well. Add the following code to the Square class just below the
declarations for contents and actualNearMines :
'Have I been clicked or not?
Private Revealed As Boolean
Boolean variables initialize to False . The AI will also want to ask the square if it is
revealed, so we should support that capability as well while we are at it. Add the
following code to the Square class:
'The outside world will want to ask us
Public ReadOnly Property IsRevealed() As Boolean
Return Revealed
End Get
End Property
We needed to control how the Square object exposes the private variable
Revealed to the outside world. Properties allow us to have code between internal
data and the outside world. Unlike functions, properties can be either or both
directions (read or write) using the same name.
Search Nedrilad ::

Custom Search