Game Development Reference
In-Depth Information
Rules
It is time to design the rules and the framework to make use of them. We start
with the rules. All the different rules have common elements. For example, every
rule proposes a set of moves as part of the matching phase. In addition, every rule
needs to execute its proposal when selected for execution by the framework. Add
a class to the project and name it BasicRule.vb. Mark it MustInherit and add code
to get the following:
Public MustInherit Class BasicRule
'Child classes and outside helpers need this
Public Enum PossibleActions
BlanksToFlags
ClickBlanks
End Enum
'We need to remember what move we propose
Protected SimonSays As PossibleActions
'And the targets of that action
Protected SquaresList As New Collection
'All rules must have tell how well they match
Public MustOverride Function Matches(ByVal RevealedSquare As Square) As Integer
'The match routine stores our proposal for possible execution
Public Sub Execute()
Dim Sq As Square
For Each Sq In SquaresList
'We only ever do unknown blanks
If (Not Sq.IsRevealed) And (Sq.Text = "") Then
'What did we propose to do?
Select Case SimonSays
Case PossibleActions.ClickBlanks
Call Sq.LeftClick()
Case PossibleActions.BlanksToFlags
Call Sq.RightClick()
End Select
End If
Next
End Sub
End Class
 
Search Nedrilad ::




Custom Search