Game Development Reference
In-Depth Information
We need to do some work on the Click event handler for the Square class.
Refactor the code that makes the button look pressed as follows. This code uses
the existing comment and property changes, but integrates them into a more
sophisticated block.
If Not Revealed Then
'Below here is where the player finds out if it is safe or not
If contents = HiddenValue.Safe Then
'This square is done
Revealed = True
'Make the button look pressed [reused code from before]
FlatStyle = Windows.Forms.FlatStyle.Flat
Me.BackColor = Color.LightGray
'Tell the user how many are near (if any)
If actualNearMines > 0 Then
Me.Text = actualNearMines.ToString
'Implement free moves here
End If
'One fewer move left to make
'Make bad things happen here
Me.Text = ShowMine
End If
End If
If the user or the AI does click a mine, the Square object asks PlayingField to tell
all the squares that the game is over. We will now add code to the Square class so
that it can take end-of-game actions. Add the following code to the class:
'It no longer matters
Public Sub Endgame()
'If it is the end of the game,
'I cannot be clicked (stops cheats)
Me.Enabled = False
If Not Revealed Then
If contents = HiddenValue.Mine Then
'If they did not flag me, show the mine
If Me.Text <> ShowFlag Then
Me.Text = ShowMine
End If
Search Nedrilad ::

Custom Search