Game Development Reference
In-Depth Information
Add a class to the project and name it NVP.vb. When the editor opens, add two
lines of code to the file as follows:
Public Class NVP
Public name As String
Public value As Integer
End Class
Needs and preferences will be initialized to random integer values when we create
a person. To get those random values, we need a helper function. We will use the
concept of rolling an N-sided die to get our integer random values. The code is
extremely useful in a variety of games. Add a module to the project and name it
Dice.vb. Add code to the file as follows:
Module Dice
'Get one roll on an N-sided die.
Public Function getDx(ByVal dots As Integer) As Integer
Return CInt(Int((Rnd() * dots) + 1))
End Function
End Module
The Mini-Database
Between the name-value pair helper object and VB's Collection object, we are
ready to make our mini-database. The database stores the available activities
along with the need each activity meets. The database also keeps a list of needs
met by the activities. We will use the database when we create a person. From the
list of needs, it can create a set of randomly initialized needs for a person.
Likewise, it can create and initialize a set of randomly initialized preferences from
the list of activities. We will also use the database to help the cruise director.
When the director gets the strongest need, the director will want a random
activity to meet that need. And when we print out the relationship data, we will
need a list of available activities. The mini-database simplifies the rest of the code
considerably; if it gets initialized cleanly, everything else just works.
Add a class to the project and name it MiniDB.vb. Add initialization code so that
it resembles the following:
Public Class MiniDB
'ToDo is activities grouped by need (a collection of collections).
Dim ToDo As New Collection
'Simple list of names of needs.
Search Nedrilad ::

Custom Search