This repository was archived by the owner on Sep 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiner.cpp
More file actions
76 lines (60 loc) · 1.88 KB
/
Miner.cpp
File metadata and controls
76 lines (60 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "Miner.h"
#include "MinerOwnedStates.h"
#include <string>
using namespace std;
Miner::Miner(int id):
BaseGameEntity(id),
enum_location(shack),
carried_gold_amount(0),
money_in_bank(0),
fatigue(0),
// m_iThirst(0),
pCurrentState(GoHomeAndSleepTilRested::Instance()) // Use GoHomeAndSleepTilRested state to begin
{}
//--------------------------- ChangeState -------------------------------------
//-----------------------------------------------------------------------------
void Miner::ChangeState(State *pNewState) {
// make sure both states are both valid before attempting to
// call their methods
assert(pCurrentState && pNewState);
// call the exit method of the existing state
pCurrentState->Exit(this);
// change state to the new state
pCurrentState = pNewState;
// call the entry method of the new state
pCurrentState->Enter(this);
}
//-----------------------------------------------------------------------------
void Miner::Update()
{
// m_iThirst += 1;
if (pCurrentState) {
pCurrentState->Execute(this);
}
}
//-----------------------------------------------------------------------------
void Miner::AddToGoldCarried(const int val) {
carried_gold_amount += val;
if (carried_gold_amount < 0)
carried_gold_amount = 0;
}
//-----------------------------------------------------------------------------
void Miner::AddToWealth(const int val) {
money_in_bank += val;
if (money_in_bank < 0)
money_in_bank = 0;
}
//-----------------------------------------------------------------------------
bool Miner::Fatigued() const {
if (fatigue > tiredness_threshold) {
return true;
}
return false;
}
//-----------------------------------------------------------------------------
// bool Miner::Thirsty() const {
// if (m_iThirst >= ThirstLevel) {
// return true;
// }
// return false;
// }