📄 miner.vb
字号:
Public Class Miner
'//the amount of gold a miner must have before he feels comfortable
Public Const ComfortLevel As Integer = 5
'//the amount of nuggets a miner can carry
Public Const MaxNuggets As Integer = 3
'//above this value a miner is thirsty
Public Const ThirstLevel As Integer = 5
'//above this value a miner is sleepy
Public Const TirednessThreshold As Integer = 5
Dim m_pCurrentState As State
Dim m_Location As enmLoction_Type
'//how many nuggets the miner has in his pockets
Dim m_iGoldCarried As Integer
Dim m_iMoneyInBank As Integer
'//the higher the value, the thirstier the miner
Dim m_iThirst As Integer
'//the higher the value, the more tired the miner
Dim m_iFatigue As Integer
Dim m_Id As Integer = 0
Public Property Id() As Integer
Get
Return m_Id
End Get
Set(ByVal Value As Integer)
m_Id = Value
End Set
End Property
Public Sub New(ByVal id As Integer)
m_Id = id
m_Location = enmLoction_Type.shack
m_iGoldCarried = 0
m_iMoneyInBank = 0
m_iThirst = 0
m_iFatigue = 0
m_pCurrentState = GoHomeAndSleepTilRested.Instance()
End Sub
'//this must be implemented
Public Overridable Sub Update_New()
m_iThirst += 1
If (Not m_pCurrentState Is Nothing) Then
m_pCurrentState.Execute(Me)
End If
End Sub
'//this method changes the current state to the new state. It first
'//calls the Exit() method of the current state, then assigns the
'//new state to m_pCurrentState and finally calls the Entry()
'//method of the new state.
Public Sub ChangeState(ByVal new_state As State)
'//make sure both states are both valid before attempting to
'//call their methods
'assert (m_pCurrentState && pNewState);
'//call the exit method of the existing state
m_pCurrentState.ExitState(Me)
'//change state to the new state
m_pCurrentState = new_state
'//call the entry method of the new state
m_pCurrentState.Enter(Me)
End Sub
Public Property Location() As enmLoction_Type
Get
Return m_Location
End Get
Set(ByVal Value As enmLoction_Type)
m_Location = Value
End Set
End Property
Public Property GoldCarried() As Integer
Get
Return m_iGoldCarried
End Get
Set(ByVal Value As Integer)
m_iGoldCarried = Value
End Set
End Property
Public Sub AddToGoldCarried(ByVal val As Integer)
m_iGoldCarried += val
If m_iGoldCarried < 0 Then m_iGoldCarried = 0
End Sub
Public Function PocketsFull() As Boolean
Return m_iGoldCarried >= MaxNuggets
End Function
Public Function Fatigued() As Boolean
If (m_iFatigue > TirednessThreshold) Then Return True
Return False
End Function
Public Sub DecreaseFatigue()
m_iFatigue -= 1
End Sub
Public Sub IncreaseFatigue()
m_iFatigue += 1
End Sub
Public Property Wealth() As Integer
Get
Return m_iMoneyInBank
End Get
Set(ByVal Value As Integer)
m_iMoneyInBank = Value
End Set
End Property
Public Sub AddToWealth(ByVal val As Integer)
m_iMoneyInBank += val
If m_iMoneyInBank < 0 Then m_iMoneyInBank = 0
End Sub
Public Function Thirsty() As Boolean
If m_iThirst >= ThirstLevel Then Return True
Return False
End Function
Public Sub BuyAndDrinkAWhiskey()
m_iThirst = 0
m_iMoneyInBank -= 2
End Sub
End Class
Public Enum enmLoction_Type
shack
goldmine
bank
saloon
End Enum
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -