Game Development Reference
In-Depth Information
The GetUpperBound function returns the highest valid subscript for the
array. Writing the code this way means fewer things to keep synchronized.
The loop always goes from the beginning of the array to the end. As long as
the two arrays have the same number of items, the same subscript can be
used for both.
Note
The function knows about the radio buttons we added to the form and puts them in an array. If
we wanted to add a third mode, such as an explicit off mode, we would add another radio button
to the form and add the name of that radio button to the array. We would also add a corre-
sponding entry into the Enum and put that entry in the ModeValues array. On the form, VB
groups all radio buttons that have the same container, such as a form, so that checking one
unchecks all of the others.
Note
It is worth noting that explicit knowledge of the world implementation is creeping into the AI
code. We will be successful at keeping it out of the core AI, but the wrapper and the world are
two different files that have to be kept in sync.
23. We still need to interrogate the world about the desired temperature. Add
the following code to AI.vb:
Private Function DesiredTemp(ByVal World As House) As Integer
'We need some subscript variables
Dim ss As Integer
'the hours after midnight but before morning count as night
'02:00 is after 21:00 but before 06:00, use the 21:00 value
Dim foundss As Integer = 3
'exploit the fact that we know that there are exactly 4 points
'and that they are in time-sorted order
For ss = 0 To 3
'if it is at or past this set time, use this set time.
If World.TimeUpDown.Value >= World.SetTimes(ss) Then
foundss = ss
End If
Next
'The times and temps are parallel arrays. A subscript for one
'can be used on the other
 
Search Nedrilad ::




Custom Search