Game Development Reference
In-Depth Information
25. Add the following line of code to all three event handlers:
Call AI.RunAI(Me)
26. The Me in this case refers to the running instance of the form. Observant
readers will have noticed that the Sub that handles the form load event is
marked as Handles Me.Load in the code. Add a comment, and your code
should look like the following:
'We check the furnace at startup and whenever conditions change.
Private Sub House_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Me.Load
Call AI.RunAI(Me)
End Sub
Private Sub Ambient_ValueChanged(ByVal sender As Object, ByVal e As _
System.EventArgs) Handles AmbientUpDown.ValueChanged
Call AI.RunAI(Me)
End Sub
Private Sub SetPointUpDown_ValueChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles SetPointUpDown.ValueChanged
Call AI.RunAI(Me)
End Sub
27. Run the application in the debugger. Note that the status label has the value
Off even though the label starts with the value Undefined. This means that
the form load event triggered. Manipulate both temperature controls and
watch the status change back and forth between Off and Heat. If we had
forgotten either event handler, our furnace would ignore changing condi-
tions of interest to it.
Analysis
The AI code, especially the core AI code, is fast, simple, and reasonably bullet-
proof. But suppose the thermostat were also asked to control the windows,
closing them whenever the furnace is running. The window AI knows exactly the
right thing to do and can execute that action so well that it is a given. (We are not
considering how easy or hard opening or closing the windows might be.) At first
blush, this makes good sense. The windows should be closed when the furnace is
running. But the thermostat will also leave the windows open all summer, even
 
Search Nedrilad ::




Custom Search