Skip to content

Commit aa5379f

Browse files
committed
init
0 parents  commit aa5379f

File tree

634 files changed

+97514
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

634 files changed

+97514
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "BaseGameEntity.h"
2+
#include <cassert>
3+
4+
5+
6+
int BaseGameEntity::m_iNextValidID = 0;
7+
8+
9+
10+
//----------------------------- SetID -----------------------------------------
11+
//
12+
// this must be called within each constructor to make sure the ID is set
13+
// correctly. It verifies that the value passed to the method is greater
14+
// or equal to the next valid ID, before setting the ID and incrementing
15+
// the next valid ID
16+
//-----------------------------------------------------------------------------
17+
void BaseGameEntity::SetID(int val)
18+
{
19+
//make sure the val is equal to or greater than the next available ID
20+
assert ( (val >= m_iNextValidID) && "<BaseGameEntity::SetID>: invalid ID");
21+
22+
m_ID = val;
23+
24+
m_iNextValidID = m_ID + 1;
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#ifndef ENTITY_H
2+
#define ENTITY_H
3+
//------------------------------------------------------------------------
4+
//
5+
// Name: BaseGameEntity.h
6+
//
7+
// Desc: Base class for a game object
8+
//
9+
// Author: Mat Buckland 2002 ([email protected])
10+
//
11+
//------------------------------------------------------------------------
12+
13+
14+
class BaseGameEntity
15+
{
16+
17+
private:
18+
19+
//every entity must have a unique identifying number
20+
int m_ID;
21+
22+
//this is the next valid ID. Each time a BaseGameEntity is instantiated
23+
//this value is updated
24+
static int m_iNextValidID;
25+
26+
//this must be called within the constructor to make sure the ID is set
27+
//correctly. It verifies that the value passed to the method is greater
28+
//or equal to the next valid ID, before setting the ID and incrementing
29+
//the next valid ID
30+
void SetID(int val);
31+
32+
public:
33+
34+
BaseGameEntity(int id)
35+
{
36+
SetID(id);
37+
}
38+
39+
virtual ~BaseGameEntity(){}
40+
41+
//all entities must implement an update function
42+
virtual void Update()=0;
43+
44+
int ID()const{return m_ID;}
45+
};
46+
47+
48+
49+
#endif
50+
51+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#ifndef NAMES_H
2+
#define NAMES_H
3+
4+
#include <string>
5+
6+
enum
7+
{
8+
ent_Miner_Bob,
9+
10+
ent_Elsa
11+
};
12+
13+
inline std::string GetNameOfEntity(int n)
14+
{
15+
switch(n)
16+
{
17+
case ent_Miner_Bob:
18+
19+
return "Miner Bob";
20+
21+
case ent_Elsa:
22+
23+
return "Elsa";
24+
25+
default:
26+
27+
return "UNKNOWN!";
28+
}
29+
}
30+
31+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef LOCATIONS_H
2+
#define LOCATIONS_H
3+
4+
5+
enum location_type
6+
{
7+
shack,
8+
goldmine,
9+
bank,
10+
saloon
11+
};
12+
13+
14+
15+
16+
17+
18+
19+
20+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#include "Miner.h"
2+
#include "MinerOwnedStates.h"
3+
4+
Miner::Miner(int id):BaseGameEntity(id),
5+
m_Location(shack),
6+
m_iGoldCarried(0),
7+
m_iMoneyInBank(0),
8+
m_iThirst(0),
9+
m_iFatigue(0),
10+
m_pCurrentState(GoHomeAndSleepTilRested::Instance())
11+
12+
{}
13+
14+
//--------------------------- ChangeState -------------------------------------
15+
//-----------------------------------------------------------------------------
16+
void Miner::ChangeState(State* pNewState)
17+
{
18+
//make sure both states are both valid before attempting to
19+
//call their methods
20+
assert (m_pCurrentState && pNewState);
21+
22+
//call the exit method of the existing state
23+
m_pCurrentState->Exit(this);
24+
25+
//change state to the new state
26+
m_pCurrentState = pNewState;
27+
28+
//call the entry method of the new state
29+
m_pCurrentState->Enter(this);
30+
}
31+
32+
33+
//-----------------------------------------------------------------------------
34+
void Miner::AddToGoldCarried(const int val)
35+
{
36+
m_iGoldCarried += val;
37+
38+
if (m_iGoldCarried < 0) m_iGoldCarried = 0;
39+
}
40+
41+
42+
//-----------------------------------------------------------------------------
43+
void Miner::AddToWealth(const int val)
44+
{
45+
m_iMoneyInBank += val;
46+
47+
if (m_iMoneyInBank < 0) m_iMoneyInBank = 0;
48+
}
49+
50+
51+
//-----------------------------------------------------------------------------
52+
bool Miner::Thirsty()const
53+
{
54+
if (m_iThirst >= ThirstLevel){return true;}
55+
56+
return false;
57+
}
58+
59+
60+
//-----------------------------------------------------------------------------
61+
void Miner::Update()
62+
{
63+
m_iThirst += 1;
64+
65+
if (m_pCurrentState)
66+
{
67+
m_pCurrentState->Execute(this);
68+
}
69+
}
70+
71+
72+
//-----------------------------------------------------------------------------
73+
bool Miner::Fatigued()const
74+
{
75+
if (m_iFatigue > TirednessThreshold)
76+
{
77+
return true;
78+
}
79+
80+
return false;
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#ifndef MINER_H
2+
#define MINER_H
3+
//------------------------------------------------------------------------
4+
//
5+
// Name: Miner.h
6+
//
7+
// Desc: A class defining a goldminer.
8+
//
9+
// Author: Mat Buckland 2002 ([email protected])
10+
//
11+
//------------------------------------------------------------------------
12+
#include <string>
13+
#include <cassert>
14+
15+
#include "BaseGameEntity.h"
16+
#include "Locations.h"
17+
18+
19+
class State;
20+
21+
//the amount of gold a miner must have before he feels comfortable
22+
const int ComfortLevel = 5;
23+
//the amount of nuggets a miner can carry
24+
const int MaxNuggets = 3;
25+
//above this value a miner is thirsty
26+
const int ThirstLevel = 5;
27+
//above this value a miner is sleepy
28+
const int TirednessThreshold = 5;
29+
30+
31+
32+
class Miner : public BaseGameEntity
33+
{
34+
private:
35+
36+
State* m_pCurrentState;
37+
38+
location_type m_Location;
39+
40+
//how many nuggets the miner has in his pockets
41+
int m_iGoldCarried;
42+
43+
int m_iMoneyInBank;
44+
45+
//the higher the value, the thirstier the miner
46+
int m_iThirst;
47+
48+
//the higher the value, the more tired the miner
49+
int m_iFatigue;
50+
51+
public:
52+
53+
Miner(int id);
54+
55+
//this must be implemented
56+
void Update();
57+
58+
//this method changes the current state to the new state. It first
59+
//calls the Exit() method of the current state, then assigns the
60+
//new state to m_pCurrentState and finally calls the Entry()
61+
//method of the new state.
62+
void ChangeState(State* new_state);
63+
64+
65+
66+
location_type Location()const{return m_Location;}
67+
void ChangeLocation(const location_type loc){m_Location=loc;}
68+
69+
int GoldCarried()const{return m_iGoldCarried;}
70+
void SetGoldCarried(const int val){m_iGoldCarried = val;}
71+
void AddToGoldCarried(const int val);
72+
bool PocketsFull()const{return m_iGoldCarried >= MaxNuggets;}
73+
74+
bool Fatigued()const;
75+
void DecreaseFatigue(){m_iFatigue -= 1;}
76+
void IncreaseFatigue(){m_iFatigue += 1;}
77+
78+
int Wealth()const{return m_iMoneyInBank;}
79+
void SetWealth(const int val){m_iMoneyInBank = val;}
80+
void AddToWealth(const int val);
81+
82+
bool Thirsty()const;
83+
void BuyAndDrinkAWhiskey(){m_iThirst = 0; m_iMoneyInBank-=2;}
84+
85+
};
86+
87+
88+
89+
90+
#endif

0 commit comments

Comments
 (0)