📄 minerstates.vb
字号:
'//------------------------------------------------------------------------
'//
'// In this state the miner will walk to a goldmine and pick up a nugget
'// of gold. If the miner already has a nugget of gold he'll change state
'// to VisitBankAndDepositGold. If he gets thirsty he'll change state
'// to QuenchThirst
'//------------------------------------------------------------------------
Public Class EnterMineAndDigForNugget
Inherits State
Public Sub EnterMineAndDigForNugget()
End Sub
'//copy ctor and assignment should be private
'private sub EnterMineAndDigForNugget(const EnterMineAndDigForNugget&)
'EnterMineAndDigForNugget& operator=(const EnterMineAndDigForNugget&);
Private Shared m_Instance As New EnterMineAndDigForNugget
Public Shared ReadOnly Property Instance() As EnterMineAndDigForNugget
Get
Return m_Instance
End Get
End Property
Public Overrides Sub Enter(ByVal m As Miner)
'//if the miner is not already located at the goldmine, he must
'//change location to the gold mine
If m.Location <> enmLoction_Type.goldmine Then
'SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
'cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": " << "Walkin' to the goldmine";
m.Location = enmLoction_Type.goldmine
End If
End Sub
Public Overrides Sub Execute(ByVal m As Miner)
'//the miner digs for gold until he is carrying in excess of MaxNuggets.
'//If he gets thirsty during his digging he packs up work for a while and
'//changes state to go to the saloon for a whiskey.
m.AddToGoldCarried(1)
m.IncreaseFatigue()
'SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
'cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": " << "Pickin' up a nugget";
'//if enough gold mined, go and put it in the bank
If m.PocketsFull() Then m.ChangeState(VisitBankAndDepositGold.Instance())
If m.Thirsty() Then m.ChangeState(QuenchThirst.Instance)
End Sub
Public Overrides Sub ExitState(ByVal m As Miner)
'SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
'cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": "
'<< "Ah'm leavin' the goldmine with mah pockets full o' sweet gold";
End Sub
End Class
'//------------------------------------------------------------------------
'//
'// Entity will go to a bank and deposit any nuggets he is carrying. If the
'// miner is subsequently wealthy enough he'll walk home, otherwise he'll
'// keep going to get more gold
'//------------------------------------------------------------------------
Public Class VisitBankAndDepositGold
Inherits State
'private:
' VisitBankAndDepositGold(){}
'//copy ctor and assignment should be private
'VisitBankAndDepositGold(const VisitBankAndDepositGold&);
'VisitBankAndDepositGold& operator=(const VisitBankAndDepositGold&);
Private Shared m_Instance As New VisitBankAndDepositGold
Public Shared ReadOnly Property Instance() As VisitBankAndDepositGold
Get
Return m_Instance
End Get
End Property
Public Overrides Sub Enter(ByVal m As Miner)
'//on entry the miner makes sure he is located at the bank
If m.Location() <> enmLoction_Type.bank Then
'SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
'cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": " << "Goin' to the bank. Yes siree";
m.Location = enmLoction_Type.bank
End If
End Sub
Public Overrides Sub Execute(ByVal m As Miner)
'//deposit the gold
m.AddToWealth(m.GoldCarried())
m.GoldCarried = 0
'SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
'cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": "
'<< "Depositing gold. Total savings now: "<< pMiner->Wealth();
'//wealthy enough to have a well earned rest?
If m.Wealth() >= Miner.ComfortLevel Then
'SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
'cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": "
'<< "WooHoo! Rich enough for now. Back home to mah li'lle lady";
m.ChangeState(GoHomeAndSleepTilRested.Instance())
Else
' //otherwise get more gold
m.ChangeState(EnterMineAndDigForNugget.Instance())
End If
End Sub
Public Overrides Sub ExitState(ByVal m As Miner)
'SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
'cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": " << "Leavin' the bank";
End Sub
End Class
'//------------------------------------------------------------------------
'//
'// miner will go home and sleep until his fatigue is decreased
'// sufficiently
'//------------------------------------------------------------------------
Public Class GoHomeAndSleepTilRested
Inherits State
'private:
'GoHomeAndSleepTilRested(){}
'//copy ctor and assignment should be private
'GoHomeAndSleepTilRested(const GoHomeAndSleepTilRested&);
'GoHomeAndSleepTilRested& operator=(const GoHomeAndSleepTilRested&);
Private Shared m_Instance As New GoHomeAndSleepTilRested
Public Shared ReadOnly Property Instance() As GoHomeAndSleepTilRested
Get
Return m_Instance
End Get
End Property
Public Overrides Sub Enter(ByVal m As Miner)
If m.Location <> enmLoction_Type.shack Then
'SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
'cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": " << "Walkin' home";
m.Location = enmLoction_Type.shack
End If
End Sub
Public Overrides Sub Execute(ByVal m As Miner)
'//if miner is not fatigued start to dig for nuggets again.
If Not m.Fatigued() Then
'SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
'cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": "
'<< "What a God darn fantastic nap! Time to find more gold";
m.ChangeState(EnterMineAndDigForNugget.Instance())
Else
'//sleep
m.DecreaseFatigue()
'SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
'cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": " << "ZZZZ... ";
End If
End Sub
Public Overrides Sub ExitState(ByVal m As Miner)
'SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
'cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": " << "Leaving the house";
End Sub
End Class
'//------------------------------------------------------------------------
'//
'//------------------------------------------------------------------------
Public Class QuenchThirst
Inherits State
'private:
' QuenchThirst(){}
'//copy ctor and assignment should be private
'QuenchThirst(const QuenchThirst&);
'QuenchThirst& operator=(const QuenchThirst&);
Private Shared m_Instance As New QuenchThirst
Public Shared ReadOnly Property Instance() As QuenchThirst
Get
Return m_Instance
End Get
End Property
Public Overrides Sub Enter(ByVal m As Miner)
If m.Location <> enmLoction_Type.saloon Then
m.Location = enmLoction_Type.saloon
'SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
'cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": " << "Boy, ah sure is thusty! Walking to the saloon";
End If
End Sub
Public Overrides Sub Execute(ByVal m As Miner)
If m.Thirsty() Then
m.BuyAndDrinkAWhiskey()
'SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
'cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": " << "That's mighty fine sippin liquer";
m.ChangeState(EnterMineAndDigForNugget.Instance())
Else
'SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
'cout << "\nERROR!\nERROR!\nERROR!";
End If
End Sub
Public Overrides Sub ExitState(ByVal m As Miner)
'SetTextColor(FOREGROUND_RED| FOREGROUND_INTENSITY);
'cout << "\n" << GetNameOfEntity(pMiner->ID()) << ": " << "Leaving the saloon, feelin' good";
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -