-
Notifications
You must be signed in to change notification settings - Fork 3
/
GameConfig.h
76 lines (63 loc) · 1.56 KB
/
GameConfig.h
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
///
/// @file GameConfig.h
/// @author lemon(haohb13@gmail.com)
/// @date 2019-05-19 20:51:16
///
#include "Types.h"
#include <map>
#include <vector>
#include <iostream>
using namespace std;
namespace warcraft
{
class GameConfig {
public:
template <typename Iterator>
void setWarriorOrder(Iterator beg, Iterator end)
{
while(beg != end) {
_initWarriorOrder.push_back(*beg);
++beg;
}
}
void readFromConsole();
void readFromFile(const string & filename);
void nextGroupId() { ++_currentGroupId; }
size_t groups() const { return _groups.size(); }
size_t currentGroupId() const { return _currentGroupId; }
size_t cityCount() { return _groups[_currentGroupId]._cityCount; }
size_t headquartersInitialElements();
size_t warriorInitalLife(WarriorType key);
size_t warriorInitalAttack(WarriorType key);
void debug() const;
static GameConfig * getInstance()
{
if(nullptr == _pInstance) {
_pInstance = new GameConfig();
}
return _pInstance;
}
static void destroy()
{
if(_pInstance)
delete _pInstance;
}
private:
GameConfig() : _currentGroupId(0){ cout << "GameConfig()" << endl; }
~GameConfig(){ cout << "~GameConfig()" << endl; }
void readFromStream(istream & is);
struct InitData
{
size_t _initElements;
size_t _cityCount;
size_t _minutes;
map<WarriorType, size_t> _initLifes;
map<WarriorType, size_t> _initAttacks;
};
private:
static GameConfig * _pInstance;
vector<InitData> _groups;
size_t _currentGroupId;//当前组的测试数据的id
vector<WarriorType> _initWarriorOrder;
};
}// end of namespace warcraft