Game Development Reference
The occupations are the easiest part of the code. The job class stores the five data
items used to create it without letting outside code change them. Add the fol-
lowing lines of code to the class to provide storage for the data:
'Other than the New call, this is mostly a read-only store of data.
Private myName As String
Private myPSuccess As Double
Private myCost As Double
Private myGain As Double
Private myLoss As Double
That takes care of storage. We want the class to be created with the five values it
will store. To do that, we add a New routine to the class. It will take the five values,
validate them, and store them. Add the following code to the class:
'New: store away my values
Public Sub New(ByVal Name As String, _
ByVal PSuccessAsPerCentage As Double, _
ByVal Cost As Double, ByVal Gain As Double, ByVal Loss As Double)
myName = Name
If PSuccessAsPerCentage > 100.0 Or PSuccessAsPerCentage < 0 Then
MsgBox("Bad PSuccess value fed to Job.New")
'convert from percent to decimal
myPSuccess = PSuccessAsPerCentage / 100.0
myCost = Cost
myGain = Gain
myLoss = Loss
Having stored the five values, we need to make them available to outside code.
Simple functions will do the trick. Add the following five access functions to the class:
'Accessors to allow outside code to read our data.
'We could have exposed them
'as public, but we do not want them changed.
Public Function Name() As String
'As a decimal; 99% means we return 0.99
Public Function PSuccess() As Double