Game Development Reference
In-Depth Information
Dim Needs As New Collection
'Simple list of names of activities.
Dim ActivityNames As New Collection
Public Sub Add(ByVal Activity As String, ByVal Satisfies As String)
Dim Category As Collection
If Not ToDo.Contains(Satisfies) Then
'Must be a new need.
Debug.WriteLine("Creating " & Satisfies)
Needs.Add(Satisfies)
'Different needs get their own category.
Category = New Collection
ToDo.Add(Category, Satisfies)
Else
Category = CType(ToDo.Item(Satisfies), Collection)
End If
'Now add the activity to the category.
If Not Category.Contains(Activity) Then
Debug.WriteLine("Adding " & Activity & " to " & Satisfies)
Category.Add(Activity, Activity)
End If
'Keep a simple list of names of activities.
If Not ActivityNames.Contains(Activity) Then
ActivityNames.Add(Activity, Activity)
End If
End Sub
End Class
When our main code initializes the database, it will add each activity with its need
to the database. The ToDo collection of collections lets us use a need name to get a
collection of activities that meet that need. The name of the need is used as a key
in ToDo to find the subtending collection. Along the way, we keep simple lists of
activities and needs so that other code can iterate through them. Much of the rest
of the code keeps us from adding the same thing twice or does explicit type
conversions.
Since everything depends on the database, we should see if we can initialize it.
Switch to the Code view of Cruise.vb and add code as follows:
Public Class Cruise
Dim Roster As New Collection
Dim MDB As New MiniDB
Search Nedrilad ::




Custom Search